pnovotnak
pnovotnak

Reputation: 4581

Helm: How to Override Value with Periods in Name

I am trying to script setup of Jenkins so that I can create and tear down Jenkins clusters programmatically with helm. I've hit an annoying snag where I cannot set a key with dots in the name. My helm values.yaml file looks like this:

---
rbac:
  install: true

Master:
  HostName: jenkins.mycompany.com
  ServiceType: ClusterIP
  ImageTag: lts
  InstallPlugins:
    - kubernetes
    - workflow-aggregator
    - workflow-job
    - credentials-binding
    - git
    - blueocean
    - github
    - github-oauth

  ScriptApproval:
    - "method groovy.json.JsonSlurperClassic parseText java.lang.String"
    - "new groovy.json.JsonSlurperClassic"
    - "staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods leftShift java.util.Map java.util.Map"
    - "staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods split java.lang.String"
    - "method java.util.Collection toArray"
    - "staticMethod org.kohsuke.groovy.sandbox.impl.Checker checkedCall java.lang.Object boolean boolean java.lang.String java.lang.Object[]"
    - "staticMethod org.kohsuke.groovy.sandbox.impl.Checker checkedGetProperty java.lang.Object boolean boolean java.lang.Object"

  Ingress:
    Annotations:
      kubernetes.io/ingress.class: nginx
      kubernetes.io/tls-acme: "true"
    TLS:
      - secretName: jenkins-mycompany-com
        hosts:
          - jenkins.mycompany.com

  Memory: "2Gi"
  # This breaks the init container
  # RunAsUser: 1000
  # FSGroup: 1000

Agent:
  Enabled: false
  ImageTag: latest

After installing cert-manager, external-dns, nginx-ingress (for now via a bash script) I install it like so:

helm install --values helm/jenkins.yml stable/jenkins

I failed to read the letsencrypt docs at all, so throughout the course of testing I used my production quota. I want to be able to add an annotation to the Ingress: certmanager.k8s.io/cluster-issuer: letsencrypt-staging so that I can continue testing (and set this as the default in the future, overriding when I'm ready for production).

The trouble is... I can't figure out how to pass this via the --set flag, since there are periods in the key name. I've tried:

helm install --values helm/jenkins.yml stable/jenkins --set Master.Ingress.Annotations.certmanager.k8s.io/cluster-issuer=letsencrypt-staging

and

helm install --values helm/jenkins.yml stable/jenkins --set Master.Ingress.Annotations.certmanager\.k8s\.io/cluster-issuer=letsencrypt-staging

I can of course solve this by adding a value that I use as a flag, but it's less explicit. Is there any way to set it directly?

Upvotes: 40

Views: 24988

Answers (4)

AlfeG
AlfeG

Reputation: 1473

In case someone try to do so from Powershell/PWSH

--set "server.serviceAccount.annotations.azure\.workload\.identity/client-id=$identity"

Upvotes: 1

TeeTee
TeeTee

Reputation: 147

If you are doing this in Jenkins within a shell script like this:

sh """
...
--set-string datasources.'datasources\\.yaml'.datasources[1].secureJsonData.token=$TOKEN \
...
"""

I'm not sure if this is the best explanation but I'll give it a shot.... Groovy interprets shell scripts with backslashes differently than a normal shell script because in Jenkins this is being written inside a shell script. The double escape is needed so Groovy ignores the first backslash and then helm ignores the second. This problem took me too long to solve so I'd figure I'd share what I found for anyone stuck in the same boat.

Upvotes: 0

sqoter3
sqoter3

Reputation: 169

Use \ to escape the dots in the key. Quotation marks are required to prevent shell interpreting the \ character.

helm install --values helm/jenkins.yml stable/jenkins --set 'Master.Ingress.Annotations.certmanager\.k8s\.io/cluster-issuer=letsencrypt-staging'

Helm requires these characters to be escaped: . [ , =

Source: https://paul-boone.medium.com/helm-chart-install-advanced-usage-of-the-set-argument-3e214b69c87a

Upvotes: 16

sk14j
sk14j

Reputation: 816

You need to enclose the key with quotations and then escape the dots

helm install --values helm/jenkins.yml stable/jenkins --set Master.Ingress.Annotations."certmanager\.k8s\.io/cluster-issuer"=letsencrypt-staging

Upvotes: 80

Related Questions