-
Notifications
You must be signed in to change notification settings - Fork 947
Add the ClusterTaintPolicy controller to handle taints on the clusters #6368
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 the ClusterTaintPolicy controller to handle taints on the clusters #6368
Conversation
Waiting for #6319 |
eaa6751
to
8a916b5
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #6368 +/- ##
==========================================
+ Coverage 49.21% 49.27% +0.06%
==========================================
Files 684 686 +2
Lines 55327 55833 +506
==========================================
+ Hits 27228 27514 +286
- Misses 26326 26521 +195
- Partials 1773 1798 +25
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Please rebase this |
8a916b5
to
d1bbdac
Compare
/hold |
d1bbdac
to
d7deebb
Compare
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.
/assign
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.
Pull Request Overview
This PR adds a new ClusterTaintPolicy controller to manage taints on clusters, along with the associated helper functions and controller integrations.
- Introduces a GenerateTaintsMessage helper for a standardized taint description.
- Implements the ClusterTaintPolicy controller with reconciliation logic based on cluster match conditions.
- Updates the cluster controller to use the new helper and integrates the new controller into the controller manager.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
pkg/util/helper/taint.go | Added GenerateTaintsMessage to format cluster taint info |
pkg/controllers/taint/clustertaintpolicy_controller.go | New controller to apply taint policies on clusters |
pkg/controllers/cluster/cluster_controller.go | Replaced local event message generation with new helper |
cmd/controller-manager/app/controllermanager.go | Integrated the new ClusterTaintPolicy controller |
var msg string | ||
for i, taint := range taints { | ||
if i != 0 { | ||
msg += "," | ||
} | ||
if taint.Value != "" { | ||
msg += strings.Join([]string{`{`, | ||
`Key:` + fmt.Sprintf("%v", taint.Key) + `,`, | ||
`Value:` + fmt.Sprintf("%v", taint.Value) + `,`, | ||
`Effect:` + fmt.Sprintf("%v", taint.Effect), | ||
`}`, | ||
}, "") | ||
} else { | ||
msg += strings.Join([]string{`{`, | ||
`Key:` + fmt.Sprintf("%v", taint.Key) + `,`, | ||
`Effect:` + fmt.Sprintf("%v", taint.Effect), | ||
`}`, | ||
}, "") | ||
} | ||
} | ||
|
||
return fmt.Sprintf("cluster now has taints([%s])", msg) |
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.
[nitpick] Consider using a strings.Builder for concatenating the taint messages in GenerateTaintsMessage to improve performance and readability when processing a larger number of taints.
var msg string | |
for i, taint := range taints { | |
if i != 0 { | |
msg += "," | |
} | |
if taint.Value != "" { | |
msg += strings.Join([]string{`{`, | |
`Key:` + fmt.Sprintf("%v", taint.Key) + `,`, | |
`Value:` + fmt.Sprintf("%v", taint.Value) + `,`, | |
`Effect:` + fmt.Sprintf("%v", taint.Effect), | |
`}`, | |
}, "") | |
} else { | |
msg += strings.Join([]string{`{`, | |
`Key:` + fmt.Sprintf("%v", taint.Key) + `,`, | |
`Effect:` + fmt.Sprintf("%v", taint.Effect), | |
`}`, | |
}, "") | |
} | |
} | |
return fmt.Sprintf("cluster now has taints([%s])", msg) | |
var builder strings.Builder | |
for i, taint := range taints { | |
if i != 0 { | |
builder.WriteString(",") | |
} | |
if taint.Value != "" { | |
builder.WriteString("{") | |
builder.WriteString("Key:" + fmt.Sprintf("%v", taint.Key) + ",") | |
builder.WriteString("Value:" + fmt.Sprintf("%v", taint.Value) + ",") | |
builder.WriteString("Effect:" + fmt.Sprintf("%v", taint.Effect)) | |
builder.WriteString("}") | |
} else { | |
builder.WriteString("{") | |
builder.WriteString("Key:" + fmt.Sprintf("%v", taint.Key) + ",") | |
builder.WriteString("Effect:" + fmt.Sprintf("%v", taint.Effect)) | |
builder.WriteString("}") | |
} | |
} | |
return fmt.Sprintf("cluster now has taints([%s])", builder.String()) |
Copilot uses AI. Check for mistakes.
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 suggestion, but in this pr I just move the function site, I want to refactor it in a single pr.
d7deebb
to
7620e71
Compare
7620e71
to
ea29052
Compare
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.
/lgtm
Signed-off-by: changzhen <[email protected]>
ea29052
to
3a72ee9
Compare
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango 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 |
/hold cancel |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Add the ClusterTaintPolicy controller to handle taints on the clusters
Which issue(s) this PR fixes:
Part of #6317
Special notes for your reviewer:
Does this PR introduce a user-facing change?: