Helm, kubeVersion, and GKE

I was recently asked about an error someone got with Helm and GKE. The error provides some insight into how semantic versions work and how to work around cases where someone isn’t following them.

The specific error was:

Error: INSTALLATION FAILED: chart requires kubeVersion: >= 1.19.0 which is incompatible with Kubernetes v1.23.8-gke.1900

This error is specific to the kubeVersion optional field someone can specify in a chart. It tells Helm to make sure a Kubernetes is a version that matches the pattern here. This has full range support as provided by the Masterminds semver package.

In this case the kubeVersion is set to >= 1.19.0. Doesn’t v1.23.8-gke.1900 fit within that range?

The answer is yes and no. The -gke.1900 marks the release as a pre-release rather than a stable release. The spec specifically says of pre-releases:

A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version.

This is a case where GKE has co-opted pre-releases to signify something about their version of the Kubernetes version. It’s not really a pre-release. GKE isn’t following semver. If you want to learn more about Kubernetes versioning you can read it here.

Now, I can relate to the problem GKE has here. How can then increment an internal version on top of the Kubernetes version? Build metadata isn’t something semver tools will let you filter on because the spec says not to use them for precedence. Semver versions don’t provide a nice way for them to sub-version Kubernetes here.

In any case, how can one work around this? The answer is pretty simple. Add a pre-release to the kubeVersion range. In this case, set it to >= 1.19.0-0. The -0 will cause the semver package to also evaluate pre-releases.

The 0 character is used because semver precedence is based on ASCII sort ordering. Of the allowable characters in a semver, 0 is the lowest one you can use. In this case it would include it and any pre-releases greater than that which is all other possible options.