-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add support for scale up/down delay #2598
Add support for scale up/down delay #2598
Conversation
Welcome @44past4! |
/assign @wojtek-t |
cd4b744
to
ec7a0f3
Compare
addon-resizer/nanny/estimator.go
Outdated
@@ -98,6 +98,8 @@ func calculateResources(numNodes uint64, resources []Resource) *corev1.ResourceR | |||
overhead := computeResourceOverheadValueString(numNodes, r) | |||
newRes := r.Base | |||
newRes.Add(resource.MustParse(overhead)) | |||
// Force initialization of newRes.s so that it could be logged | |||
newRes.String() |
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.
Seriously? You really need?
How this is logged?
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.
Without this call this value can be logged as:
{i:{value:0 scale:0} d:{Dec:0xc4202b5d70} s: Format:DecimalSI}
WIth this call this becomes:
{i:{value:0 scale:0} d:{Dec:0xc4202b5d70} s:455m Format:DecimalSI}
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.
How do you print it? If you would log it with:
klog.("%s", <your var>)
if would work fine (as this is calling String() method.
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 it seems like a better way to print it - things like d:{Dec:0xc4202b5d70}
aren't particularly useful :)
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.
This value is not printed directly but instead it is nested in k8s.io/api/core/v1/ResourceRequirements which is printed with %+v
.
I will change it in a way that I will serialize ResourceRequirements to json before displaying it.
addon-resizer/nanny/nanny_lib.go
Outdated
log.V(3).Infof("Resources are not within the expected limits, Actual: %+v, accepted range: %+v. Skipping resource update because of scale up/down delay", *resources, *expResources) | ||
continue | ||
} | ||
|
||
log.Infof("Resources are not within the expected limits, updating the deployment. Actual: %+v Expected: %+v", *resources, *expResources) |
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.
nit: can you make this log consistent with the one above? Also could you add a log verbosity level?
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.
Log message has been updated. I have not added log verbosity because I believe that this message will be logged only when actual resize will be performed and therefore it is ok to log this message without a verbosity level being set.
addon-resizer/nanny/nanny_lib.go
Outdated
scaleDown operation = iota | ||
scaleUp operation = iota | ||
) | ||
|
||
// checkResource determines whether a specific resource needs to be over-written. |
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.
Can you update the comment?
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
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.
Same comments as on #2599
Please provide more information on the E2E tests performed.
addon-resizer/nanny/nanny_lib.go
Outdated
log.V(4).Infof("Resources are within the expected limits. Actual: %+v Expected: %+v", *resources, *expResources) | ||
continue | ||
} | ||
|
||
now := time.Now() | ||
if (op == scaleDown && now.Before(lastChange.Add(scaleDownDelay))) || |
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.
Can you point me to the specific line in test where this thing is properly unit-tested. I don't see a line where we check what happens if last change is slightly before or slightly after scale****Delay. But maybe I'm missing something.
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.
I have extracted logic for checking resources for deployment and updating them to a separate method and added unit tests for this.
When it comes E2E tests I have build an image with addon-resizer, deployed it to a Kubernetes cluster first without any delay being set and then with scale up and scale down being set and I have scaled cluster from 3 to 10 nodes and then back to 3 nodes.
5077ba6
to
893093b
Compare
override, op = checkResource(threshold, reqs, expReqs, resourceType) | ||
if override { | ||
return true, op | ||
} |
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.
This silently assumes that we don't go up in some resource and down on the other resource.
This is probably fine, but it requires an explicit comment.
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.
I have added a comment about the operation type to the function description.
addon-resizer/nanny/nanny_lib.go
Outdated
if (op == scaleDown && now.Before(lastChange.Add(scaleDownDelay))) || | ||
(op == scaleUp && now.Before(lastChange.Add(scaleUpDelay))) { | ||
if log.V(3) { | ||
log.V(3).Infof("Resources are not within the expected limits, Actual: %+v, accepted range: %+v. Skipping resource update because of scale up/down delay", jsonOrValue(*resources), jsonOrValue(*expResources)) |
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.
I actually think this should be logged unconditionally - this is important log and lack of it may introduce a lot of misunderstanding - please change to simply log.Infof
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.
Logging this unconditionally could spam logs with hundreds of the same messages were only the first one is really useful for the user. Therefore I have decided to change the implementation in a way that I will log this message unconditionally but only for the first time we when we are skipping the the override.
7701275
to
a007438
Compare
addon-resizer/nanny/nanny_lib.go
Outdated
// updateResources counts the number of nodes, estimates the expected | ||
// ResourceRequirements, compares them to the actual ResourceRequirements, and | ||
// updates the deployment with the expected ResourceRequirements if necessary. | ||
// It returns true if deployment has been updated. |
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.
no longer true
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.
Updated the information about the returned values.
addon-resizer/nanny/nanny_lib.go
Outdated
log.V(4).Infof("Resources are within the expected limits. Actual: %+v Expected: %+v", *resources, *expResources) | ||
continue | ||
// If there's a difference, go ahead and set the new values. | ||
overwrite, op := shouldOverwriteResources(int64(threshold), resources.Limits, resources.Requests, expResources.Limits, expResources.Requests) |
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.
nit: consistency - you're using overwrite in some places and override in other
Can you please unify it?
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.
I have changed all occurrences of override to overwrite.
251e7ca
to
5c35e71
Compare
5c35e71
to
e158b6b
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wojtek-t The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fix for #2597 for 1.8
@bskiba