Skip to content
Open
4 changes: 4 additions & 0 deletions pkg/clusteragent/autoscaling/workload/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func (c *Controller) syncPodAutoscaler(ctx context.Context, key, ns, name string
return autoscaling.NoRequeue, nil
}

// Track Datadog Pod Autoscaler configuration and status
// run it only at the end of handleScaling()
defer trackDPATelemetry(podAutoscaler)

// Object is present in both our store and Kubernetes, we need to sync depending on ownership.
// Implement info sync based on ownership.
if podAutoscaler.Spec.Owner == datadoghqcommon.DatadogPodAutoscalerRemoteOwner {
Expand Down
10 changes: 6 additions & 4 deletions pkg/clusteragent/autoscaling/workload/controller_horizontal.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,10 @@ func applyScaleUpPolicy(
// For that we consider the current number and apply the opposite of the events that happened in the period.
periodStartReplicas := currentDesiredReplicas - replicasAdded + replicasRemoved
var ruleMax int32
if rule.Type == datadoghqcommon.DatadogPodAutoscalerPodsScalingRuleType {
switch rule.Type {
case datadoghqcommon.DatadogPodAutoscalerPodsScalingRuleType:
ruleMax = periodStartReplicas + rule.Value
} else if rule.Type == datadoghqcommon.DatadogPodAutoscalerPercentScalingRuleType {
case datadoghqcommon.DatadogPodAutoscalerPercentScalingRuleType:
// 1.x * start may yield the same number of replicas as periodStartReplicas, ceiling up to always always allow at least 1 replica
// otherwise it would block scaling up forever.
ruleMax = int32(math.Ceil(float64(periodStartReplicas) * (1 + float64(rule.Value)/100)))
Expand Down Expand Up @@ -467,9 +468,10 @@ func applyScaleDownPolicy(
// For that we consider the current number and apply the opposite of the events that happened in the period.
periodStartReplicas := currentDesiredReplicas - replicasAdded + replicasRemoved
var ruleMin int32
if rule.Type == datadoghqcommon.DatadogPodAutoscalerPodsScalingRuleType {
switch rule.Type {
case datadoghqcommon.DatadogPodAutoscalerPodsScalingRuleType:
ruleMin = periodStartReplicas - rule.Value
} else if rule.Type == datadoghqcommon.DatadogPodAutoscalerPercentScalingRuleType {
case datadoghqcommon.DatadogPodAutoscalerPercentScalingRuleType:
// When casting, the decimal is truncated, so we always have at least 1 replica allowed
ruleMin = int32(float64(periodStartReplicas) * (1 - float64(rule.Value)/100))
}
Expand Down
Loading
Loading