diff --git a/api/v1beta1/cinder_types.go b/api/v1beta1/cinder_types.go index 2c2375b1..70709b93 100644 --- a/api/v1beta1/cinder_types.go +++ b/api/v1beta1/cinder_types.go @@ -52,8 +52,7 @@ const ( DBPurgeDefaultSchedule = "1 0 * * *" ) -// CinderSpec defines the desired state of Cinder -type CinderSpec struct { +type CinderSpecBase struct { CinderTemplate `json:",inline"` // +kubebuilder:validation:Required @@ -89,35 +88,60 @@ type CinderSpec struct { // to /etc//.conf.d directory as a custom config file. CustomServiceConfig string `json:"customServiceConfig,omitempty"` - // +kubebuilder:validation:Required + // +kubebuilder:validation:Optional + // ExtraMounts containing conf files and credentials + ExtraMounts []CinderExtraVolMounts `json:"extraMounts,omitempty"` + + // +kubebuilder:validation:Optional + // NodeSelector to target subset of worker nodes running this service. Setting + // NodeSelector here acts as a default value and can be overridden by service + // specific NodeSelector Settings. + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + + // +kubebuilder:validation:Optional + // DBPurge parameters - + DBPurge DBPurge `json:"dbPurge,omitempty"` +} + +// CinderSpecCore the same as CinderSpec without ContainerImage references +type CinderSpecCore struct { + CinderSpecBase `json:",inline"` + // CinderAPI - Spec definition for the API service of this Cinder deployment - CinderAPI CinderAPITemplate `json:"cinderAPI"` + CinderAPI CinderAPITemplateCore `json:"cinderAPI"` // +kubebuilder:validation:Required // CinderScheduler - Spec definition for the Scheduler service of this Cinder deployment - CinderScheduler CinderSchedulerTemplate `json:"cinderScheduler"` + CinderScheduler CinderSchedulerTemplateCore `json:"cinderScheduler"` // +kubebuilder:validation:Optional // CinderBackup - Spec definition for the Backup service of this Cinder deployment - CinderBackup CinderBackupTemplate `json:"cinderBackup"` + CinderBackup CinderBackupTemplateCore `json:"cinderBackup"` // +kubebuilder:validation:Optional // CinderVolumes - Map of chosen names to spec definitions for the Volume(s) service(s) of this Cinder deployment - CinderVolumes map[string]CinderVolumeTemplate `json:"cinderVolumes,omitempty"` + CinderVolumes map[string]CinderVolumeTemplateCore `json:"cinderVolumes,omitempty"` +} - // +kubebuilder:validation:Optional - // ExtraMounts containing conf files and credentials - ExtraMounts []CinderExtraVolMounts `json:"extraMounts,omitempty"` +// CinderSpec defines the desired state of Cinder +type CinderSpec struct { + CinderSpecBase `json:",inline"` + + // +kubebuilder:validation:Required + // CinderAPI - Spec definition for the API service of this Cinder deployment + CinderAPI CinderAPITemplate `json:"cinderAPI"` + + // +kubebuilder:validation:Required + // CinderScheduler - Spec definition for the Scheduler service of this Cinder deployment + CinderScheduler CinderSchedulerTemplate `json:"cinderScheduler"` // +kubebuilder:validation:Optional - // NodeSelector to target subset of worker nodes running this service. Setting - // NodeSelector here acts as a default value and can be overridden by service - // specific NodeSelector Settings. - NodeSelector map[string]string `json:"nodeSelector,omitempty"` + // CinderBackup - Spec definition for the Backup service of this Cinder deployment + CinderBackup CinderBackupTemplate `json:"cinderBackup"` // +kubebuilder:validation:Optional - // DBPurge parameters - - DBPurge DBPurge `json:"dbPurge,omitempty"` + // CinderVolumes - Map of chosen names to spec definitions for the Volume(s) service(s) of this Cinder deployment + CinderVolumes map[string]CinderVolumeTemplate `json:"cinderVolumes,omitempty"` } // CinderStatus defines the observed state of Cinder diff --git a/api/v1beta1/cinder_webhook.go b/api/v1beta1/cinder_webhook.go index d30c80a2..e603e72e 100644 --- a/api/v1beta1/cinder_webhook.go +++ b/api/v1beta1/cinder_webhook.go @@ -74,30 +74,30 @@ var _ webhook.Defaulter = &Cinder{} func (r *Cinder) Default() { cinderlog.Info("default", "name", r.Name) - r.Spec.Default() -} - -// Default - set defaults for this Cinder spec -func (spec *CinderSpec) Default() { - if spec.CinderAPI.ContainerImage == "" { - spec.CinderAPI.ContainerImage = cinderDefaults.APIContainerImageURL + if r.Spec.CinderAPI.ContainerImage == "" { + r.Spec.CinderAPI.ContainerImage = cinderDefaults.APIContainerImageURL } - if spec.CinderBackup.ContainerImage == "" { - spec.CinderBackup.ContainerImage = cinderDefaults.BackupContainerImageURL + if r.Spec.CinderBackup.ContainerImage == "" { + r.Spec.CinderBackup.ContainerImage = cinderDefaults.BackupContainerImageURL } - if spec.CinderScheduler.ContainerImage == "" { - spec.CinderScheduler.ContainerImage = cinderDefaults.SchedulerContainerImageURL + if r.Spec.CinderScheduler.ContainerImage == "" { + r.Spec.CinderScheduler.ContainerImage = cinderDefaults.SchedulerContainerImageURL } - for index, cinderVolume := range spec.CinderVolumes { + for index, cinderVolume := range r.Spec.CinderVolumes { if cinderVolume.ContainerImage == "" { cinderVolume.ContainerImage = cinderDefaults.VolumeContainerImageURL } // This is required, as the loop variable is a by-value copy - spec.CinderVolumes[index] = cinderVolume + r.Spec.CinderVolumes[index] = cinderVolume } + r.Spec.CinderSpecBase.Default() +} + +// Default - set defaults for this Cinder spec +func (spec *CinderSpecBase) Default() { if spec.DBPurge.Age == 0 { spec.DBPurge.Age = cinderDefaults.DBPurgeAge @@ -107,6 +107,11 @@ func (spec *CinderSpec) Default() { } } +// Default - set defaults for this Cinder spec +func (spec *CinderSpecCore) Default() { + spec.CinderSpecBase.Default() +} + // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. //+kubebuilder:webhook:path=/validate-cinder-openstack-org-v1beta1-cinder,mutating=false,failurePolicy=fail,sideEffects=None,groups=cinder.openstack.org,resources=cinders,verbs=create;update,versions=v1beta1,name=vcinder.kb.io,admissionReviewVersions=v1 diff --git a/api/v1beta1/cinderapi_types.go b/api/v1beta1/cinderapi_types.go index bc145e73..b57316b1 100644 --- a/api/v1beta1/cinderapi_types.go +++ b/api/v1beta1/cinderapi_types.go @@ -24,7 +24,7 @@ import ( ) // CinderAPITemplate defines the input parameters for the Cinder API service -type CinderAPITemplate struct { +type CinderAPITemplateCore struct { // Common input parameters for the Cinder API service CinderServiceTemplate `json:",inline"` @@ -44,6 +44,15 @@ type CinderAPITemplate struct { TLS tls.API `json:"tls,omitempty"` } +// CinderAPITemplate defines the input parameters for the Cinder API service +type CinderAPITemplate struct { + // +kubebuilder:validation:Required + // ContainerImage - Cinder Container Image URL (will be set to environmental default if empty) + ContainerImage string `json:"containerImage"` + + CinderAPITemplateCore `json:",inline"` +} + // APIOverrideSpec to override the generated manifest of several child resources. type APIOverrideSpec struct { // Override configuration for the Service created to serve traffic to the cluster. diff --git a/api/v1beta1/cinderbackup_types.go b/api/v1beta1/cinderbackup_types.go index 00e9fd87..ec223b95 100644 --- a/api/v1beta1/cinderbackup_types.go +++ b/api/v1beta1/cinderbackup_types.go @@ -23,7 +23,7 @@ import ( ) // CinderBackupTemplate defines the input parameters for the Cinder Backup service -type CinderBackupTemplate struct { +type CinderBackupTemplateCore struct { // Common input parameters for the Cinder Backup service CinderServiceTemplate `json:",inline"` @@ -34,6 +34,15 @@ type CinderBackupTemplate struct { Replicas *int32 `json:"replicas"` } +// CinderBackupTemplate defines the input parameters for the Cinder Backup service +type CinderBackupTemplate struct { + // +kubebuilder:validation:Required + // ContainerImage - Cinder Container Image URL (will be set to environmental default if empty) + ContainerImage string `json:"containerImage"` + + CinderBackupTemplateCore `json:",inline"` +} + // CinderBackupSpec defines the desired state of CinderBackup type CinderBackupSpec struct { // Common input parameters for all Cinder services diff --git a/api/v1beta1/cinderscheduler_types.go b/api/v1beta1/cinderscheduler_types.go index 063471c9..32f09fcf 100644 --- a/api/v1beta1/cinderscheduler_types.go +++ b/api/v1beta1/cinderscheduler_types.go @@ -23,7 +23,7 @@ import ( ) // CinderSchedulerTemplate defines the input parameters for the Cinder Scheduler service -type CinderSchedulerTemplate struct { +type CinderSchedulerTemplateCore struct { // Common input parameters for the Cinder Scheduler service CinderServiceTemplate `json:",inline"` @@ -34,6 +34,15 @@ type CinderSchedulerTemplate struct { Replicas *int32 `json:"replicas"` } +// CinderSchedulerTemplate defines the input parameters for the Cinder Scheduler service +type CinderSchedulerTemplate struct { + // +kubebuilder:validation:Required + // ContainerImage - Cinder Container Image URL (will be set to environmental default if empty) + ContainerImage string `json:"containerImage"` + + CinderSchedulerTemplateCore `json:",inline"` +} + // CinderSchedulerSpec defines the desired state of CinderScheduler type CinderSchedulerSpec struct { // Common input parameters for all Cinder services diff --git a/api/v1beta1/cindervolume_types.go b/api/v1beta1/cindervolume_types.go index 00fe376e..e7694122 100644 --- a/api/v1beta1/cindervolume_types.go +++ b/api/v1beta1/cindervolume_types.go @@ -23,7 +23,7 @@ import ( ) // CinderVolumeTemplate defines the input parameters for the Cinder Volume service -type CinderVolumeTemplate struct { +type CinderVolumeTemplateCore struct { // Common input parameters for the Cinder Volume service CinderServiceTemplate `json:",inline"` @@ -35,6 +35,15 @@ type CinderVolumeTemplate struct { Replicas *int32 `json:"replicas"` } +// CinderVolumeTemplate defines the input parameters for the Cinder Volume service +type CinderVolumeTemplate struct { + // +kubebuilder:validation:Required + // ContainerImage - Cinder Container Image URL (will be set to environmental default if empty) + ContainerImage string `json:"containerImage"` + + CinderVolumeTemplateCore `json:",inline"` +} + // CinderVolumeSpec defines the desired state of CinderVolume type CinderVolumeSpec struct { // Common input parameters for all Cinder services diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 0f44aef2..0a122e03 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -45,9 +45,6 @@ type CinderTemplate struct { // CinderServiceTemplate defines the input parameters that can be defined for a given // Cinder service type CinderServiceTemplate struct { - // +kubebuilder:validation:Required - // ContainerImage - Cinder Container Image URL (will be set to environmental default if empty) - ContainerImage string `json:"containerImage"` // +kubebuilder:validation:Optional // NodeSelector to target subset of worker nodes running this service. Setting here overrides diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index b0c522e7..4b9ce231 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -230,6 +230,22 @@ func (in *CinderAPIStatus) DeepCopy() *CinderAPIStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CinderAPITemplate) DeepCopyInto(out *CinderAPITemplate) { + *out = *in + in.CinderAPITemplateCore.DeepCopyInto(&out.CinderAPITemplateCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderAPITemplate. +func (in *CinderAPITemplate) DeepCopy() *CinderAPITemplate { + if in == nil { + return nil + } + out := new(CinderAPITemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CinderAPITemplateCore) DeepCopyInto(out *CinderAPITemplateCore) { *out = *in in.CinderServiceTemplate.DeepCopyInto(&out.CinderServiceTemplate) if in.Replicas != nil { @@ -241,12 +257,12 @@ func (in *CinderAPITemplate) DeepCopyInto(out *CinderAPITemplate) { in.TLS.DeepCopyInto(&out.TLS) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderAPITemplate. -func (in *CinderAPITemplate) DeepCopy() *CinderAPITemplate { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderAPITemplateCore. +func (in *CinderAPITemplateCore) DeepCopy() *CinderAPITemplateCore { if in == nil { return nil } - out := new(CinderAPITemplate) + out := new(CinderAPITemplateCore) in.DeepCopyInto(out) return out } @@ -381,6 +397,22 @@ func (in *CinderBackupStatus) DeepCopy() *CinderBackupStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CinderBackupTemplate) DeepCopyInto(out *CinderBackupTemplate) { + *out = *in + in.CinderBackupTemplateCore.DeepCopyInto(&out.CinderBackupTemplateCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderBackupTemplate. +func (in *CinderBackupTemplate) DeepCopy() *CinderBackupTemplate { + if in == nil { + return nil + } + out := new(CinderBackupTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CinderBackupTemplateCore) DeepCopyInto(out *CinderBackupTemplateCore) { *out = *in in.CinderServiceTemplate.DeepCopyInto(&out.CinderServiceTemplate) if in.Replicas != nil { @@ -390,12 +422,12 @@ func (in *CinderBackupTemplate) DeepCopyInto(out *CinderBackupTemplate) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderBackupTemplate. -func (in *CinderBackupTemplate) DeepCopy() *CinderBackupTemplate { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderBackupTemplateCore. +func (in *CinderBackupTemplateCore) DeepCopy() *CinderBackupTemplateCore { if in == nil { return nil } - out := new(CinderBackupTemplate) + out := new(CinderBackupTemplateCore) in.DeepCopyInto(out) return out } @@ -614,6 +646,22 @@ func (in *CinderSchedulerStatus) DeepCopy() *CinderSchedulerStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CinderSchedulerTemplate) DeepCopyInto(out *CinderSchedulerTemplate) { + *out = *in + in.CinderSchedulerTemplateCore.DeepCopyInto(&out.CinderSchedulerTemplateCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderSchedulerTemplate. +func (in *CinderSchedulerTemplate) DeepCopy() *CinderSchedulerTemplate { + if in == nil { + return nil + } + out := new(CinderSchedulerTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CinderSchedulerTemplateCore) DeepCopyInto(out *CinderSchedulerTemplateCore) { *out = *in in.CinderServiceTemplate.DeepCopyInto(&out.CinderServiceTemplate) if in.Replicas != nil { @@ -623,12 +671,12 @@ func (in *CinderSchedulerTemplate) DeepCopyInto(out *CinderSchedulerTemplate) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderSchedulerTemplate. -func (in *CinderSchedulerTemplate) DeepCopy() *CinderSchedulerTemplate { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderSchedulerTemplateCore. +func (in *CinderSchedulerTemplateCore) DeepCopy() *CinderSchedulerTemplateCore { if in == nil { return nil } - out := new(CinderSchedulerTemplate) + out := new(CinderSchedulerTemplateCore) in.DeepCopyInto(out) return out } @@ -669,8 +717,7 @@ func (in *CinderServiceTemplate) DeepCopy() *CinderServiceTemplate { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CinderSpec) DeepCopyInto(out *CinderSpec) { *out = *in - out.CinderTemplate = in.CinderTemplate - out.Debug = in.Debug + in.CinderSpecBase.DeepCopyInto(&out.CinderSpecBase) in.CinderAPI.DeepCopyInto(&out.CinderAPI) in.CinderScheduler.DeepCopyInto(&out.CinderScheduler) in.CinderBackup.DeepCopyInto(&out.CinderBackup) @@ -681,6 +728,23 @@ func (in *CinderSpec) DeepCopyInto(out *CinderSpec) { (*out)[key] = *val.DeepCopy() } } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderSpec. +func (in *CinderSpec) DeepCopy() *CinderSpec { + if in == nil { + return nil + } + out := new(CinderSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CinderSpecBase) DeepCopyInto(out *CinderSpecBase) { + *out = *in + out.CinderTemplate = in.CinderTemplate + out.Debug = in.Debug if in.ExtraMounts != nil { in, out := &in.ExtraMounts, &out.ExtraMounts *out = make([]CinderExtraVolMounts, len(*in)) @@ -698,12 +762,38 @@ func (in *CinderSpec) DeepCopyInto(out *CinderSpec) { out.DBPurge = in.DBPurge } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderSpec. -func (in *CinderSpec) DeepCopy() *CinderSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderSpecBase. +func (in *CinderSpecBase) DeepCopy() *CinderSpecBase { if in == nil { return nil } - out := new(CinderSpec) + out := new(CinderSpecBase) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CinderSpecCore) DeepCopyInto(out *CinderSpecCore) { + *out = *in + in.CinderSpecBase.DeepCopyInto(&out.CinderSpecBase) + in.CinderAPI.DeepCopyInto(&out.CinderAPI) + in.CinderScheduler.DeepCopyInto(&out.CinderScheduler) + in.CinderBackup.DeepCopyInto(&out.CinderBackup) + if in.CinderVolumes != nil { + in, out := &in.CinderVolumes, &out.CinderVolumes + *out = make(map[string]CinderVolumeTemplateCore, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderSpecCore. +func (in *CinderSpecCore) DeepCopy() *CinderSpecCore { + if in == nil { + return nil + } + out := new(CinderSpecCore) in.DeepCopyInto(out) return out } @@ -914,6 +1004,22 @@ func (in *CinderVolumeStatus) DeepCopy() *CinderVolumeStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CinderVolumeTemplate) DeepCopyInto(out *CinderVolumeTemplate) { + *out = *in + in.CinderVolumeTemplateCore.DeepCopyInto(&out.CinderVolumeTemplateCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderVolumeTemplate. +func (in *CinderVolumeTemplate) DeepCopy() *CinderVolumeTemplate { + if in == nil { + return nil + } + out := new(CinderVolumeTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CinderVolumeTemplateCore) DeepCopyInto(out *CinderVolumeTemplateCore) { *out = *in in.CinderServiceTemplate.DeepCopyInto(&out.CinderServiceTemplate) if in.Replicas != nil { @@ -923,12 +1029,12 @@ func (in *CinderVolumeTemplate) DeepCopyInto(out *CinderVolumeTemplate) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderVolumeTemplate. -func (in *CinderVolumeTemplate) DeepCopy() *CinderVolumeTemplate { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderVolumeTemplateCore. +func (in *CinderVolumeTemplateCore) DeepCopy() *CinderVolumeTemplateCore { if in == nil { return nil } - out := new(CinderVolumeTemplate) + out := new(CinderVolumeTemplateCore) in.DeepCopyInto(out) return out } diff --git a/test/functional/cinder_controller_test.go b/test/functional/cinder_controller_test.go index e9f5f10b..81aa10a3 100644 --- a/test/functional/cinder_controller_test.go +++ b/test/functional/cinder_controller_test.go @@ -245,8 +245,8 @@ var _ = Describe("Cinder controller", func() { }) It("has the expected container image defaults", func() { cinderDefault := GetCinder(cinderTest.Instance) - Expect(cinderDefault.Spec.CinderAPI.CinderServiceTemplate.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_CINDER_API_IMAGE_URL_DEFAULT", cinderv1.CinderAPIContainerImage))) - Expect(cinderDefault.Spec.CinderScheduler.CinderServiceTemplate.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_CINDER_SCHEDULER_IMAGE_URL_DEFAULT", cinderv1.CinderSchedulerContainerImage))) + Expect(cinderDefault.Spec.CinderAPI.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_CINDER_API_IMAGE_URL_DEFAULT", cinderv1.CinderAPIContainerImage))) + Expect(cinderDefault.Spec.CinderScheduler.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_CINDER_SCHEDULER_IMAGE_URL_DEFAULT", cinderv1.CinderSchedulerContainerImage))) for _, volume := range cinderDefault.Spec.CinderVolumes { Expect(volume.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_CINDER_VOLUME_IMAGE_URL_DEFAULT", cinderv1.CinderVolumeContainerImage))) }