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

Label removal from wrapped object does not trigger label removal on managed cluster #367

Open
andreyod opened this issue Mar 6, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@andreyod
Copy link

andreyod commented Mar 6, 2024

Describe the bug
When label is removed from an object wrapped by ManifestWork, it is not removed from the object in the managed cluster.

To Reproduce

  1. Setup OCM with https://open-cluster-management.io/getting-started/quick-start/
  2. Use kubectl to create a ManifestWork on the hub with the following yaml file. Note the test: test label in the deployment metadata.
apiVersion: work.open-cluster-management.io/v1
kind: ManifestWork
metadata:
  namespace: cluster1
  name: my-first-work
spec:
  workload:
    manifests:
      - apiVersion: v1
        kind: ServiceAccount
        metadata:
          namespace: default
          name: my-sa
      - apiVersion: apps/v1
        kind: Deployment
        metadata:
          namespace: default
          name: nginx-deployment
          labels:
            app: nginx
            test: test
        spec:
          replicas: 1
          selector:
            matchLabels:
              app: nginx
          template:
            metadata:
              labels:
                app: nginx
            spec:
              serviceAccountName: my-sa
              containers:
                - name: nginx
                  image: nginx:1.14.2
                  ports:
                    - containerPort: 80
  1. Ensure deployment nginx-deployment in cluster1 is labeled with the test label
    kubectl --context kind-cluster1 get deployment nginx-deployment -o yaml
  2. Edit the ManifestWork and remove the test label.
    kubectl --context kind-hub edit manifestworks my-first-work -n cluster1
  3. Deployment nginx-deployment in cluster1 is still labeled with the test label.

Expected behavior
In step 6 above, I expect the test label to be removed.

Environment ie: OCM version, Kubernetes version and provider:
kind v0.19.0 go1.19 linux/amd64

Additional context
Add new label and update a label value works as expected.

@qiujian16
Copy link
Member

we use openshift/library-go to apply resources, the label is always merged. see mergemap here https://github.com/openshift/library-go/blob/master/pkg/operator/resource/resourcemerge/object_merger.go#L141

To remove the label, you will need to explicitly set it by adding a "-" suffix, e.g.

labels:
  test: test-

@andreyod
Copy link
Author

andreyod commented Mar 7, 2024

From looking at https://github.com/openshift/library-go/blob/master/pkg/operator/resource/resourcemerge/object_merger.go#L141 , I can see that the key is checked for "-" suffix, not the value.
Anyway this edit is invalid for labels. Valid label key and value must begin and end with an alphanumeric character ([a-z0-9A-Z]) according to https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

@qiujian16
Copy link
Member

/assign

Copy link

This issue is stale because it has been open for 120 days with no activity. After 14 days of inactivity, it will be closed. Remove the stable label to prevent this issue from being closed.

@github-actions github-actions bot added the Stale label Jul 17, 2024
@qiujian16 qiujian16 removed the Stale label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

2 participants