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 Feb 23, 2024
1 parent fe54250 commit b701dd4
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 39 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
26 changes: 13 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.Default()
}

// Default - set defaults for this Cinder spec
func (spec *CinderSpecBase) Default() {

if spec.DBPurge.Age == 0 {
spec.DBPurge.Age = cinderDefaults.DBPurgeAge
Expand Down
28 changes: 28 additions & 0 deletions api/v1beta1/cinderapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,36 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)


// CinderAPITemplate defines the input parameters for the Cinder API service
type CinderAPITemplateCore struct {
// Common input parameters for the Cinder API service
CinderServiceTemplate `json:",inline"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=0
// Replicas - Cinder API Replicas
Replicas *int32 `json:"replicas"`

// +kubebuilder:validation:Optional
// Override, provides the ability to override the generated manifest of several child resources.
Override APIOverrideSpec `json:"override,omitempty"`

// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
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"`

// Common input parameters for the Cinder API service
CinderServiceTemplate `json:",inline"`

Expand Down
18 changes: 18 additions & 0 deletions api/v1beta1/cinderbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,26 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CinderBackupTemplate defines the input parameters for the Cinder Backup service
type CinderBackupTemplateCore struct {
// Common input parameters for the Cinder Backup service
CinderServiceTemplate `json:",inline"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=0
// Replicas - Cinder Backup Replicas
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"`

// Common input parameters for the Cinder Backup service
CinderServiceTemplate `json:",inline"`

Expand Down
17 changes: 17 additions & 0 deletions api/v1beta1/cinderscheduler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,25 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CinderSchedulerTemplate defines the input parameters for the Cinder Scheduler service
type CinderSchedulerTemplateCore struct {
// Common input parameters for the Cinder Scheduler service
CinderServiceTemplate `json:",inline"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=0
// Replicas - Cinder Scheduler Replicas
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"`

// Common input parameters for the Cinder Scheduler service
CinderServiceTemplate `json:",inline"`

Expand Down
19 changes: 19 additions & 0 deletions api/v1beta1/cindervolume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,27 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CinderVolumeTemplate defines the input parameters for the Cinder Volume service
type CinderVolumeTemplateCore struct {
// Common input parameters for the Cinder Volume service
CinderServiceTemplate `json:",inline"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=1
// Replicas - Cinder Volume Replicas
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"`

// Common input parameters for the Cinder Volume service
CinderServiceTemplate `json:",inline"`

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 @@ -46,9 +46,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 b701dd4

Please sign in to comment.