Skip to content

Commit

Permalink
Add support of scaling rules for horizontal scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
vboulineau committed Jun 27, 2024
1 parent 60b1de9 commit 2c43fcd
Show file tree
Hide file tree
Showing 15 changed files with 1,804 additions and 80 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/pointer v0.55.0-rc.3
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.55.0-rc.3
github.com/DataDog/datadog-go/v5 v5.5.0
github.com/DataDog/datadog-operator v0.7.1-0.20240522081847-e83dd785258a
github.com/DataDog/datadog-operator v0.7.1-0.20240627103854-fe86c2214d4c
github.com/DataDog/ebpf-manager v0.6.1
github.com/DataDog/gopsutil v1.2.2
github.com/DataDog/nikos v1.12.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/clusteragent/autoscaling/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ func (p ProcessResult) ShouldRequeue() bool {
return p.Requeue || p.RequeueAfter > 0
}

// After returns a copy of current ProcessResult with RequeueAfter set to the given duration
func (p ProcessResult) After(after time.Duration) ProcessResult {
p.RequeueAfter = after
return p
}

// Merge merges the other ProcessResult into a newly returned one
func (p ProcessResult) Merge(other ProcessResult) ProcessResult {
if other.Requeue {
p.Requeue = true

if p.Requeue {
p.RequeueAfter = min(p.RequeueAfter, other.RequeueAfter)
} else {
p.RequeueAfter = other.RequeueAfter
}
}

return p
}

var (
// Requeue is a shortcut to avoid having ProcessResult{Requeue: true} everywhere in the code
Requeue = ProcessResult{Requeue: true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestConfigRetriverAutoscalingSettingsLeader(t *testing.T) {
Name: "deploy3",
},
Policy: &datadoghq.DatadogPodAutoscalerPolicy{
ApplyMode: datadoghq.DatadogPodAutoscalerAllApplyNone,
ApplyMode: datadoghq.DatadogPodAutoscalerNoneApplyMode,
Update: &datadoghq.DatadogPodAutoscalerUpdatePolicy{
Strategy: datadoghq.DatadogPodAutoscalerAutoUpdateStrategy,
},
Expand Down
7 changes: 6 additions & 1 deletion pkg/clusteragent/autoscaling/workload/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,12 @@ func (c *Controller) handleScaling(ctx context.Context, podAutoscaler *datadoghq
return horizontalRes, err
}

return c.verticalController.sync(ctx, podAutoscaler, podAutoscalerInternal)
verticalRes, err := c.verticalController.sync(ctx, podAutoscaler, podAutoscalerInternal)
if err != nil {
return verticalRes, err
}

return horizontalRes.Merge(verticalRes), nil
}

func (c *Controller) createPodAutoscaler(ctx context.Context, podAutoscalerInternal model.PodAutoscalerInternal) error {
Expand Down
Loading

0 comments on commit 2c43fcd

Please sign in to comment.