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 21.27660% with 37 lines in your changes missing coverage. Please review.

Project coverage is 48.07%. Comparing base (006cf70) to head (eee26ca).

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.07%   48.07%           
=======================================
  Files         668      669    +1     
  Lines       55327    55348   +21     
=======================================
+ Hits        26597    26608   +11     
- Misses      26992    27003   +11     
+ Partials     1738     1737    -1     
Flag Coverage Δ
unittests 48.07% <21.27%> (+<0.01%) ⬆️

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!

)

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

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, my mistake, I didn't double check.

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) {

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 the handling here is not necessary, we can directly remove it if we use suspendDispatching. For some other places, we cannot use suspendDispatching filter because the suspendDispatching condition for work needs to be updated in reconcile.

https://github.com/karmada-io/karmada/blob/4982157d65188c45916b06b080c46761eac89155/pkg/util/helper/predicate.go#L82C1-L85C4

Copy link
Member

Choose a reason for hiding this comment

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

I think the handling here is not necessary, we can directly remove it if we use suspendDispatching.

For a new work formed by collecting Endpointslices, this condition judgment is always valid, which is equivalent to invalid judgment.

For some other places, we cannot use suspendDispatching filter because the suspendDispatching condition for work needs to be updated in reconcile.

I'm sorry, I don't quite understand this point. Could you explain it a little bit?

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 mean, when using PropagationInstruction for the execution controller's predicate, the suspendDispatching field cannot be used as a filtering condition because the execution controller needs to update the Dispatching condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For a new work formed by collecting Endpointslices, this condition judgment is always valid, which is equivalent to invalid judgment.

So I think we can remove this judgment directly, according to my understanding adding labels and annotations to the work's manifest should be fine.

I'm worried that if we add IsWorkSuspendDispatching(obj) in the jugement here, user-created suspended works might lose these label and annotation information. If we add IsWorkSuspendDispatching(obj) here, we might add some handle in the mutating webhook.

// Skip label/annotate the workload of Work that is not intended to be propagated.
if work.Labels[util.PropagationInstruction] != util.PropagationInstructionSuppressed {
setLabelsAndAnnotationsForWorkload(workloadObj, work)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about progress, I'm busy lately, I'll probably test it next week, are there any releases planned lately that require this pr?

Copy link
Member

Choose a reason for hiding this comment

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

Version 1.13 will be released at the end of February. I'm not sure if we can catch up with it. Let's follow your schedule.

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 tested and it works fine. I followed the following steps to test:

  1. Use local-up-karmada script to make a test enviroment.
  2. Build my karmada controller manager image and use it.
  3. Follow https://karmada.io/docs/userguide/service/multi-cluster-service to test multi cluster discovery.
  4. Endpointslice is propagted correctly.

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 your test!

I think we can move on. The current pr and master branch conflict, can you help solve it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@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

feat: rename workIndex and mv GetWorkSuspendDispatching to helper

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

feat: label and annotate workloads even though work is suspended

Signed-off-by: vie-serendipity <[email protected]>

test: fix ut for CreateOrUpdateWork

Signed-off-by: vie-serendipity <[email protected]>
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