英文:
Facing "error calling ge: incompatible types for comparison" in helm template
问题
我正在尝试根据 HPA 的最小副本值设置 pdb 值,使用以下逻辑:
spec:
{{ if (ge .Values.autoscaling.minReplicas 5) }}
minAvailable: 80
{{ else if (eq .Values.autoscaling.minReplicas 4) }}
minAvailable: 75
{{ else if (eq .Values.autoscaling.minReplicas 3) }}
minAvailable: 65
{{ else if (eq .Values.autoscaling.minReplicas 2) }}
minAvailable: 50
{{ else }}
minAvailable: 0
但是当我执行干运行时,我遇到了以下错误:
Error: INSTALLATION FAILED: template: service/templates/pdb.yaml:11:7: executing "service/templates/pdb.yaml" at <ge .Values.autoscaling.minReplicas 5>: error calling ge: incompatible types for comparison
helm.go:84: [debug] template: service/templates/pdb.yaml:11:7: executing "ffservice/templates/pdb.yaml" at <ge .Values.autoscaling.minReplicas 5>: error calling ge: incompatible types for comparison
INSTALLATION FAILED
main.newInstallCmd.func2
helm.sh/helm/v3/cmd/helm/install.go:127
github.com/spf13/cobra.(*Command).execute
github.com/spf13/cobra@v1.4.0/command.go:856
github.com/spf13/cobra.(*Command).ExecuteC
github.com/spf13/cobra@v1.4.0/command.go:974
github.com/spf13/cobra.(*Command).Execute
github.com/spf13/cobra@v1.4.0/command.go:902
main.main
helm.sh/helm/v3/cmd/helm/helm.go:83
runtime.main
runtime/proc.go:255
runtime.goexit
runtime/asm_amd64.s:158
我尝试使用 int 将 .Values.autoscaling.minReplicas 包装起来,像这样:{{ if (ge int(.Values.autoscaling.minReplicas) 5) }},但仍然遇到相同的错误。
有人可以帮我解决这个错误吗?我该如何将值定义为 int 并进行比较?
英文:
I'm trying to set pdb value based on hpa min replica value using below logic
spec:
{{ if (ge .Values.autoscaling.minReplicas 5) }}
minAvailable: 80
{{ else if (eq .Values.autoscaling.minReplicas 4) }}
minAvailable: 75
{{ else if (eq .Values.autoscaling.minReplicas 3) }}
minAvailable: 65
{{ else if (eq .Values.autoscaling.minReplicas 2) }}
minAvailable: 50
{{ else }}
minAvailable: 0
But I'm facing this error when I perform dry run
Error: INSTALLATION FAILED: template: service/templates/pdb.yaml:11:7: executing "service/templates/pdb.yaml" at <ge .Values.autoscaling.minReplicas 5>: error calling ge: incompatible types for comparison
helm.go:84: [debug] template: service/templates/pdb.yaml:11:7: executing "ffservice/templates/pdb.yaml" at <ge .Values.autoscaling.minReplicas 5>: error calling ge: incompatible types for comparison
INSTALLATION FAILED
main.newInstallCmd.func2
helm.sh/helm/v3/cmd/helm/install.go:127
github.com/spf13/cobra.(*Command).execute
github.com/spf13/cobra@v1.4.0/command.go:856
github.com/spf13/cobra.(*Command).ExecuteC
github.com/spf13/cobra@v1.4.0/command.go:974
github.com/spf13/cobra.(*Command).Execute
github.com/spf13/cobra@v1.4.0/command.go:902
main.main
helm.sh/helm/v3/cmd/helm/helm.go:83
runtime.main
runtime/proc.go:255
runtime.goexit
runtime/asm_amd64.s:158
I tried enclosing .Values.autoscaling.minReplicas with int like this,
{{ if (ge int(.Values.autoscaling.minReplicas) 5) }} but still facing same error
Can someone please help me with this error, how do I define the value as int and perform comparison?
答案1
得分: 6
抱歉,我找到了答案
我应该像这样进行比较
spec:
{{ if (ge (int .Values.autoscaling.minReplicas) 5) }}
minAvailable: 80%
{{ else if (eq (int .Values.autoscaling.minReplicas) 4) }}
minAvailable: 75%
{{ else if (eq (int .Values.autoscaling.minReplicas) 3) }}
minAvailable: 65%
{{ else if (eq (int .Values.autoscaling.minReplicas) 2) }}
minAvailable: 50%
{{ else }}
minAvailable: 0%
希望对任何人有所帮助,如果他们犯了同样的愚蠢错误。
英文:
Sorry, I found the answer
I should have compared like this
spec:
{{ if (ge (int .Values.autoscaling.minReplicas) 5) }}
minAvailable: 80%
{{ else if (eq (int .Values.autoscaling.minReplicas) 4) }}
minAvailable: 75%
{{ else if (eq (int .Values.autoscaling.minReplicas) 3) }}
minAvailable: 65%
{{ else if (eq (int .Values.autoscaling.minReplicas) 2) }}
minAvailable: 50%
{{ else }}
minAvailable: 0%
Hope it helps anyone, if they do this same silly mistake
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论