Helm Go模板报错U+002F '/':如何设置带斜杠的默认值?
问题原因
直接在default中写coreregciqa/(.Values.serviceName)会触发语法错误,因为Helm模板解析器会把/当作非法的语法字符,无法识别这种直接拼接字符串和变量的写法。
解决方法
使用Helm的printf函数构造默认值,将固定前缀coreregciqa/与serviceName变量拼接成完整字符串,作为default的参数。修改后的模板代码如下:
--share-name {{ .Values.systemFilesPath | default (printf "coreregciqa/%s" .Values.serviceName) }}
修改后的完整Job YAML配置
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 (printf "coreregciqa/%s" .Values.serviceName) }} --account-key ***** restartPolicy: Never
内容的提问来源于stack exchange,提问作者John Pj
相关产品推荐
相关产品推荐

