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

feat: replace instruction annotation with work suspendDispatching field #6043

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vie-serendipity
Copy link
Contributor

What type of PR is this?

/kind deprecation
What this PR does / why we need it:
Replace propagation.karmada.io/instruction with suspendDispatching field. Annotation was just a temporary solution. With the native support of the work API, we should deprecate the use of annotations and utilize the work field instead.
Which issue(s) this PR fixes:
Fixes #5386

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Users who are still using annotations to suspend work should migrate to the `suspendDispatching` field as soon as possible.

@karmada-bot karmada-bot added the kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. label Jan 14, 2025
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 14, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2025

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

Codecov Report

Attention: Patch coverage is 2.63158% with 37 lines in your changes missing coverage. Please review.

Project coverage is 48.09%. Comparing base (446dbe9) to head (85f3dca).
Report is 40 commits behind head on master.

Files with missing lines Patch % Lines
pkg/controllers/mcs/common.go 0.00% 10 Missing ⚠️
pkg/controllers/mcs/service_export_controller.go 0.00% 9 Missing ⚠️
pkg/util/helper/predicate.go 0.00% 6 Missing and 2 partials ⚠️
cmd/agent/app/agent.go 0.00% 3 Missing ⚠️
cmd/controller-manager/app/controllermanager.go 0.00% 3 Missing ⚠️
pkg/util/helper/work.go 0.00% 2 Missing ⚠️
...clusterservice/endpointslice_collect_controller.go 50.00% 1 Missing ⚠️
.../controllers/multiclusterservice/mcs_controller.go 0.00% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6043      +/-   ##
==========================================
- Coverage   48.35%   48.09%   -0.26%     
==========================================
  Files         666      669       +3     
  Lines       54831    55186     +355     
==========================================
+ Hits        26513    26543      +30     
- Misses      26599    26916     +317     
- Partials     1719     1727       +8     
Flag Coverage Δ
unittests 48.09% <2.63%> (-0.26%) ⬇️

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.

@chaosi-zju
Copy link
Member

/retest

@XiShanYongYe-Chang
Copy link
Member

Thanks~
/assign

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks a lot~

pkg/util/work.go Outdated
)

// GetWorkSuspendDispatching will get suspendDispatching field from work spec
func GetWorkSuspendDispatching(spec *workv1alpha1.WorkSpec) []string {
Copy link
Member

Choose a reason for hiding this comment

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

How about moving this function to the pkg/util/helper/work.go file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

)

const (
workKeyIndex = "workSpec.suspendDispatching"
Copy link
Member

Choose a reason for hiding this comment

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

How about renaming this to workSuspendDispatchdingIndex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -46,7 +46,7 @@ const (
//
// Note: This instruction is intended to set on Work objects to indicate the Work should be ignored by
// execution controller. The instruction maybe deprecated once we extend the Work API and no other scenario want this.
PropagationInstruction = "propagation.karmada.io/instruction"
PropagationInstruction = "propagation.karmada.io/instruction" // deprecated
Copy link
Member

Choose a reason for hiding this comment

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

There are still some places in the warehouse that use the variable. Should we replace all the places that use the variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I think we should retain the handling of this label. I just replaced the usage of PropagationInstruction with suspendDispatching in the repository when creating new resources, ensuring NO new resources with the PropagationInstruction label are created. And we can remove it entirely later.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, I think we can clean them up in the next version(v1.14).

By the way, can we mark the PropagationInstruction and the related value to be deprecated like this:

// Deprecated
PropagationInstruction = "propagation.karmada.io/instruction"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

util.ServiceNamespaceLabel: endpointSlice.GetNamespace(),
util.ServiceNameLabel: endpointSlice.GetLabels()[discoveryv1.LabelServiceName],
// indicate the Work should be not propagated since it's collected resource.
util.PropagationInstruction: util.PropagationInstructionSuppressed,
Copy link
Member

Choose a reason for hiding this comment

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

Can we delete this variable in the next version to consider compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think removing this tag won't cause compatibility issues, because I've retained the handling logic for PropagationInstruction, which will still work as intended.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you are right!

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from xishanyongye-chang. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

fix: get false when suspendDispatching is nil

fix: ignore work events when suspendDispatching is true

feat: rename workIndex and mv GetWorkSuspendDispatching to helper

feat: modify the style of Deprecated
Signed-off-by: vie-serendipity <[email protected]>
)

const (
workSuspendDispatchdingIndex = "workSpec.suspendDispatching"
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I made a mistake in my previous comment, a typo Dispatchding -> Dispatching

Comment on lines +87 to +90
if IsWorkSuspendDispatching(obj) {
klog.V(5).Infof("Ignored Work(%s/%s) %s event as dispatching is suspended.", obj.Namespace, obj.Name, eventType)
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

Should such a judgment be added to other places where judgment util.GetLabelValue(obj.Labels, util.PropagationInstruction) == util.PropagationInstructionSuppressed is used, because for users who directly use this version (v1.13), the work in the environment will not have the propagation.karmada.io/instruction label.

For example:

--- a/pkg/controllers/ctrlutil/work.go
+++ b/pkg/controllers/ctrlutil/work.go
@@ -36,7 +36,8 @@ import (

 // CreateOrUpdateWork creates a Work object if not exist, or updates if it already exists.
 func CreateOrUpdateWork(ctx context.Context, client client.Client, workMeta metav1.ObjectMeta, resource *unstructured.Unstructured, options ...WorkOption) error {
-       if workMeta.Labels[util.PropagationInstruction] != util.PropagationInstructionSuppressed {
+       if workMeta.Labels[util.PropagationInstruction] != util.PropagationInstructionSuppressed ||
+               IsWorkSuspendDispatching(obj) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. 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.

Replace work propagation.karmada.io/instruction annotation with work Suspension field
5 participants