我们有几个取决于 AWS 区域的值。所以我把这个放在我的
values.yaml
文件中
regional_values:
us-east-1:
repository: 01234567890.dkr.ecr.us-east-1.amazonaws.com
serviceSecurityGroup1:
- sg-01234567
- sg-12345678
- sg-23456789
...
us-west-1:
repository: 98765432109.dkr.ecr.us-east-1.amazonaws.com
serviceSecurityGroup1:
- sg-34567890
- sg-45678901
- sg-56789012
...
当我做
helm install
时,我会通过 aws_region
$ helm install myApp myChart/ --set aws_region
返回
.Values.regional_values.us-east-1.repository
的辅助函数是什么,这样我就得到 01234567890.dkr.ecr.us-east-1.amazonaws.com
?
{{/*
Get the repository from the AWS region
*/}}
{{- define "microservice-base-chart.reponame" -}}
{{/* I know this syntax is wrong */}}
{{- get .Values.regional_values .Values.aws_region.repository }}
{{- end }}
这确实有效,但是有什么更好的方法呢?有没有办法将
$idx :=
和 printf
线简化为一条线?
{{/*
Get the repository from the AWS region
*/}}
{{- define "microservice-base-chart.reponame" -}}
{{- $idx := index .Values.regional_values .Values.aws_region }}
{{- printf "%s" $idx.repository }}
{{- end }}