I have a project deployed using helm2, but with the upgrade of the k8s version, the apiVersion
of rbac
has changed. However, not all k8s clusters are upgraded together, so they need to be compatible with different versions.
I searched for information and found that I can use Helm's semverCompare
function.
I modified the apiVersion of the Role
resource through the reference.
{{- if semverCompare ">=1.22-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: rbac.authorization.k8s.io/v1
{{- else }}
apiVersion: rbac.authorization.k8s.io/v1beta1
{{- end }}
kind: Role
...
...
But semverCompare seems to be a function of Helm3 semvercompare. I didn't find any description of this function in helm2.
I would like to ask if there is a function similar to semvercompare
in helm2, or to implement the function of semvercompare in other ways. Looking forward to your reply.
The listing of template functions in the Helm documentation is somewhat recent. Older versions of the documentation contain text like this:
And, indeed, the semantic version functions are part of Sprig.
The next question is, does this very old version of Helm contain these functions? The Helm 2.17 source references Sprig 2.20.0. That version of Sprig does seem to contain the semver functions. So you're probably good to use these, even on a 4-year-old unmaintained version of the Helm tool.
Helm (including this old version) also has a
.Capabilities
object which lets you check what API versions the cluster supports. Rather than gating on the Kubernetes version, it may be easier to just ask if the newer API version exists