-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allow delayed downscale of subset of pods #156
Conversation
…ome pods at the end of statefulset are ready to be downscaled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job Peter! LGTM. I left a couple of minor comments I would be glad if you could look at before merging. Thanks!
} | ||
|
||
delay, prepareURL, err := parseDelayedDownscaleAnnotations(sts.GetAnnotations()) | ||
if delay == 0 || prepareURL == nil || err != nil { | ||
return err | ||
return desiredReplicas, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there was an error would be more correct to return currentReplicas
. Today the caller doesn't scale to updatedDesiredReplicas
in case of error, but I would like to protect from future bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in f7fcdb0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And follow-up fix in 7e79c3b.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And follow-up fix in 7e79c3b.
Exactly. That's what I had in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fortunately test caught my mistake :)
// No change in the number of replicas: don't log because this will be the result most of the time. | ||
continue | ||
} | ||
|
||
// We're going to change number of replicas on the statefulset. | ||
// If there is delayed downscale configured on the statefulset, we will first handle delay part, and only if that succeeds, | ||
// continue with downscaling or upscaling. | ||
if err := checkScalingDelay(ctx, c.logger, sts, client, currentReplicas, desiredReplicas); err != nil { | ||
level.Warn(c.logger).Log("msg", "not scaling statefulset due to failed scaling delay check", "group", groupName, "name", sts.GetName(), "currentReplicas", currentReplicas, "desiredReplicas", desiredReplicas, "err", err) | ||
var desiredReplicas int32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make code more robust from future changes, I suggest to not have this initialised to 0. We could simply do:
var desiredReplicas int32 | |
desiredReplicas, err := checkScalingDelay(ctx, c.logger, sts, client, currentReplicas, referenceResourceDesiredReplicas) | |
if err != nil { | |
// ... | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done in f7fcdb0.
This PR implements earlier delayed downscale of pods that have already reached their delay, even if not ALL pods have reached it yet.
Fixes #155