Skip to content

Commit

Permalink
Add CinderSpecCore struct
Browse files Browse the repository at this point in the history
This version of the struct (called "core") is meant to
be used via the OpenStackControlplane. It is the same
as CinderSpec only it is missing the containerImages
from the nested API, Backup, Scheduler, and Volume specs.

The Default() function for webhooks has been split accordingly.

Jira: OSPRH-4835
  • Loading branch information
dprince committed Mar 6, 2024
1 parent c2e2433 commit 2f257b0
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 55 deletions.
56 changes: 40 additions & 16 deletions api/v1beta1/cinder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,35 +88,60 @@ type CinderSpec struct {
// to /etc/<service>/<service>.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
Expand Down
31 changes: 18 additions & 13 deletions api/v1beta1/cinder_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 10 additions & 1 deletion api/v1beta1/cinderapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion api/v1beta1/cinderbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion api/v1beta1/cinderscheduler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion api/v1beta1/cindervolume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2f257b0

Please sign in to comment.