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

Add mechanism to override drainability status #6196

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

artemvmin
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds a mechanism for one rule to selectively override other rules. This allows for custom rules that override some outcomes (e.g. BlockDrain -> DrainOk) while not overriding others (e.g. SkipDrain).

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 13, 2023
@artemvmin
Copy link
Contributor Author

/assign x13n

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/cluster-autoscaler labels Oct 13, 2023
@artemvmin artemvmin mentioned this pull request Oct 13, 2023
@artemvmin artemvmin force-pushed the drain-blocking-rule branch from 71d2546 to 8b9f8a1 Compare October 13, 2023 19:15
Copy link
Member

@x13n x13n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor comments, this looks like a reasonable mechanism.

},
"override no match": {
rules: Rules{
fakeRule{drainability.Status{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: How about drainability.NewDrainableStatus(drainability.OverridingOnly(drainability.SkipDrain))? Or is it not really easier to read?

Copy link
Contributor Author

@artemvmin artemvmin Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they're both quite readable. I would argue the opposite and say that the constructors in the drainability package are unnecessary boilerplate. Since drainability.Status is already exported, the following are identical:

status := drainability.NewBlockedStatus(reason, err)
status := &drainability.Status{
  Reason: reason,
  Error: err,
}

The latter is better because it's explicit about parameters and requires no additional boilerplate when new fields are added to the struct.

}
for _, candidate := range candidates {
for _, override := range candidate.Overrides {
if status.Outcome == override {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth logging the fact that override happened? At least at V(5)? This logic becomes non-trivial with this change, so some observability wouldn't hurt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea. Added a Name() to the Rule interface to make this log more useful.

@artemvmin artemvmin force-pushed the drain-blocking-rule branch from 3fbaa8f to a0d56b3 Compare October 18, 2023 21:40
@x13n
Copy link
Member

x13n commented Oct 19, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 19, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: artemvmin, x13n

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 19, 2023
@k8s-ci-robot k8s-ci-robot merged commit a3a29cf into kubernetes:master Oct 19, 2023
4 checks passed
jbartosik added a commit to jbartosik/autoscaler that referenced this pull request Oct 23, 2023
The interface changed in kubernetes#6196 but the Rules class didn't
jbartosik added a commit to jbartosik/autoscaler that referenced this pull request Oct 23, 2023
The interface changed in kubernetes#6196 but the Rules class didn't
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants