Facing "error calling ge: incompatible types for comparison" in helm template

huangapple go评论128阅读模式
英文:

Facing "error calling ge: incompatible types for comparison" in helm template

问题

我正在尝试根据 HPA 的最小副本值设置 pdb 值,使用以下逻辑:

  1. spec:
  2. {{ if (ge .Values.autoscaling.minReplicas 5) }}
  3. minAvailable: 80
  4. {{ else if (eq .Values.autoscaling.minReplicas 4) }}
  5. minAvailable: 75
  6. {{ else if (eq .Values.autoscaling.minReplicas 3) }}
  7. minAvailable: 65
  8. {{ else if (eq .Values.autoscaling.minReplicas 2) }}
  9. minAvailable: 50
  10. {{ else }}
  11. minAvailable: 0

但是当我执行干运行时,我遇到了以下错误:

  1. 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
  2. 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
  3. INSTALLATION FAILED
  4. main.newInstallCmd.func2
  5. helm.sh/helm/v3/cmd/helm/install.go:127
  6. github.com/spf13/cobra.(*Command).execute
  7. github.com/spf13/cobra@v1.4.0/command.go:856
  8. github.com/spf13/cobra.(*Command).ExecuteC
  9. github.com/spf13/cobra@v1.4.0/command.go:974
  10. github.com/spf13/cobra.(*Command).Execute
  11. github.com/spf13/cobra@v1.4.0/command.go:902
  12. main.main
  13. helm.sh/helm/v3/cmd/helm/helm.go:83
  14. runtime.main
  15. runtime/proc.go:255
  16. runtime.goexit
  17. 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

  1. spec:
  2. {{ if (ge .Values.autoscaling.minReplicas 5) }}
  3. minAvailable: 80
  4. {{ else if (eq .Values.autoscaling.minReplicas 4) }}
  5. minAvailable: 75
  6. {{ else if (eq .Values.autoscaling.minReplicas 3) }}
  7. minAvailable: 65
  8. {{ else if (eq .Values.autoscaling.minReplicas 2) }}
  9. minAvailable: 50
  10. {{ else }}
  11. minAvailable: 0

But I'm facing this error when I perform dry run

  1. Error: INSTALLATION FAILED: template: service/templates/pdb.yaml:11:7: executing &quot;service/templates/pdb.yaml&quot; at &lt;ge .Values.autoscaling.minReplicas 5&gt;: error calling ge: incompatible types for comparison
  2. helm.go:84: [debug] template: service/templates/pdb.yaml:11:7: executing &quot;ffservice/templates/pdb.yaml&quot; at &lt;ge .Values.autoscaling.minReplicas 5&gt;: error calling ge: incompatible types for comparison
  3. INSTALLATION FAILED
  4. main.newInstallCmd.func2
  5. helm.sh/helm/v3/cmd/helm/install.go:127
  6. github.com/spf13/cobra.(*Command).execute
  7. github.com/spf13/cobra@v1.4.0/command.go:856
  8. github.com/spf13/cobra.(*Command).ExecuteC
  9. github.com/spf13/cobra@v1.4.0/command.go:974
  10. github.com/spf13/cobra.(*Command).Execute
  11. github.com/spf13/cobra@v1.4.0/command.go:902
  12. main.main
  13. helm.sh/helm/v3/cmd/helm/helm.go:83
  14. runtime.main
  15. runtime/proc.go:255
  16. runtime.goexit
  17. 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

抱歉,我找到了答案

我应该像这样进行比较

  1. spec:
  2. {{ if (ge (int .Values.autoscaling.minReplicas) 5) }}
  3. minAvailable: 80%
  4. {{ else if (eq (int .Values.autoscaling.minReplicas) 4) }}
  5. minAvailable: 75%
  6. {{ else if (eq (int .Values.autoscaling.minReplicas) 3) }}
  7. minAvailable: 65%
  8. {{ else if (eq (int .Values.autoscaling.minReplicas) 2) }}
  9. minAvailable: 50%
  10. {{ else }}
  11. minAvailable: 0%

希望对任何人有所帮助,如果他们犯了同样的愚蠢错误。

英文:

Sorry, I found the answer

I should have compared like this

  1. spec:
  2. {{ if (ge (int .Values.autoscaling.minReplicas) 5) }}
  3. minAvailable: 80%
  4. {{ else if (eq (int .Values.autoscaling.minReplicas) 4) }}
  5. minAvailable: 75%
  6. {{ else if (eq (int .Values.autoscaling.minReplicas) 3) }}
  7. minAvailable: 65%
  8. {{ else if (eq (int .Values.autoscaling.minReplicas) 2) }}
  9. minAvailable: 50%
  10. {{ else }}
  11. minAvailable: 0%

Hope it helps anyone, if they do this same silly mistake

huangapple
  • 本文由 发表于 2022年10月4日 14:58:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/73944131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定