From ddc21ce6da9b59e7a567789c96db9e90eefa9e93 Mon Sep 17 00:00:00 2001 From: Bence Csati Date: Fri, 6 Dec 2024 10:06:58 +0100 Subject: [PATCH] feat: make control namespace field immutable Signed-off-by: Bence Csati --- .../logging-extensions.banzaicloud.io_eventtailers.yaml | 3 +++ .../templates/logging.banzaicloud.io_loggings.yaml | 3 +++ .../crds/logging-extensions.banzaicloud.io_eventtailers.yaml | 3 +++ .../crds/logging.banzaicloud.io_loggings.yaml | 3 +++ .../bases/logging-extensions.banzaicloud.io_eventtailers.yaml | 3 +++ config/crd/bases/logging.banzaicloud.io_loggings.yaml | 3 +++ pkg/sdk/extensions/api/v1alpha1/eventtailer_types.go | 3 ++- pkg/sdk/logging/api/v1beta1/logging_types.go | 4 ++++ 8 files changed, 24 insertions(+), 1 deletion(-) diff --git a/charts/logging-operator/charts/logging-operator-crds/templates/logging-extensions.banzaicloud.io_eventtailers.yaml b/charts/logging-operator/charts/logging-operator-crds/templates/logging-extensions.banzaicloud.io_eventtailers.yaml index c948cc5cf..903d50ee9 100644 --- a/charts/logging-operator/charts/logging-operator-crds/templates/logging-extensions.banzaicloud.io_eventtailers.yaml +++ b/charts/logging-operator/charts/logging-operator-crds/templates/logging-extensions.banzaicloud.io_eventtailers.yaml @@ -333,6 +333,9 @@ spec: type: object controlNamespace: type: string + x-kubernetes-validations: + - message: Value is immutable, please recreate the resource + rule: self == oldSelf image: properties: imagePullSecrets: diff --git a/charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_loggings.yaml b/charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_loggings.yaml index 55a61de20..450138a38 100644 --- a/charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_loggings.yaml +++ b/charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_loggings.yaml @@ -84,6 +84,9 @@ spec: type: object controlNamespace: type: string + x-kubernetes-validations: + - message: Value is immutable, please recreate the resource + rule: self == oldSelf defaultFlow: properties: filters: diff --git a/charts/logging-operator/crds/logging-extensions.banzaicloud.io_eventtailers.yaml b/charts/logging-operator/crds/logging-extensions.banzaicloud.io_eventtailers.yaml index 4cdc6c583..45726d717 100644 --- a/charts/logging-operator/crds/logging-extensions.banzaicloud.io_eventtailers.yaml +++ b/charts/logging-operator/crds/logging-extensions.banzaicloud.io_eventtailers.yaml @@ -330,6 +330,9 @@ spec: type: object controlNamespace: type: string + x-kubernetes-validations: + - message: Value is immutable, please recreate the resource + rule: self == oldSelf image: properties: imagePullSecrets: diff --git a/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml b/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml index 44fce8683..d710d8b2f 100644 --- a/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml +++ b/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml @@ -81,6 +81,9 @@ spec: type: object controlNamespace: type: string + x-kubernetes-validations: + - message: Value is immutable, please recreate the resource + rule: self == oldSelf defaultFlow: properties: filters: diff --git a/config/crd/bases/logging-extensions.banzaicloud.io_eventtailers.yaml b/config/crd/bases/logging-extensions.banzaicloud.io_eventtailers.yaml index 4cdc6c583..45726d717 100644 --- a/config/crd/bases/logging-extensions.banzaicloud.io_eventtailers.yaml +++ b/config/crd/bases/logging-extensions.banzaicloud.io_eventtailers.yaml @@ -330,6 +330,9 @@ spec: type: object controlNamespace: type: string + x-kubernetes-validations: + - message: Value is immutable, please recreate the resource + rule: self == oldSelf image: properties: imagePullSecrets: diff --git a/config/crd/bases/logging.banzaicloud.io_loggings.yaml b/config/crd/bases/logging.banzaicloud.io_loggings.yaml index 44fce8683..d710d8b2f 100644 --- a/config/crd/bases/logging.banzaicloud.io_loggings.yaml +++ b/config/crd/bases/logging.banzaicloud.io_loggings.yaml @@ -81,6 +81,9 @@ spec: type: object controlNamespace: type: string + x-kubernetes-validations: + - message: Value is immutable, please recreate the resource + rule: self == oldSelf defaultFlow: properties: filters: diff --git a/pkg/sdk/extensions/api/v1alpha1/eventtailer_types.go b/pkg/sdk/extensions/api/v1alpha1/eventtailer_types.go index 69e05ba67..1f49e82bf 100644 --- a/pkg/sdk/extensions/api/v1alpha1/eventtailer_types.go +++ b/pkg/sdk/extensions/api/v1alpha1/eventtailer_types.go @@ -35,7 +35,8 @@ type _metaEventTailer = interface{} //nolint:deadcode,unused // EventTailerSpec defines the desired state of EventTailer type EventTailerSpec struct { - //+kubebuilder:validation:Required + // +kubebuilder:validation:Required + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable, please recreate the resource" // The resources of EventTailer will be placed into this namespace ControlNamespace string `json:"controlNamespace"` diff --git a/pkg/sdk/logging/api/v1beta1/logging_types.go b/pkg/sdk/logging/api/v1beta1/logging_types.go index 08cba5803..4d7398ee8 100644 --- a/pkg/sdk/logging/api/v1beta1/logging_types.go +++ b/pkg/sdk/logging/api/v1beta1/logging_types.go @@ -72,6 +72,10 @@ type LoggingSpec struct { WatchNamespaceSelector *metav1.LabelSelector `json:"watchNamespaceSelector,omitempty"` // Cluster domain name to be used when templating URLs to services (default: "cluster.local."). ClusterDomain *string `json:"clusterDomain,omitempty"` + + // +kubebuilder:validation:Required + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable, please recreate the resource" + // Namespace for cluster wide configuration resources like ClusterFlow and ClusterOutput. // This should be a protected namespace from regular users. // Resources like fluentbit and fluentd will run in this namespace as well.