kubernetes: Valid Semver 2.0 not compatible with kubernetes labels

What happened?

Semver is allowed to have the following syntax: 1.2.3+45, where 45 is the build number. We are using this versioning approach, and when we tried to put that into the app.kubernetes.io/version label we got the following error:

a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')

I think this is a slight oversight and I think the regex there should be extended to:

(([A-Za-z0-9][-A-Za-z0-9_+.]*)?[A-Za-z0-9])?
                         ^ plus sign added here

From what I understand adding support for a + character doesn’t have any additional implications and should be safe.

What did you expect to happen?

I expected that a valid Semver is accepted as a label value.

How can we reproduce it (as minimally and precisely as possible)?

Add the following K8s label to any object:

metadata:
  labels:
    app.kubernetes.io/version: 1.2.3+45

Example:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: test
  labels:
    app.kubernetes.io/version: 1.2.3+45

Kubernetes version

Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.0", GitCommit:"b46a3f887ca979b1a5d14fd39cb1af43e7e5d12d", GitTreeState:"clean", BuildDate:"2022-12-09T16:23:44Z", GoVersion:"go1.19.4", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"24+", GitVersion:"v1.24.8-eks-ffeb93d", GitCommit:"abb98ec0631dfe573ec5eae40dc48fd8f2017424", GitTreeState:"clean", BuildDate:"2022-11-29T18:45:03Z", GoVersion:"go1.18.8", Compiler:"gc", Platform:"linux/amd64"}

Cloud provider

AWS EKS

OS version

Bottlerocket OS 1.11.1 (aws-k8s-1.24)

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 15 (9 by maintainers)

Most upvoted comments

What do people think about the annotation idea?

We could also perhaps define a new annotation (not label) such as app.kubernetes.io/semantic-version-1.0 and app.kubernetes.io/semantic-version-2.0, and encourage people to use these.