登录
首页 >  Golang >  Go问答

遇到helm模板中的“调用ge时出错:不兼容比较类型”问题

来源:stackoverflow

时间:2024-02-16 21:09:22 450浏览 收藏

从现在开始,我们要努力学习啦!今天我给大家带来《遇到helm模板中的“调用ge时出错:不兼容比较类型”问题》,感兴趣的朋友请继续看下去吧!下文中的内容我们主要会涉及到等等知识点,如果在阅读本文过程中有遇到不清楚的地方,欢迎留言呀!我们一起讨论,一起学习!

问题内容

我正在尝试使用以下逻辑根据 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 : error calling ge: incompatible types for comparison
helm.go:84: [debug] template: service/templates/pdb.yaml:11:7: executing "ffservice/templates/pdb.yaml" at : 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/[email protected]/command.go:856
github.com/spf13/cobra.(*Command).ExecuteC
    github.com/spf13/[email protected]/command.go:974
github.com/spf13/cobra.(*Command).Execute
    github.com/spf13/[email protected]/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 并进行比较?


正确答案


抱歉,我找到了答案

我应该这样比较

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%

希望它能帮助任何人,如果他们犯了同样的愚蠢错误

今天关于《遇到helm模板中的“调用ge时出错:不兼容比较类型”问题》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>