Skip to content

Commit

Permalink
refactor: make scaling none skip (#53)
Browse files Browse the repository at this point in the history
* refactor: make scaling none skip

* feat: bump chart version
  • Loading branch information
jonathan-mayer authored Sep 16, 2024
1 parent d19831b commit d159ef4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions cmd/kubedownscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ func scanWorkload(workload scalable.Workload, client kubernetes.Client, ctx cont
return nil
}

scaling, err := layers.GetCurrentScaling()
if err != nil {
return fmt.Errorf("failed to get current scaling for workload: %w", err)
scaling := layers.GetCurrentScaling()
if scaling == values.ScalingNone {
slog.Debug("scaling is not set by any layer, skipping", "workload", workload.GetName(), "namespace", workload.GetNamespace())
return nil
}
if scaling == values.ScalingIgnore {
slog.Debug("scaling is ignored, skipping", "workload", workload.GetName(), "namespace", workload.GetNamespace())
Expand Down
4 changes: 2 additions & 2 deletions deployments/chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: go-kube-downscaler
description: A Helm chart for deploying the go-kube-downscaler

type: application
version: 1.0.0
appVersion: 1.0.0
version: 1.0.1
appVersion: 1.0.1
16 changes: 8 additions & 8 deletions internal/pkg/values/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Undefined = -1 // Undefined represents an undefined integer value
type scaling int

const (
scalingNone scaling = iota // no scaling set in this layer, go to next layer
ScalingNone scaling = iota // no scaling set in this layer, go to next layer
ScalingIgnore // not scaling
ScalingDown // scaling down
ScalingUp // scaling up
Expand Down Expand Up @@ -113,7 +113,7 @@ func (l Layer) getCurrentScaling() scaling {
return ScalingIgnore
}

return scalingNone
return ScalingNone
}

// getForcedScaling checks if the layer has forced scaling enabled and returns the matching scaling
Expand All @@ -131,24 +131,24 @@ func (l Layer) getForcedScaling() scaling {
type Layers []Layer

// GetCurrentScaling gets the current scaling of the first layer that implements scaling
func (l Layers) GetCurrentScaling() (scaling, error) {
func (l Layers) GetCurrentScaling() scaling {
// check for forced scaling
for _, layer := range l {
forcedScaling := layer.getForcedScaling()
if forcedScaling != scalingNone {
return forcedScaling, nil
if forcedScaling != ScalingNone {
return forcedScaling
}
}
// check for time-based scaling
for _, layer := range l {
layerScaling := layer.getCurrentScaling()
if layerScaling == scalingNone {
if layerScaling == ScalingNone {
continue
}
return layerScaling, nil
return layerScaling
}

return scalingNone, errValueNotSet
return ScalingNone
}

// GetDownscaleReplicas gets the downscale replicas of the first layer that implements downscale replicas
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/values/layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestLayer_getCurrentScaling(t *testing.T) {
{
name: "none set",
layer: Layer{},
wantScaling: scalingNone,
wantScaling: ScalingNone,
},
}

Expand Down

0 comments on commit d159ef4

Please sign in to comment.