Reputation: 10439
I have a map variable in golang as my config:
MyConfig map[int64][]int64 `mapstructure:"my-config"`
I tried to define this config in my helm files as follows:
Config Map:
my-config: {{ .Values.config.myconfig }}
Values:
myconfig:
1: [2]
2: [1]
But it rendered as:
my-config: map[1:[2] 2:[1]]
I also changed my config structure as follows:
Application:
MyConfig []MyConfigItem `mapstructure:"my-config"`
MyConfigItem struct {
FirstPart int64 `mapstructure:"first-part" validate:"required"`
SecondPart []int64 `mapstructure:"second-part" validate:"required"`
}
Config Map:
my-config: {{ .Values.config.myconfig }}
Values:
myConfig:
- first-part: 1
second-part:
- 2
- first-part: 2
second-part:
- 1
But it rendered as:
my-config: [map[first-part:1 second-part:[2]] map[first-part:2 second-part:[1]]]
Upvotes: 1
Views: 35
Reputation: 10439
I have found a solution for the second way. This is how I setup my config map file:
my-config:
{{- range .Values.config.myConfig }}
- {{ . | toYaml | indent 4 | trim }}
{{- end }}
{{- else }}
[]
{{- end }}
I found the solution here: https://stackoverflow.com/a/64830481/1626977
But applying this solution on the first mode did not result in a proper configuration. The rendered config was:
my-config:
- "1":
- 2
- "2":
- 2
The keys are string, but they should be integers.
I will search more to find out the proper solution for the first mode too; I will update the answer if I find any.
Upvotes: 0