How do I assign value to variable in helmfile?

4/16/2018

How do I assign a variable within a helmfile?

context: example.com                # kube-context (--kube-context)

releases:
  # Published chart example
  - name: controller-pod-nginx                  # Name of this release
    namespace: ingress-nginx                    # Target namespace
    chart: stable/nginx-ingress                 # The chart being installed to create this release, referenced by `repository/chart` syntax
    set:                                        # Values (--set)
      - name: rbac.create
        value: true
      - name: controller.service.annotations
        value: 'service.beta.kubernetes.io/aws-load-balancer-ssl-ports:https'

Error message

 helmfile -f deploy_cp_ns_ingress-nginx.yaml sync
exec: helm repo add roboll http://roboll.io/charts --kube-context example.com
"roboll" has been added to your repositories
exec: helm repo update --kube-context example.com
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "roboll" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
exec: helm upgrade --install controller-pod-nginx stable/nginx-ingress --namespace ingress-nginx --set rbac.create=true,controller.service.annotations=service.beta.kubernetes.io/aws-load-balancer-ssl-ports:https --kube-context example.com
Error: UPGRADE FAILED: YAML parse error on nginx-ingress/templates/controller-service.yaml: error unmarshaling JSON: json: cannot unmarshal string into Go struct field .annotations of type map[string]string
err: exit status 1

If I use a pure helm installation that works with no problem:

helm install stable/nginx-ingress --set rbac.create=true --set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-backend-protocol"=http --namespace=ingress-nginx

That works with no problem. I will need to add numerous annotations.

-- user2156115
helmfile
kubernetes
kubernetes-helm
kubernetes-ingress

1 Answer

8/10/2018

Typically, if using the set parameter in helmfile.yaml, you would specify it this way:

set:
  - name: 'controller.service.annotations.service\.beta\.kubernetes\.io/aws-load-balancer-ssl-ports'
    value: 'https'

NOTE the backslashes are used to escape the dots in the key service.beta.kubernetes.io/aws-load-balancer-ssl-ports. Dots in YAML selectors have a special meaning, so we need to escape them.

However, since that's very unintuitive, I recommend using inline values. Then it looks something like this:

values:
  - rbac:
      create: true
    controller:
      service:
        annotations:
          "service.beta.kubernetes.io/aws-load-balancer-ssl-ports": true

NOTE In the end, it's always tricky with helm since there's no universal specification for how to consume values.yaml - that is, the structure can be arbitrary. I am assuming that it's a map, since most charts we use define annotations as a simple map (as opposed to a list).

Here's an example where we define an annotation for replica.annotations.iam\.amazonaws\.com/role

https://github.com/cloudposse/geodesic/blob/0.12.0/rootfs/conf/kops/helmfile.yaml#L104-L105

And here's how we do it for inline values: (we switched to using this everywhere) https://github.com/cloudposse/helmfiles/blob/0.2.4/helmfile.d/0300.chartmuseum.yaml#L52-L55

-- Erik Osterman
Source: StackOverflow