From 3fc6449d615f180e6553148ed62245b15604727a Mon Sep 17 00:00:00 2001 From: Rashmi Gottipati Date: Fri, 10 May 2024 12:08:31 -0400 Subject: [PATCH 1/2] Add optional field to ClusterExtension API to skip CRD upgrade safety checks Signed-off-by: Rashmi Gottipati --- api/v1alpha1/clusterextension_types.go | 33 +++++++++++++++++++ api/v1alpha1/zz_generated.deepcopy.go | 32 ++++++++++++++++++ ...peratorframework.io_clusterextensions.yaml | 20 +++++++++++ 3 files changed, 85 insertions(+) diff --git a/api/v1alpha1/clusterextension_types.go b/api/v1alpha1/clusterextension_types.go index 11d7e7b13..8d7e24c4b 100644 --- a/api/v1alpha1/clusterextension_types.go +++ b/api/v1alpha1/clusterextension_types.go @@ -73,8 +73,41 @@ type ClusterExtensionSpec struct { // the bundle may contain resources that are cluster-scoped or that are // installed in a different namespace. This namespace is expected to exist. InstallNamespace string `json:"installNamespace"` + + //+kubebuilder:Optional + // Preflight defines the strategy for the preflight checks (i.e. as of now, the CRD upgrade safety checks) to be applied or skipped when attempting to install the cluster extension. + Preflight PreflightConfig `json:"preflight,omitempty"` +} + +// PreflightConfig holds the config for the preflight checks. Currently, this is implemented for the +// CRDUpgradeSafety preflight check and can be extended in the future to add other preflight checks. +type PreflightConfig struct { + CRDUpgradeSafety CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety,omitempty"` +} + +// CRDUpgradeSafetyPreflightConfig is a custom struct that holds the necessary configuration values to +// enable or disable the CRD Upgrade Safety validations. Currently, this holds Mode +// that sets the CRD Upgrade Safety validations to either Enabled/Disabled. +// By default, this is set to "Enabled". +type CRDUpgradeSafetyPreflightConfig struct { + //+kubebuilder:validation:Enum:=Enabled;Disabled + //+kubebuilder:default:=Enabled + //+kubebuilder:Optional + CRDUpgradeSafetyMode CRDUpgradeSafetyMode `json:"crdUpgradeSafetyMode,omitempty"` } +type CRDUpgradeSafetyMode string + +const ( + // CRDUpgradeSafetyModeEnabled represents the default state for the + // CRD Upgrade Safety validations by setting it to "Enabled". + CRDUpgradeSafetyModeEnabled CRDUpgradeSafetyMode = "Enabled" + + // CRDUpgradeSafetyModeDisabled represents the option for the + // CRD Upgrade Safety validations to be disabled by setting it to "Disabled". + CRDUpgradeSafetyModeDisabled CRDUpgradeSafetyMode = "Disabled" +) + const ( // TODO(user): add more Types, here and into init() TypeInstalled = "Installed" diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 1d981d93c..c56520a85 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -40,6 +40,21 @@ func (in *BundleMetadata) DeepCopy() *BundleMetadata { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CRDUpgradeSafetyPreflightConfig) DeepCopyInto(out *CRDUpgradeSafetyPreflightConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CRDUpgradeSafetyPreflightConfig. +func (in *CRDUpgradeSafetyPreflightConfig) DeepCopy() *CRDUpgradeSafetyPreflightConfig { + if in == nil { + return nil + } + out := new(CRDUpgradeSafetyPreflightConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterExtension) DeepCopyInto(out *ClusterExtension) { *out = *in @@ -102,6 +117,7 @@ func (in *ClusterExtensionList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterExtensionSpec) DeepCopyInto(out *ClusterExtensionSpec) { *out = *in + out.Preflight = in.Preflight } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterExtensionSpec. @@ -145,3 +161,19 @@ func (in *ClusterExtensionStatus) DeepCopy() *ClusterExtensionStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PreflightConfig) DeepCopyInto(out *PreflightConfig) { + *out = *in + out.CRDUpgradeSafety = in.CRDUpgradeSafety +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PreflightConfig. +func (in *PreflightConfig) DeepCopy() *PreflightConfig { + if in == nil { + return nil + } + out := new(PreflightConfig) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml b/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml index 2b0ebb960..22dc7831b 100644 --- a/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml +++ b/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml @@ -56,6 +56,26 @@ spec: maxLength: 48 pattern: ^[a-z0-9]+(-[a-z0-9]+)*$ type: string + preflight: + description: Preflight defines the strategy for the preflight checks + (i.e. as of now, the CRD upgrade safety checks) to be applied or + skipped when attempting to install the cluster extension. + properties: + crdUpgradeSafety: + description: |- + CRDUpgradeSafetyPreflightConfig is a custom struct that holds the necessary configuration values to + enable or disable the CRD Upgrade Safety validations. Currently, this holds Mode + that sets the CRD Upgrade Safety validations to either Enabled/Disabled. + By default, this is set to "Enabled". + properties: + crdUpgradeSafetyMode: + default: Enabled + enum: + - Enabled + - Disabled + type: string + type: object + type: object upgradeConstraintPolicy: default: Enforce description: Defines the policy for how to handle upgrade constraints From fffc98a0a57f9d860aab3a2347a36bd8edfe28bd Mon Sep 17 00:00:00 2001 From: Rashmi Gottipati Date: Tue, 14 May 2024 14:12:43 -0400 Subject: [PATCH 2/2] Address latest review comment Signed-off-by: Rashmi Gottipati --- api/v1alpha1/clusterextension_types.go | 2 +- .../crd/bases/olm.operatorframework.io_clusterextensions.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/v1alpha1/clusterextension_types.go b/api/v1alpha1/clusterextension_types.go index 8d7e24c4b..21d4dd9e7 100644 --- a/api/v1alpha1/clusterextension_types.go +++ b/api/v1alpha1/clusterextension_types.go @@ -93,7 +93,7 @@ type CRDUpgradeSafetyPreflightConfig struct { //+kubebuilder:validation:Enum:=Enabled;Disabled //+kubebuilder:default:=Enabled //+kubebuilder:Optional - CRDUpgradeSafetyMode CRDUpgradeSafetyMode `json:"crdUpgradeSafetyMode,omitempty"` + CRDUpgradeSafetyMode CRDUpgradeSafetyMode `json:"mode,omitempty"` } type CRDUpgradeSafetyMode string diff --git a/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml b/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml index 22dc7831b..c132d81cf 100644 --- a/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml +++ b/config/crd/bases/olm.operatorframework.io_clusterextensions.yaml @@ -68,7 +68,7 @@ spec: that sets the CRD Upgrade Safety validations to either Enabled/Disabled. By default, this is set to "Enabled". properties: - crdUpgradeSafetyMode: + mode: default: Enabled enum: - Enabled