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

replacements: Unable to add/create a new array element #4469

Closed
jceb opened this issue Feb 11, 2022 · 6 comments · Fixed by #4886
Closed

replacements: Unable to add/create a new array element #4469

jceb opened this issue Feb 11, 2022 · 6 comments · Fixed by #4886
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@jceb
Copy link

jceb commented Feb 11, 2022

Describe the bug

I'd like to copy the host name from an Ingress and use it in a newly created tls section. However, kustomize seems to be unable to create arrays to build the tls section.

Files that can reproduce the issue

ingress.yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myingress
spec:
  rules:
    - host: myingress.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-svc
                port:
                  number: 80

kustomize.yaml:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ingress.yaml

replacements:
  - source:
      kind: Ingress
      name: myingress
      fieldPath: spec.rules.0.host
    targets:
      - select:
          kind: Ingress
          name: myingress
        fieldPaths:
          - spec.tls.0.hosts.0
          - spec.tls.0.secretName
        options:
          create: true

Expected output:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myingress
spec:
  rules:
    - host: myingress.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-svc
                port:
                  number: 80
tls:
  - hosts:
    - myingress.example.com
    secretName: myingress.example.com

Actual output:

Error: accumulating components: accumulateDirectory: "recursed accumulation of path '$PWD': wrong Node Kind for spec.tls expected: SequenceNode was MappingNode: value: {{}}"

Workaround:

Pre-create the tls structure, including a value in hosts, otherwise it won't create the entry.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

replacements:
  - source:
      kind: Ingress
      name: myingress
      fieldPath: spec.rules.0.host
    targets:
      - select:
          kind: Ingress
          name: myingress
        fieldPaths:
          - spec.tls.0.hosts.0
          - spec.tls.0.secretName
        options:
          create: true
  tls:
    - hosts: ["dummy-entry-to-make-kustomize-replacements-work"]

Expected output

Actual output

Kustomize version

Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.6
", GitCommit:"f59f5c2fda36e4036b49ec027e556a15456108f0", GitTreeState:"
archive", BuildDate:"1980-01-01T00:00:00Z", GoVersion:"go1.16.13", Comp
iler:"gc", Platform:"linux/amd64"}

Additional context

@jceb jceb added the kind/bug Categorizes issue or PR as related to a bug. label Feb 11, 2022
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Feb 11, 2022
@KnVerey
Copy link
Contributor

KnVerey commented Feb 16, 2022

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 16, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 17, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 16, 2022
@jceb
Copy link
Author

jceb commented Jun 17, 2022

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jun 17, 2022
@koba1t
Copy link
Member

koba1t commented Sep 11, 2022

/assign koba1t

@KnVerey
Copy link
Contributor

KnVerey commented Sep 12, 2022

@koba1t @natasha41575 how do we want this feature to work? I've been thinking about this lately as part of looking into #4561, which is required for the use case in #4761 (the regression is from incorrectly ignoring the invalid paths to a panic--it should throw an error, which will break that person's workflow). In short, I'm wondering if we need to constrain this feature to be able to create only append an array element. To give an extreme example, if they have 2 elements and try to create something in element 100, it doesn't make sense for us to try to create 98 blank elements in the middle. But if they have 2 and they target the 3rd, we have complete knowledge of what the overall array should contain.

Incidentally, you may want to hold off on the implementation until I PR the fix to #4561, which will hopefully be soon. I currently expect that to contain a fairly big change to the transformer, because it surfaces the fact that we're currently splitting the implementation across two different filters, neither of which actually logically should behave the way we need it to for our ultimate feature set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants