Configure map data in Helm chart values.yaml file

1.3k Views Asked by At

I'm trying to deploy my Spring Boot application in Minikube using Helm charts. I have a configuration class where I map all the @value variables. If keep my map value in application.yaml or applicationConfig.yaml file then

@Value("#{${user.apiKey}}")
private Map<String, String> userApiKeyMap;

works fine.

But if I want to pass this map from values.yaml then it's not working. Below are the things I tried and errors I got. Try 1:

user:
    apiKey: 
      key1: "value1"
      key2: "value2"


org.springframework.expression.spel.SpelParseException: Expression [map[key1:value1 key2:value2]] @6: EL1043E: Unexpected token. Expected 'rsquare(])' but was 'colon(:)'

Try 2:

user:
    apiKey: |-
      key1: "value1"
      key2: "value2"

Error: UPGRADE FAILED: YAML parse error on user-service/templates/applicationConfig.yaml: error converting YAML to JSON: yaml: line 29: did not find expected key

Try 3:

user:
    apiKey: { key1: "value1",
            key2: "value2" }

org.springframework.expression.spel.SpelParseException: Expression [map[key1:value1 key2:value2]] @6: EL1043E: Unexpected token. Expected 'rsquare(])' but was 'colon(:)'

Try 4:

user:
    apiKey: '{ "key1": "value1",
                "key2": "value2" }'

nested exception is java.lang.IllegalArgumentException: Could not resolve placeholkey2r 'user.apiKey' in value "#{${user.apiKey}}"

Try 5:

user:
    apiKey:
      - "key1": "value1"
      - "key2": "value2"



ERROR 2022-11-09 09:51:01,614 [main] [SpringApplication] Application run failed
 org.yaml.snakeyaml.parser.ParserException: while parsing a flow sequence
 in 'reader', line 22, column 13:
        apiKey: [map[key1:value1 ... 
                ^
expected ',' or ']', but got [
 in 'reader', line 22, column 17:
        apiKey: [map[key1:value1 ... 
                    ^
1

There are 1 best solutions below

0
On

I was able to fix it by adding | quote in applicationConfig.yaml file.

Ex:

user:
    apiKey: {{ .Values.user.apiKey | quote }}