Aravindhan P
Aravindhan P

Reputation: 167

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

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/[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

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?

Upvotes: 4

Views: 7705

Answers (1)

Aravindhan P
Aravindhan P

Reputation: 167

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

Upvotes: 12

Related Questions