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

How to update varreference #2704

Closed
benjamin-bergia opened this issue Jul 8, 2020 · 2 comments
Closed

How to update varreference #2704

benjamin-bergia opened this issue Jul 8, 2020 · 2 comments

Comments

@benjamin-bergia
Copy link

Hi,

I am kind of lost here. I need to reference a field from custom object in one of my variables and obviously, it is not in the default list of of "referenceable" fields/objects allowed by kustomize.

The documentation here https://kubernetes-sigs.github.io/kustomize/faq/#some-field-is-not-transformed-by-kustomize mentions adding a configurations field. But the example there https://github.com/kubernetes-sigs/kustomize/blob/master/examples/configureBuiltinPlugin.md#the-old-way-to-do-this talk about it being the "old way" of doing it.

What is the simplest and recommended way of adding a field to the list of fields that can be referenced by variables?

As a bonus point question, why is there a list of fields that are allowed in the first place? Is there any risk in simply letting people reference any object field containing a string?

@neilharris123
Copy link

neilharris123 commented Aug 19, 2020

In your kustomization.yaml, add field:

configurations:
- my_variables.yaml

And in my_variables.yaml file, which should be in the same directory as the kustomization.yaml, you can reference different fields like so:

varReference:
- kind: Deployment
  path: spec/template/spec/containers/volumeMounts/name
- kind: Deployment
  path: spec/template/spec/volumes/configMap/name

The above example would allow you to add your vars to the volumeMounts name for a Deployment, or the configMap name for a Deployment. This logic can be used to point at and add your envs to different fields in any k8s resource.

To answer your question of why a list of fields is required in the first place, I can't answer that. I do also wonder why this is necessary. I don't see why having to create a separate list in order to use your vars is a good idea personally.

@Shell32-Natsu
Copy link
Contributor

@neilharris123 provided a good example for customizing fieldSpecs for varReference. You don't need to have a "a list of fields that are allowed in the first place". The fieldSpecs in configurations files will be merged with builtin fieldSpecs.

Another method to customize the fieldSpecs is using varReference plugin.

You can choose the way you prefer.

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

No branches or pull requests

3 participants