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

Variable Fieldpath can't reference key name with dashes #3421

Closed
kferrone opened this issue Jan 5, 2021 · 7 comments
Closed

Variable Fieldpath can't reference key name with dashes #3421

kferrone opened this issue Jan 5, 2021 · 7 comments
Labels
area/api issues for api module kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@kferrone
Copy link

kferrone commented Jan 5, 2021

Describe the bug

I have a kustomize variable which was working until a recent update. Now the variables are misbehaving for strange reasons.

Files that can reproduce the issue

Here is the var in my kustomization.yaml

vars:
  - name: ZONE
    objref:
      apiVersion: v1
      kind: PersistentVolume
      name: bitcoind
    fieldref:
      fieldpath: metadata.labels[failure-domain.beta.kubernetes.io/zone]

Then here is the corresponding PV with the label
pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: bitcoind
  labels:
    failure-domain.beta.kubernetes.io/region: eu-west-2
    failure-domain.beta.kubernetes.io/zone: eu-west-2a

Expected output

I expect the variable to be able to reference any key even with special characters in the name

Actual output

Error: field specified in var '{ZONE ~G_v1_PersistentVolume {metadata.labels[failure-domain.beta.kubernetes.io/zone]}}' not found in corresponding resource

Kustomize version

{Version:kustomize/v3.9.1 GitCommit:7439f1809e5ccd4677ed52be7f98f2ad75122a93 BuildDate:2020-12-30T00:43:15+00:00 GoOs:darwin GoArch:amd64}

Platform

Tested on Mac and Windows, both had the issue

Additional context

I pretty much determined it's the dash because below works:

vars:
  - name: ZONE
    objref:
      apiVersion: v1
      kind: PersistentVolume
      name: bitcoind
    fieldref:
      fieldpath: metadata.labels[failure_domain.beta.kubernetes.io/zone]

... so long as there are no dashes -, a key can be referenced even with dots and slashes in the name

@kferrone kferrone changed the title Fieldpath with key name with dots Variabel Fieldpath can't reference key name with dashes Jan 5, 2021
@kferrone kferrone changed the title Variabel Fieldpath can't reference key name with dashes Variable Fieldpath can't reference key name with dashes Jan 5, 2021
@Shell32-Natsu
Copy link
Contributor

fields := strings.Split(path, ".")

In kustomize version >= v3.9, we just simply split the field path by .. We may improve this in future.

BTW, we are planning to remove var from kustomize. #2052

@Shell32-Natsu Shell32-Natsu added area/api issues for api module 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. priority/backlog Higher priority than priority/awaiting-more-evidence. labels Jan 7, 2021
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

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 Apr 7, 2021
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

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 May 7, 2021
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@diogosilva30
Copy link

diogosilva30 commented Sep 18, 2023

What is the solution for this?

My ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
ingressClassName: traefik
metadata:
  name: longhorn-ingress
  annotations:
    external-dns.alpha.kubernetes.io/target: $(DNS)

My replacement:

replacements:
  - source:
      kind: Ingress
      fieldPath: metadata.annotations.dns
      name: longhorn-ingress
    targets:
      - select:
          kind: Ingress
          name: longhorn-ingress
        fieldPaths:
          - metadata.annotations[external-dns.alpha.kubernetes.io/target]

I have tried wrapping it with quotes. No success.

@aeciopires
Copy link

I had the same problem and solved it with this tip: #1256 (comment)

I used ~1 to represent a /

(workaround)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api issues for api module kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

6 participants