From 87471bb214d06b8e8b7fb4eead03d0cb64d2ac42 Mon Sep 17 00:00:00 2001 From: Johnny Fredheim Horvi Date: Mon, 16 Dec 2024 10:50:17 +0100 Subject: [PATCH] Add validation of name length for naisjobs Co-authored-by: Trong Huu Nguyen Co-authored-by: Christer Edvartsen --- charts/templates/nais.io_naisjobs.yaml | 3 +++ config/crd/bases/nais.io_naisjobs.yaml | 3 +++ pkg/apis/nais.io/v1/naisjob_types.go | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/charts/templates/nais.io_naisjobs.yaml b/charts/templates/nais.io_naisjobs.yaml index 6ad83b27..9855a66f 100644 --- a/charts/templates/nais.io_naisjobs.yaml +++ b/charts/templates/nais.io_naisjobs.yaml @@ -1362,6 +1362,9 @@ spec: required: - spec type: object + x-kubernetes-validations: + - message: metadata.name must be no more than 63 characters + rule: self.metadata.name.size() <= 63 served: true storage: true subresources: {} diff --git a/config/crd/bases/nais.io_naisjobs.yaml b/config/crd/bases/nais.io_naisjobs.yaml index 6ad83b27..9855a66f 100644 --- a/config/crd/bases/nais.io_naisjobs.yaml +++ b/config/crd/bases/nais.io_naisjobs.yaml @@ -1362,6 +1362,9 @@ spec: required: - spec type: object + x-kubernetes-validations: + - message: metadata.name must be no more than 63 characters + rule: self.metadata.name.size() <= 63 served: true storage: true subresources: {} diff --git a/pkg/apis/nais.io/v1/naisjob_types.go b/pkg/apis/nais.io/v1/naisjob_types.go index 639656f2..5b357c70 100644 --- a/pkg/apis/nais.io/v1/naisjob_types.go +++ b/pkg/apis/nais.io/v1/naisjob_types.go @@ -29,6 +29,7 @@ func init() { // +kubebuilder:printcolumn:name="Team",type="string",JSONPath=".metadata.labels.team" // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.synchronizationState" // +kubebuilder:resource:path="naisjobs",shortName="nj",singular="naisjob" +// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63", message="metadata.name must be no more than 63 characters" type Naisjob struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -314,4 +315,4 @@ func (in *Naisjob) SkipDeploymentMessage() bool { func (in *Naisjob) ClientID(cluster string) string { return fmt.Sprintf("%s:%s:%s", cluster, in.ObjectMeta.Namespace, in.ObjectMeta.Name) -} +} \ No newline at end of file