karmada-io / karmada

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

unable add annotation use plaintext overide whether annotation fileld is exist or not exist #3923

Open wu0407 opened 1 year ago

wu0407 commented 1 year ago

What happened: I want to add annotation to spec.template.metadata.annotation whether annotation fileld is exist, but plaintext overide unable to achieve this goal.

direct add annotation

configuration:

spec:
 overrideRules:
  - overriders:
      plaintext:
      - path: /spec/template/metadata/annotations/test
        operator: add
        value: "test-value"

It is ok on spec.template.metadata.annotations is exist.

                        {"spec": {
                "template": {
                    "metadata": {
                        "annotations": {
                            "c": "d"
                        },
                        "labels": {
                            "a": "b"
                        }
                    }
                }
            }}

result

                            {"spec": {
                "template": {
                    "metadata": {
                        "annotations": {
                            "c": "d",
                                                        "test": "test-value"
                        },
                        "labels": {
                            "a": "b"
                        }
                    }
                }
            }}

It is not ok on spec.template.metadata.annotations is not exist.

                        {"spec": {
                "template": {
                    "metadata": {
                        "labels": {
                            "a": "b"
                        }
                    }
                }
            }}

result:

E0809 07:50:41.625787       1 controller.go:329] "Reconciler error" err="add operation does not apply: doc is missing path: \"/spec/template/metadata/annotations/test\": missing value" controller="resourcebinding" controllerGroup="work.karmada.io" controllerKind="ResourceBinding" ResourceBinding="xxxxx/xxxxx-deployment" namespace="xxxxx" name="xxxx-deployment" reconcileID=b87a1530-c398-4393-82fa-82bef68ac8cb

Another way is add annotation field first, then add annotation. But It is not work.

configuration:

spec:
 overrideRules:
  - overriders:
      plaintext:
      - path: /spec/template/metadata/annotations
        operator: add
        value: {}
      - path: /spec/template/metadata/annotations/test
        operator: add
        value: "test-value"

It is not ok on spec.template.metadata.annotations is exist.

                        {"spec": {
                "template": {
                    "metadata": {
                        "annotations": {
                            "c": "d"
                        },
                        "labels": {
                            "a": "b"
                        }
                    }
                }
            }}

result

                            {"spec": {
                "template": {
                    "metadata": {
                        "annotations": {
                                                        "test": "test-value"
                        },
                        "labels": {
                            "a": "b"
                        }
                    }
                }
            }}

It is ok on spec.template.metadata.annotations is not exist.

                        {"spec": {
                "template": {
                    "metadata": {
                        "labels": {
                            "a": "b"
                        }
                    }
                }
            }}

result:

{"spec": {
                "template": {
                    "metadata": {
                        "annotations": {
                                                        "test": "test-value"
                        },
                        "labels": {
                            "a": "b"
                        }
                    }
                }
            }}

the last method is one deployment one configuration, so inconvenient.

What you expected to happen: add new annotation successed

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

chaunceyjiang commented 1 year ago

I think it meets expectations. Please refer to RFC 6902

wu0407 commented 1 year ago

Users don't care about this, they need a more user-friendly configuration experience. And previous already fix on LabelAnnotationOverrider https://github.com/karmada-io/karmada/pull/2971