Helmfile: Variables in kustomization.yaml

Created on 8 Jul 2020  路  5Comments  路  Source: roboll/helmfile

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
feature request

Most helpful comment

I.e. what if helmfile allowed this?

releases:
- name: yourapp
  kustomization: some/dir/kustomization.yaml.gotmpl
  values:
  - appVersion: ver

All 5 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willejs picture willejs  路  4Comments

aslafy-z picture aslafy-z  路  4Comments

michaelpporter picture michaelpporter  路  3Comments

ppawiggers picture ppawiggers  路  3Comments

mumoshu picture mumoshu  路  4Comments