Skip to content

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

Conversation

XiShanYongYe-Chang
Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang commented May 13, 2025

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?:

`karmada-controller-manager`: Added the `clustertaintpolicy` controller to manage cluster taint based on ClusterTaintPolicy.

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label May 13, 2025
@XiShanYongYe-Chang XiShanYongYe-Chang marked this pull request as draft May 13, 2025 06:35
@karmada-bot karmada-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 13, 2025
@karmada-bot karmada-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 13, 2025
@XiShanYongYe-Chang
Copy link
Member Author

Waiting for #6319

@codecov-commenter
Copy link

codecov-commenter commented May 13, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 31.57895% with 117 lines in your changes missing coverage. Please review.

Project coverage is 49.27%. Comparing base (5730c74) to head (3a72ee9).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...controllers/taint/clustertaintpolicy_controller.go 40.15% 79 Missing ⚠️
pkg/util/helper/taint.go 0.00% 24 Missing ⚠️
cmd/controller-manager/app/controllermanager.go 0.00% 14 Missing ⚠️

❗ 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     
Flag Coverage Δ
unittests 49.27% <31.57%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RainbowMango
Copy link
Member

Please rebase this

@XiShanYongYe-Chang XiShanYongYe-Chang force-pushed the add-clustertaintpolicy-controller branch from 8a916b5 to d1bbdac Compare May 15, 2025 12:31
@XiShanYongYe-Chang XiShanYongYe-Chang marked this pull request as ready for review May 15, 2025 12:31
@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels May 15, 2025
@karmada-bot karmada-bot requested a review from CharlesQQ May 15, 2025 12:31
@XiShanYongYe-Chang
Copy link
Member Author

XiShanYongYe-Chang commented May 15, 2025

/hold
Under Testing.

@karmada-bot karmada-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 15, 2025
@XiShanYongYe-Chang XiShanYongYe-Chang force-pushed the add-clustertaintpolicy-controller branch from d1bbdac to d7deebb Compare May 15, 2025 13:10
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/assign

@RainbowMango RainbowMango requested a review from Copilot May 16, 2025 06:26
Copy link
Contributor

@Copilot Copilot AI left a 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

Comment on lines +221 to +242
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)
Copy link
Preview

Copilot AI May 16, 2025

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.

Suggested change
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.

Copy link
Member Author

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.

@XiShanYongYe-Chang XiShanYongYe-Chang force-pushed the add-clustertaintpolicy-controller branch from d7deebb to 7620e71 Compare May 16, 2025 06:30
@karmada-bot karmada-bot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 16, 2025
@karmada-bot karmada-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 16, 2025
@XiShanYongYe-Chang XiShanYongYe-Chang force-pushed the add-clustertaintpolicy-controller branch from 7620e71 to ea29052 Compare May 16, 2025 08:01
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label May 16, 2025
@XiShanYongYe-Chang XiShanYongYe-Chang force-pushed the add-clustertaintpolicy-controller branch from ea29052 to 3a72ee9 Compare May 16, 2025 10:03
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label May 16, 2025
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label May 17, 2025
@karmada-bot
Copy link
Collaborator

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 17, 2025
@RainbowMango
Copy link
Member

/hold cancel

@karmada-bot karmada-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 17, 2025
@karmada-bot karmada-bot merged commit ab9e018 into karmada-io:master May 17, 2025
24 checks passed
@XiShanYongYe-Chang XiShanYongYe-Chang deleted the add-clustertaintpolicy-controller branch May 22, 2025 06:39
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants