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

v3: feature request: yaml should provide function to disable unique keys. #751

Open
xyz-li opened this issue Jun 18, 2021 · 3 comments
Open

Comments

@xyz-li
Copy link

xyz-li commented Jun 18, 2021

Why we need this feature?

The strict flag was split into knownFields and uniqueKeys in commit 085f382.
But in commit 309c9d1,uniqueKeys was dropped and set to true.
If yaml text has duplicate keys, Decoder.Decode and yaml.Unmarshal will return errors. This result in application likes kustomize returns errors after version v3.9.0, since kustomize uses yaml.Unmarshal of v3.
I think it is a good option to provide a function to disable unique keys, then these application could ignore duplicate keys.

Related issues

kubernetes-sigs/kustomize#3480
kubesphere/kubesphere#3933

@davisford
Copy link

Please consider adding this. I have a real world example. If you look at the spec for deploying ingress-nginx to AWS with network load balancer terminating TLS at the load balancer, there is a section where kustomize thinks there are duplicate keys in this section (I don't really understand why since each entry is keyed with a different name):

          ports:
            - name: http
              containerPort: 80
              protocol: TCP
            - name: https
              containerPort: 80
              protocol: TCP
            - name: tohttps
              containerPort: 2443
              protocol: TCP
            - name: webhook
              containerPort: 8443
              protocol: TCP

When run through kustomize (which uses go-yaml), it generates the following error:

Kustomization reconciliation failed: Deployment/ingress-nginx/ingress-nginx-controller dry-run failed, error: failed to create manager for existing fields: failed to convert new object (apps/v1, Kind=Deployment) to smd typed: .spec.template.spec.containers[name="controller"].ports: duplicate entries for key [containerPort=80,protocol="TCP"]

But this is the way the spec needs to be. I know @xyz-li added a PR in Kustomize to disable unique key check but it was rejected because they wanted to handle it here instead.

As it stands right now, my deployment is broken because of this. Can someone please strongly consider adopting this feature?

@natasha41575
Copy link

natasha41575 commented Nov 5, 2021

@davisford What you have is duplicate kubernetes merge keys. Related: kubernetes/kubernetes#39188

That is not the same thing as YAML keys, which what this issue is about. go-yaml (correctly) throws an error with something like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: podinfo
spec:
  template:
    spec:
      containers:
      - env:
        - name: PODINFO_UI_COLOR
          value: "#34577c"
        env:
          - name: PODINFO_UI_COLOR
            value: "#34577c"

Or something like:

ports:
  - name: http
    containerPort: 8080
    containerPort: 80
    protocol: TCP

(Notice the duplicate env/containerPort keys in a single YAML sequence element.)

As I've stated in the other PR you commented on in kustomize, I believe that your problem is with duplicate kubernetes merge keys, which is distinct from YAML keys and probably not related to this issue.

@MeNsaaH
Copy link

MeNsaaH commented Jan 18, 2024

Is this stalled? Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants