Search code examples
kubernetes-helmgo-templates

Helm - go templates : bad character U+002F '/'


I have this job yaml which work well:

apiVersion: batch/v1
kind: Job
metadata:
  name: cli-commands
spec:
  template:
    spec:
      containers:
      - name: cli-commands
        image: ubuntu:22.04  
        command: [ 'bash', '-c']
        args: 
        -  DEBIAN_FRONTEND=noninteractive apt update && apt install -y curl && curl -sL https://aka.ms/InstallAzureCLIDeb | bash &&
           echo installation successful &&
           az storage directory create --account-name {{ .Values.env.secret.azurestorageaccountname | b64dec}} --name {{ .Release.Namespace }}
               --share-name {{ .Values.systemFilesPath | default (.Values.serviceName) }}
               --account-key *****
      restartPolicy: Never

The issue is:

I need to change this part of code (first version):

--share-name {{ .Values.systemFilesPath | default (.Values.serviceName) }}

into this (second version):

--share-name {{ .Values.systemFilesPath | default coreregciqa/(.Values.serviceName) }}

but the second version doesn't work and throws this error:

bad character U+002F '/'

How can I resolve that? All what I want to do is to create a default value which looks like that (for example): coreregciqa/mono ,but I dont know how to deal with the '/' in this case. My first version works well because I don't have the '/' there, but my second version doesn't work.

I need your advice please. Thanks a lot.


Solution

  • Default needs a value after it, and it can't automatically complete the splicing, you need to explicitly call the function to connect the string.

    Like this:

    --share-name {{ .Values.systemFilesPath | default (printf "coreregciqa/%s" .Values.serviceName) }}