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

Var reference does not work in volumes #1540

Closed
phillebaba opened this issue Sep 17, 2019 · 6 comments
Closed

Var reference does not work in volumes #1540

phillebaba opened this issue Sep 17, 2019 · 6 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@phillebaba
Copy link

Var reference does not work when used in volumes.

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nfs-client-provisioner
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: $(NFS_SERVER)
            - name: NFS_PATH
              value: /var/nfs
      volumes:
      - name: nfs-client-root
        nfs:
          server: $(NFS_SERVER)
          path: /var/nfs

When kustomizing this manifest with a varible that references a Service ClusterIP the following is outputed.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-client-provisioner
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      containers:
      - env:
        - name: PROVISIONER_NAME
          value: fuseim.pri/ifs
        - name: NFS_SERVER
          value: 10.43.118.159
        - name: NFS_PATH
          value: /var/nfs
        image: quay.io/external_storage/nfs-client-provisioner-arm:latest
        name: nfs-client-provisioner
        volumeMounts:
        - mountPath: /persistentvolumes
          name: nfs-client-root
      serviceAccountName: nfs-client-provisioner
      volumes:
      - name: nfs-client-root
        nfs:
          path: /var/nfs
          server: $(NFS_SERVER)

I would expect the $(NFS_SERVER) in the volume to also be replaced with the ClusterIP. I need this as there are currently issues with using the service dns to resolve the ip of a nfs server running in the same cluster.

@jbrette
Copy link
Contributor

jbrette commented Sep 17, 2019

@phillebaba You can solve that the complicated way by changing the variable reference configuration.
Have a look here
and especially at the varreference.yaml kustomize config file

varReference:
- path: spec/template/spec/volumes[]/nfs
  kind: Deployment

or you can do it the easy way leveraging this PR. Check how much more simple the configuration is.
No need for varReference file nor entry in the kustomization.yaml.
The only thing you need to do is to have an variable name like this:
$(..)

In any case, I don't think there is a bug in kustomize.

/cc @monopole @Liujingfang1 @ian-howell

@phillebaba
Copy link
Author

Yes you are right that this is not a bug. In hindsight I realize that I should have spent more time researching my issues. Your example solved my issue, and I must thank you @jbrette as they were really detailed and easy to understand.

I guess the reason I thought this was a bug was because I dont really understand why kustomize does variable replacement in some fields by default and not in others.

I will be following your PR as I do agree that it creates a much clean kustomization file.

@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-testing, kubernetes/test-infra and/or fejta.
/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 Dec 18, 2019
@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-testing, kubernetes/test-infra and/or fejta.
/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 Jan 17, 2020
@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-testing, kubernetes/test-infra and/or fejta.
/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-testing, kubernetes/test-infra and/or fejta.
/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants