From 4376f3f11087e53d064a4fe1a39b3b513aa997d8 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 28 Feb 2024 16:34:48 -0500 Subject: [PATCH] Add GaleraSpecCore struct This version of the struct (called "core") is meant to be used via the OpenStackControlplane. It is the same as GaleraSpec only it is missing the containerImages. The Default() function for webhooks has been updated accordingly. Jira: OSPRH-4835 --- api/v1beta1/galera_types.go | 11 ++++++++--- api/v1beta1/galera_webhook.go | 9 ++++++++- api/v1beta1/zz_generated.deepcopy.go | 22 +++++++++++++++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/api/v1beta1/galera_types.go b/api/v1beta1/galera_types.go index e81ab5e1..a3473bcf 100644 --- a/api/v1beta1/galera_types.go +++ b/api/v1beta1/galera_types.go @@ -39,6 +39,14 @@ type AdoptionRedirectSpec struct { // GaleraSpec defines the desired state of Galera type GaleraSpec struct { + GaleraSpecCore `json:",inline"` + // Name of the galera container image to run (will be set to environmental default if empty) + // +kubebuilder:validation:Required + ContainerImage string `json:"containerImage"` +} + +// GaleraSpec defines the desired state of Galera +type GaleraSpecCore struct { // Name of the secret to look for password keys // +kubebuilder:validation:Required Secret string `json:"secret"` @@ -48,9 +56,6 @@ type GaleraSpec struct { // Storage size allocated for the mariadb databases // +kubebuilder:validation:Required StorageRequest string `json:"storageRequest"` - // Name of the galera container image to run (will be set to environmental default if empty) - // +kubebuilder:validation:Required - ContainerImage string `json:"containerImage"` // +kubebuilder:validation:Minimum=1 // +kubebuilder:default=1 // +kubebuilder:validation:Enum=1;3 diff --git a/api/v1beta1/galera_webhook.go b/api/v1beta1/galera_webhook.go index 9d305694..1d722887 100644 --- a/api/v1beta1/galera_webhook.go +++ b/api/v1beta1/galera_webhook.go @@ -52,11 +52,18 @@ func (r *Galera) Default() { r.Spec.Default() } -// Default - set defaults for this MariaDB spec +// Default - set defaults for this GaleraSpec func (spec *GaleraSpec) Default() { + // only image validations go here if spec.ContainerImage == "" { spec.ContainerImage = galeraDefaults.ContainerImageURL } + spec.GaleraSpecCore.Default() +} + +// Default - set defaults for the GaleraSpecCore. This version is used by OpenStackControlplane +func (spec *GaleraSpecCore) Default() { + // nothing here yet } // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 39bcb171..07c33552 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -164,6 +164,22 @@ func (in *GaleraList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GaleraSpec) DeepCopyInto(out *GaleraSpec) { + *out = *in + in.GaleraSpecCore.DeepCopyInto(&out.GaleraSpecCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GaleraSpec. +func (in *GaleraSpec) DeepCopy() *GaleraSpec { + if in == nil { + return nil + } + out := new(GaleraSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GaleraSpecCore) DeepCopyInto(out *GaleraSpecCore) { *out = *in if in.Replicas != nil { in, out := &in.Replicas, &out.Replicas @@ -181,12 +197,12 @@ func (in *GaleraSpec) DeepCopyInto(out *GaleraSpec) { in.TLS.DeepCopyInto(&out.TLS) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GaleraSpec. -func (in *GaleraSpec) DeepCopy() *GaleraSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GaleraSpecCore. +func (in *GaleraSpecCore) DeepCopy() *GaleraSpecCore { if in == nil { return nil } - out := new(GaleraSpec) + out := new(GaleraSpecCore) in.DeepCopyInto(out) return out }