karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.49k stars 890 forks source link

OverridePolicy can not overwrite annotations #4014

Closed HuckOps closed 10 months ago

HuckOps commented 1 year ago

Please provide an in-depth description of the question you have: This is a service:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/nks-load-balancer-disabled: "False"
    service.beta.kubernetes.io/nks-load-balancer-platform: nks
  creationTimestamp: "2023-08-29T13:34:01Z"
  labels:
    app: testing-app
    propagationpolicy.karmada.io/name: testing-app-service
    propagationpolicy.karmada.io/namespace: testing
  name: app
  namespace:testing
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: testing-app
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

when i use overridepolicy to inject an annotations named service.beta.kubernetes.io/nks-load-balancer-set-vpcid: TEMP like this:

apiVersion: policy.karmada.io/v1alpha1
kind: OverridePolicy
metadata:
  annotations:
  creationTimestamp: "2023-08-29T13:34:01Z"
  name: testing-app-service-cluster1
  namespace: testing
spec:
  overrideRules:
  - overriders:
      plaintext:
      - operator: add
        path: /metadata/annotations/"service.beta.kubernetes.io/nks-load-balancer-set-vpcid"
        value: xxxxxxxxxxxxxxx
    targetCluster:
      clusterNames:
      - cluster1
  overriders: {}
  resourceSelectors:
  - apiVersion: v1
    kind: Service
    name: app
    namespace: testing

But resourcebinding return an event log:

  Warning  SyncWorkFailed          6s (x4 over 29m)      binding-rb-controller  add operation does not apply: doc is missing path: "/metadata/annotations/"service.beta.kubernetes.io/nks-load-balancer-set-vpcid"": missing value

So, how can i modify overridepolicy?

What do you think about this question?:

Maybe format error

Environment:

wu0407 commented 1 year ago

A more convenient way is to use AnnotationsOverrider directly. https://karmada.io/docs/userguide/scheduling/override-policy#annotationsoverrider If you use plaintext change it to like this:

       - operator: add
        path: /metadata/annotations/service.beta.kubernetes.io~1nks-load-balancer-set-vpcid
        value: xxxxxxxxxxxxxxx

The “/” in the path needs to be replaced with "~1" https://datatracker.ietf.org/doc/html/rfc6901/#section-4

XiShanYongYe-Chang commented 10 months ago

It seems that it has been answered. Thanks all of you. /close

karmada-bot commented 10 months ago

@XiShanYongYe-Chang: Closing this issue.

In response to [this](https://github.com/karmada-io/karmada/issues/4014#issuecomment-1905542117): >It seems that it has been answered. Thanks all of you. >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.