Variables in kustomization.yaml
Is it possible to use go template variables in kustomization.yaml file?
For example I want to have something like this:
$ cat kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/kubernetes-sigs/metrics-server/releases/download/{{ .Values.appVersion }}/components.yaml
patches:
- target:
group: apps
version: v1
kind: Deployment
name: metrics-server
path: patches/deployment.yaml
@olfway Hey! Interesting idea. It's impossible today, but worth investigating.
What .Values.appVersion should refer to, btw? The values of the release, or helmfile state(environment) values?
I.e. what if helmfile allowed this?
releases:
- name: yourapp
kustomization: some/dir/kustomization.yaml.gotmpl
values:
- appVersion: ver
I thought .Values. should refer to the values of the release, like in your example
I absolutely need this feature. My use case is this use a namespace for the installation but also set the subjects[0].namespace in ClusterRoleBinding.rbac.authorization.k8s.io. So the question is, how do I inject env var of ROOK_NFS_OPERATOR_NAMESPACE into the kustomize with helmfile?
releases:
{{- if eq (env "NFS_STRATEGY") "rook" }}
- name: rook-nfs-operator
namespace: {{ env "ROOK_NFS_OPERATOR_NAMESPACE" | default "rook-nfs-system" }}
chart: ./rook-nfs-operator
hooks:
- events:
- prepare
- cleanup
command: ./helmify.sh
args:
- "{{`{{if eq .Event.Name \"prepare\"}}build{{else}}clean{{end}}`}}"
- "{{`{{.Release.Chart}}`}}"
- default
{{- end }}
In my rook-nfs-operator-kustomize/base/operator.yaml, I will have this:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: rook-nfs-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: rook-nfs-operator
subjects:
- kind: ServiceAccount
name: rook-nfs-operator
namespace: $(ROOK_NFS_OPERATOR_NAMESPACE)
@darkn3rd Hey! How do you define ROOK_NFS_OPERATOR_NAMESPACE in your kustomization? Is it just an entry under kustomize vars?
AFAIK, it's kustomize's own restriction that you can't inject arbitrary built-time args. I'm not sure how we workaround that.
This feature would be pretty amazing. As far as I've been testing, we can't pass values to the Kustomize builds, which is very important in case you are building the manifests for different teams and/or environments. For example, if you are using Helmfile to deploy overlays of Kubeflow that depend on the environment, you must write your overlays and patches in the helmfile.yaml file because the patches that would be inside the different Kustomize overlays wouldn't get the values available in the helmfile.yaml file.