Skip to content

Nginx ingress chart PSP uses not portable way to provide kubernetes 1.21+ compatibility

Currently it's implemented as

https://gitlab.com/gitlab-org/charts/gitlab/-/blob/e569605278297fa411cc76f7c94734e55919a8b3/charts/nginx-ingress/templates/controller-poddisruptionbudget.yaml#L2

apiVersion: {{ ternary "policy/v1" "policy/v1beta1" (semverCompare ">=1.21.0-0" .Capabilities.KubeVersion.Version) }}

Unfortunately it's not the "right" way to implement it: not all environments provide .Capabilities.KubeVersion.Version, eg: when you use helm templating.

The "correct" implementation should look like

{{ if $.Capabilities.APIVersions.Has "policy/v1/PodDisruptionBudget" -}}
apiVersion: policy/v1
{{- else -}}
apiVersion: policy/v1beta1
{{- end }}

Grep with Capabilities.APIVersions.Has to see how it is implemented elsewhere in this repository.