Skip to content

Commit

Permalink
Add environment variable to disable changing an existing PodAutoscal…
Browse files Browse the repository at this point in the history
…er status to a negative desired count
  • Loading branch information
SaschaSchwarze0 committed Dec 28, 2023
1 parent 149db32 commit 3cf9051
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/reconciler/autoscaling/kpa/kpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"math"
"os"

"go.opencensus.io/stats"
"go.uber.org/zap"
Expand Down Expand Up @@ -53,6 +54,14 @@ const (
minActivators = 2
)

var (
ignoreSwitchToNegativeDesiredScale = false
)

func init() {
ignoreSwitchToNegativeDesiredScale = os.Getenv("IGNORE_SWITCH_TO_NEGATIVE_DESIRED_SCALE") == "true"
}

// podCounts keeps record of various numbers of pods
// for each revision.
type podCounts struct {
Expand Down Expand Up @@ -220,7 +229,10 @@ func (c *Reconciler) reconcileDecider(ctx context.Context, pa *autoscalingv1alph
}

func computeStatus(ctx context.Context, pa *autoscalingv1alpha1.PodAutoscaler, pc podCounts, logger *zap.SugaredLogger) {
pa.Status.DesiredScale, pa.Status.ActualScale = ptr.Int32(int32(pc.want)), ptr.Int32(int32(pc.ready))
pa.Status.ActualScale = ptr.Int32(int32(pc.ready))
if !ignoreSwitchToNegativeDesiredScale || pc.want > -1 || pa.Status.DesiredScale == nil || *pa.Status.DesiredScale < 0 {
pa.Status.DesiredScale = ptr.Int32(int32(pc.want))
}

reportMetrics(pa, pc)
computeActiveCondition(ctx, pa, pc)
Expand Down

0 comments on commit 3cf9051

Please sign in to comment.