From d1d1a652b8fc123d7df6467d443eb31a0e363e67 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 1 Mar 2024 15:32:50 -0500 Subject: [PATCH] Add Swift*SpecCore struct This version of the structs (each called "core") is meant to be used via the OpenStackControlplane. It is the same as regular Swift specs except they don't have containerImages on them. The Default() function for webhooks has been split accordingly. Jira: OSPRH-4835 --- api/v1beta1/swift_types.go | 23 ++++++ api/v1beta1/swift_webhook.go | 5 ++ api/v1beta1/swiftproxy_types.go | 13 +++- api/v1beta1/swiftring_types.go | 15 ++-- api/v1beta1/swiftstorage_types.go | 33 +++++---- api/v1beta1/zz_generated.deepcopy.go | 107 ++++++++++++++++++++++++--- controllers/swift_controller.go | 54 ++++++++------ 7 files changed, 191 insertions(+), 59 deletions(-) diff --git a/api/v1beta1/swift_types.go b/api/v1beta1/swift_types.go index 0de9704e..deb2a9fd 100644 --- a/api/v1beta1/swift_types.go +++ b/api/v1beta1/swift_types.go @@ -32,6 +32,8 @@ const ( // SwiftSpec defines the desired state of Swift type SwiftSpec struct { + SwiftSpecBase `json:",inline"` + // +kubebuilder:validation:Required // SwiftRing - Spec definition for the Ring service of this Swift deployment SwiftRing SwiftRingSpec `json:"swiftRing"` @@ -43,6 +45,27 @@ type SwiftSpec struct { // +kubebuilder:validation:Required // SwiftProxy - Spec definition for the Proxy service of this Swift deployment SwiftProxy SwiftProxySpec `json:"swiftProxy"` +} + +// SwiftSpecCore defines the desired state of Swift (this version is used by OpenStackControlplane) +type SwiftSpecCore struct { + SwiftSpecBase `json:",inline"` + + // +kubebuilder:validation:Required + // SwiftRing - Spec definition for the Ring service of this Swift deployment + SwiftRing SwiftRingSpecCore `json:"swiftRing"` + + // +kubebuilder:validation:Required + // SwiftStorage - Spec definition for the Storage service of this Swift deployment + SwiftStorage SwiftStorageSpecCore `json:"swiftStorage"` + + // +kubebuilder:validation:Required + // SwiftProxy - Spec definition for the Proxy service of this Swift deployment + SwiftProxy SwiftProxySpecCore `json:"swiftProxy"` +} + +// SwiftSpecBase - +type SwiftSpecBase struct { // +kubebuilder:validation:Required // +kubebuilder:default=swift-conf diff --git a/api/v1beta1/swift_webhook.go b/api/v1beta1/swift_webhook.go index 83bbfcd3..0c7db941 100644 --- a/api/v1beta1/swift_webhook.go +++ b/api/v1beta1/swift_webhook.go @@ -100,6 +100,11 @@ func (spec *SwiftSpec) Default() { } } +// Default - set defaults for this Swift core spec (this version is used by OpenStackControlplane webhooks) +func (spec *SwiftSpecCore) Default() { + // nothing here yet +} + // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. //+kubebuilder:webhook:path=/validate-swift-openstack-org-v1beta1-swift,mutating=false,failurePolicy=fail,sideEffects=None,groups=swift.openstack.org,resources=swifts,verbs=create;update,versions=v1beta1,name=vswift.kb.io,admissionReviewVersions=v1 diff --git a/api/v1beta1/swiftproxy_types.go b/api/v1beta1/swiftproxy_types.go index 8752f585..008a6851 100644 --- a/api/v1beta1/swiftproxy_types.go +++ b/api/v1beta1/swiftproxy_types.go @@ -36,16 +36,21 @@ type PasswordSelector struct { // SwiftProxySpec defines the desired state of SwiftProxy type SwiftProxySpec struct { + SwiftProxySpecCore `json:",inline"` + + // +kubebuilder:validation:Required + // Swift Proxy Container Image URL + ContainerImageProxy string `json:"containerImageProxy"` +} + +// SwiftProxySpecCore - +type SwiftProxySpecCore struct { // +kubebuilder:validation:Required // +kubebuilder:default=1 // +kubebuilder:validation:Minimum=0 // Replicas of Swift Proxy Replicas *int32 `json:"replicas"` - // +kubebuilder:validation:Required - // Swift Proxy Container Image URL - ContainerImageProxy string `json:"containerImageProxy"` - // +kubebuilder:default=swift // ServiceUser - optional username used for this service to register in Swift ServiceUser string `json:"serviceUser"` diff --git a/api/v1beta1/swiftring_types.go b/api/v1beta1/swiftring_types.go index 5794a7e7..c62fe61f 100644 --- a/api/v1beta1/swiftring_types.go +++ b/api/v1beta1/swiftring_types.go @@ -35,6 +35,16 @@ type SwiftRingSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file + SwiftRingSpecCore `json:",inline"` + + // +kubebuilder:validation:Required + // Image URL for Swift proxy service + ContainerImage string `json:"containerImage"` +} + +// SwiftRingSpec defines the desired state of SwiftRing +type SwiftRingSpecCore struct { + // +kubebuilder:validation:Required // +kubebuilder:default=1 // +kubebuilder:validation:Minimum=1 @@ -53,10 +63,6 @@ type SwiftRingSpec struct { // Minimum numbeir of hours to restrict moving a partition more than once MinPartHours *int64 `json:"minPartHours"` - // +kubebuilder:validation:Required - // Image URL for Swift proxy service - ContainerImage string `json:"containerImage"` - // +kubebuilder:validation:Required // +kubebuilder:default=swift-conf // Name of Secret containing swift.conf @@ -100,7 +106,6 @@ type SwiftRingList struct { Items []SwiftRing `json:"items"` } - type SwiftDisk struct { Device string `json:"device"` Path string `json:"path"` diff --git a/api/v1beta1/swiftstorage_types.go b/api/v1beta1/swiftstorage_types.go index 1619b77d..3881b64d 100644 --- a/api/v1beta1/swiftstorage_types.go +++ b/api/v1beta1/swiftstorage_types.go @@ -26,20 +26,7 @@ import ( // SwiftStorageSpec defines the desired state of SwiftStorage type SwiftStorageSpec struct { - // +kubebuilder:validation:Required - // +kubebuilder:default=1 - // +kubebuilder:validation:Minimum=0 - Replicas *int32 `json:"replicas"` - - // +kubebuilder:validation:Required - // Name of StorageClass to use for Swift PVs - // +kubebuilder:default="" - StorageClass string `json:"storageClass"` - - // +kubebuilder:validation:Required - // +kubebuilder:default="10Gi" - // Minimum size for Swift PVs - StorageRequest string `json:"storageRequest"` + SwiftStorageSpecCore `json:",inline"` // +kubebuilder:validation:Required // Image URL for Swift account service @@ -56,6 +43,24 @@ type SwiftStorageSpec struct { // +kubebuilder:validation:Required // Image URL for Swift proxy service ContainerImageProxy string `json:"containerImageProxy"` +} + +// SwiftStorageSpecCore - +type SwiftStorageSpecCore struct { + // +kubebuilder:validation:Required + // +kubebuilder:default=1 + // +kubebuilder:validation:Minimum=0 + Replicas *int32 `json:"replicas"` + + // +kubebuilder:validation:Required + // Name of StorageClass to use for Swift PVs + // +kubebuilder:default="" + StorageClass string `json:"storageClass"` + + // +kubebuilder:validation:Required + // +kubebuilder:default="10Gi" + // Minimum size for Swift PVs + StorageRequest string `json:"storageRequest"` // +kubebuilder:validation:Required // +kubebuilder:default=swift-conf diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index f2d29b99..3471c07a 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -214,6 +214,22 @@ func (in *SwiftProxyList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SwiftProxySpec) DeepCopyInto(out *SwiftProxySpec) { + *out = *in + in.SwiftProxySpecCore.DeepCopyInto(&out.SwiftProxySpecCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftProxySpec. +func (in *SwiftProxySpec) DeepCopy() *SwiftProxySpec { + if in == nil { + return nil + } + out := new(SwiftProxySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SwiftProxySpecCore) DeepCopyInto(out *SwiftProxySpecCore) { *out = *in if in.Replicas != nil { in, out := &in.Replicas, &out.Replicas @@ -237,12 +253,12 @@ func (in *SwiftProxySpec) DeepCopyInto(out *SwiftProxySpec) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftProxySpec. -func (in *SwiftProxySpec) DeepCopy() *SwiftProxySpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftProxySpecCore. +func (in *SwiftProxySpecCore) DeepCopy() *SwiftProxySpecCore { if in == nil { return nil } - out := new(SwiftProxySpec) + out := new(SwiftProxySpecCore) in.DeepCopyInto(out) return out } @@ -352,6 +368,22 @@ func (in *SwiftRingList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SwiftRingSpec) DeepCopyInto(out *SwiftRingSpec) { + *out = *in + in.SwiftRingSpecCore.DeepCopyInto(&out.SwiftRingSpecCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftRingSpec. +func (in *SwiftRingSpec) DeepCopy() *SwiftRingSpec { + if in == nil { + return nil + } + out := new(SwiftRingSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SwiftRingSpecCore) DeepCopyInto(out *SwiftRingSpecCore) { *out = *in if in.RingReplicas != nil { in, out := &in.RingReplicas, &out.RingReplicas @@ -371,12 +403,12 @@ func (in *SwiftRingSpec) DeepCopyInto(out *SwiftRingSpec) { out.TLS = in.TLS } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftRingSpec. -func (in *SwiftRingSpec) DeepCopy() *SwiftRingSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftRingSpecCore. +func (in *SwiftRingSpecCore) DeepCopy() *SwiftRingSpecCore { if in == nil { return nil } - out := new(SwiftRingSpec) + out := new(SwiftRingSpecCore) in.DeepCopyInto(out) return out } @@ -413,9 +445,25 @@ func (in *SwiftRingStatus) DeepCopy() *SwiftRingStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SwiftSpec) DeepCopyInto(out *SwiftSpec) { *out = *in + in.SwiftSpecBase.DeepCopyInto(&out.SwiftSpecBase) in.SwiftRing.DeepCopyInto(&out.SwiftRing) in.SwiftStorage.DeepCopyInto(&out.SwiftStorage) in.SwiftProxy.DeepCopyInto(&out.SwiftProxy) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftSpec. +func (in *SwiftSpec) DeepCopy() *SwiftSpec { + if in == nil { + return nil + } + out := new(SwiftSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SwiftSpecBase) DeepCopyInto(out *SwiftSpecBase) { + *out = *in if in.NetworkAttachments != nil { in, out := &in.NetworkAttachments, &out.NetworkAttachments *out = make([]string, len(*in)) @@ -423,12 +471,31 @@ func (in *SwiftSpec) DeepCopyInto(out *SwiftSpec) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftSpec. -func (in *SwiftSpec) DeepCopy() *SwiftSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftSpecBase. +func (in *SwiftSpecBase) DeepCopy() *SwiftSpecBase { if in == nil { return nil } - out := new(SwiftSpec) + out := new(SwiftSpecBase) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SwiftSpecCore) DeepCopyInto(out *SwiftSpecCore) { + *out = *in + in.SwiftSpecBase.DeepCopyInto(&out.SwiftSpecBase) + in.SwiftRing.DeepCopyInto(&out.SwiftRing) + in.SwiftStorage.DeepCopyInto(&out.SwiftStorage) + in.SwiftProxy.DeepCopyInto(&out.SwiftProxy) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftSpecCore. +func (in *SwiftSpecCore) DeepCopy() *SwiftSpecCore { + if in == nil { + return nil + } + out := new(SwiftSpecCore) in.DeepCopyInto(out) return out } @@ -516,6 +583,22 @@ func (in *SwiftStorageList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SwiftStorageSpec) DeepCopyInto(out *SwiftStorageSpec) { + *out = *in + in.SwiftStorageSpecCore.DeepCopyInto(&out.SwiftStorageSpecCore) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftStorageSpec. +func (in *SwiftStorageSpec) DeepCopy() *SwiftStorageSpec { + if in == nil { + return nil + } + out := new(SwiftStorageSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SwiftStorageSpecCore) DeepCopyInto(out *SwiftStorageSpecCore) { *out = *in if in.Replicas != nil { in, out := &in.Replicas, &out.Replicas @@ -536,12 +619,12 @@ func (in *SwiftStorageSpec) DeepCopyInto(out *SwiftStorageSpec) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftStorageSpec. -func (in *SwiftStorageSpec) DeepCopy() *SwiftStorageSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SwiftStorageSpecCore. +func (in *SwiftStorageSpecCore) DeepCopy() *SwiftStorageSpecCore { if in == nil { return nil } - out := new(SwiftStorageSpec) + out := new(SwiftStorageSpecCore) in.DeepCopyInto(out) return out } diff --git a/controllers/swift_controller.go b/controllers/swift_controller.go index 49f24d53..e8e4e3af 100644 --- a/controllers/swift_controller.go +++ b/controllers/swift_controller.go @@ -359,10 +359,12 @@ func (r *SwiftReconciler) reconcileDelete(ctx context.Context, instance *swiftv1 func (r *SwiftReconciler) ringCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift) (*swiftv1.SwiftRing, controllerutil.OperationResult, error) { swiftRingSpec := swiftv1.SwiftRingSpec{ - RingReplicas: instance.Spec.SwiftRing.RingReplicas, - ContainerImage: instance.Spec.SwiftRing.ContainerImage, - SwiftConfSecret: instance.Spec.SwiftConfSecret, - TLS: instance.Spec.SwiftProxy.TLS.Ca, + ContainerImage: instance.Spec.SwiftRing.ContainerImage, + SwiftRingSpecCore: swiftv1.SwiftRingSpecCore{ + RingReplicas: instance.Spec.SwiftRing.RingReplicas, + SwiftConfSecret: instance.Spec.SwiftConfSecret, + TLS: instance.Spec.SwiftProxy.TLS.Ca, + }, } deployment := &swiftv1.SwiftRing{ @@ -388,18 +390,20 @@ func (r *SwiftReconciler) ringCreateOrUpdate(ctx context.Context, instance *swif func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift, memcachedServers string) (*swiftv1.SwiftStorage, controllerutil.OperationResult, error) { swiftStorageSpec := swiftv1.SwiftStorageSpec{ - Replicas: instance.Spec.SwiftStorage.Replicas, - StorageClass: instance.Spec.SwiftStorage.StorageClass, - StorageRequest: instance.Spec.SwiftStorage.StorageRequest, ContainerImageAccount: instance.Spec.SwiftStorage.ContainerImageAccount, ContainerImageContainer: instance.Spec.SwiftStorage.ContainerImageContainer, ContainerImageObject: instance.Spec.SwiftStorage.ContainerImageObject, ContainerImageProxy: instance.Spec.SwiftStorage.ContainerImageProxy, - SwiftConfSecret: instance.Spec.SwiftConfSecret, - NetworkAttachments: instance.Spec.SwiftStorage.NetworkAttachments, - MemcachedServers: memcachedServers, - ContainerSharderEnabled: instance.Spec.SwiftStorage.ContainerSharderEnabled, - DefaultConfigOverwrite: instance.Spec.SwiftStorage.DefaultConfigOverwrite, + SwiftStorageSpecCore: swiftv1.SwiftStorageSpecCore{ + Replicas: instance.Spec.SwiftStorage.Replicas, + StorageClass: instance.Spec.SwiftStorage.StorageClass, + StorageRequest: instance.Spec.SwiftStorage.StorageRequest, + SwiftConfSecret: instance.Spec.SwiftConfSecret, + NetworkAttachments: instance.Spec.SwiftStorage.NetworkAttachments, + MemcachedServers: memcachedServers, + ContainerSharderEnabled: instance.Spec.SwiftStorage.ContainerSharderEnabled, + DefaultConfigOverwrite: instance.Spec.SwiftStorage.DefaultConfigOverwrite, + }, } deployment := &swiftv1.SwiftStorage{ @@ -425,18 +429,20 @@ func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *s func (r *SwiftReconciler) proxyCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift, memcachedServers string) (*swiftv1.SwiftProxy, controllerutil.OperationResult, error) { swiftProxySpec := swiftv1.SwiftProxySpec{ - Replicas: instance.Spec.SwiftProxy.Replicas, - ContainerImageProxy: instance.Spec.SwiftProxy.ContainerImageProxy, - Secret: instance.Spec.SwiftProxy.Secret, - ServiceUser: instance.Spec.SwiftProxy.ServiceUser, - PasswordSelectors: instance.Spec.SwiftProxy.PasswordSelectors, - SwiftConfSecret: instance.Spec.SwiftConfSecret, - Override: instance.Spec.SwiftProxy.Override, - NetworkAttachments: instance.Spec.SwiftProxy.NetworkAttachments, - MemcachedServers: memcachedServers, - TLS: instance.Spec.SwiftProxy.TLS, - DefaultConfigOverwrite: instance.Spec.SwiftProxy.DefaultConfigOverwrite, - EncryptionEnabled: instance.Spec.SwiftProxy.EncryptionEnabled, + ContainerImageProxy: instance.Spec.SwiftProxy.ContainerImageProxy, + SwiftProxySpecCore: swiftv1.SwiftProxySpecCore{ + Replicas: instance.Spec.SwiftProxy.Replicas, + Secret: instance.Spec.SwiftProxy.Secret, + ServiceUser: instance.Spec.SwiftProxy.ServiceUser, + PasswordSelectors: instance.Spec.SwiftProxy.PasswordSelectors, + SwiftConfSecret: instance.Spec.SwiftConfSecret, + Override: instance.Spec.SwiftProxy.Override, + NetworkAttachments: instance.Spec.SwiftProxy.NetworkAttachments, + MemcachedServers: memcachedServers, + TLS: instance.Spec.SwiftProxy.TLS, + DefaultConfigOverwrite: instance.Spec.SwiftProxy.DefaultConfigOverwrite, + EncryptionEnabled: instance.Spec.SwiftProxy.EncryptionEnabled, + }, } deployment := &swiftv1.SwiftProxy{