Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds delay in scale down interval #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type options struct {
kubeconfig string
syncInterval time.Duration
scaleInterval time.Duration
scaleDownDelay time.Duration
statsD string
statsDInterval time.Duration
}
Expand Down Expand Up @@ -58,7 +59,7 @@ func main() {
kingpin.Flag("kubeconfig", "Path to kubeconfig.").StringVar(&opts.kubeconfig)
kingpin.Flag("sync-interval", "Interval to periodically refresh Scaler objects from Kubernetes.").Default("1m").DurationVar(&opts.syncInterval)
kingpin.Flag("scale-interval", "Interval to check queue sizes and scale deployments.").Default("1m").DurationVar(&opts.scaleInterval)

kingpin.Flag("scaledown-delay", "Delay in scaling down the pods once the scale down threshold is met.").Default("1s").DurationVar(&opts.scaleDownDelay)
kingpin.Flag("statsd", "UDP address to publish StatsD metrics. e.g. 127.0.0.1:8125").Default("").StringVar(&opts.statsD)
kingpin.Flag("statsd-interval", "Interval to publish to StatsD").Default("10s").DurationVar(&opts.statsDInterval)

Expand Down Expand Up @@ -109,7 +110,7 @@ func main() {
cache := crd.NewCache(sc, opts.syncInterval)
go cache.Run(ctx)

s := scaler.New(cs, cache.Store, opts.scaleInterval)
s := scaler.New(cs, cache.Store, opts.scaleInterval, opts.scaleDownDelay)
go s.Run(ctx)

<-stopChan
Expand Down
6 changes: 4 additions & 2 deletions pkg/scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ type Scaler struct {
client *kubernetes.Clientset
store cache.Store
interval time.Duration
delay time.Duration
}

func New(client *kubernetes.Clientset, store cache.Store, interval time.Duration) *Scaler {
return &Scaler{client, store, interval}
func New(client *kubernetes.Clientset, store cache.Store, interval time.Duration, delay time.Duration) *Scaler {
return &Scaler{client, store, interval, delay}
}

func (s Scaler) Run(ctx context.Context) error {
Expand Down Expand Up @@ -70,6 +71,7 @@ func (s Scaler) targetReplicas(size int64, scale *crd.SqsAutoScaler, d *appsv1.D
desired := replicas + scale.Spec.ScaleUp.Amount
return min(desired, scale.Spec.MaxPods), nil
} else if size <= scale.Spec.ScaleDown.Threshold {
time.Sleep(s.delay * time.Second)
desired := replicas - scale.Spec.ScaleDown.Amount
return max(desired, scale.Spec.MinPods), nil
}
Expand Down