Access the value of a property with dashes in property name for environment variable assignment

Viewed 21

I have a values.yaml where I'm storing a value in a property and a deployment.yaml where I'm trying to assign that value to an environment variable. The problem is the property name includes dashes and the following error message is thrown.

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'security.enable-mock-service' to boolean:

    Property: security.enable-mock-service
    Value:
    Origin: System Environment Property "SECURITY_ENABLEMOCKSERVICE"
    Reason: failed to convert java.lang.String to boolean (caused by java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type)

The 'null value' is because I'm trying to reference the name as {{ Values.security.enablemockservice | quote }} without the dashes using relaxed binding, but the actual property name is Values.security.enable-mock-service. If I attempt to reference the name in deployment.yaml as {{ Values.security.enable-mock-service | quote }}, I get the following error:

Error: UPGRADE FAILED: parse error at (project/templates/deployment.yaml:105): bad character U+002D '-'

Evidently relaxed binding can't be used in this way or I don't understand how to use it. Is there any other way to reference this property?

Here is the code in my two files:

values.yaml

  security:
     enable-mock-service: "false"

deployment.yaml

- name: SECURITY_ENABLEMOCKSERVICE
  value: {{ .Values.security.enablemockservice | quote }}
1 Answers

The Problem

We wish to write something like:

   value: {{ .Values.security.enable-mock-service | quote }}

But, Dash "-" is a reserved character in YAML so, we cannot directly use it.

The Fix

According to YAML spec, to escape dash "-", there are multiple options:

value: '{{ .Values.security.enable-mock-service | quote }}'
value: "{{ .Values.security.enable-mock-service | quote }}"
value: 
    {{ .Values.security.enable-mock-service | quote }}
value: >-
    {{ .Values.security.enable-mock-service | quote }}
value: |-
    {{ .Values.security.enable-mock-service | quote }} 
Related