Skip to content

Commit

Permalink
Add ManilaSpecCore 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 ManilaSpec only it is missing the containerImages
from the nested API, Scheduler, and Share specs.

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

Jira: OSPRH-4835
  • Loading branch information
dprince committed Mar 1, 2024
1 parent b19b1bc commit def503c
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 32 deletions.
4 changes: 0 additions & 4 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ type ManilaTemplate struct {
// Manila service
type ManilaServiceTemplate struct {

// +kubebuilder:validation:Required
// ContainerImage - Manila API Container Image URL
ContainerImage string `json:"containerImage"`

// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service. Setting here overrides
// any global NodeSelector settings within the Manila CR.
Expand Down
46 changes: 34 additions & 12 deletions api/v1beta1/manila_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ const (

// ManilaSpec defines the desired state of Manila
type ManilaSpec struct {
ManilaSpecBase `json:",inline"`

// +kubebuilder:validation:Required
// ManilaAPI - Spec definition for the API service of this Manila deployment
ManilaAPI ManilaAPITemplate `json:"manilaAPI"`

// +kubebuilder:validation:Required
// ManilaScheduler - Spec definition for the Scheduler service of this Manila deployment
ManilaScheduler ManilaSchedulerTemplate `json:"manilaScheduler"`

// +kubebuilder:validation:Optional
// ManilaShares - Map of chosen names to spec definitions for the Share(s) service(s) of this Manila deployment
ManilaShares map[string]ManilaShareTemplate `json:"manilaShares,omitempty"`
}

// ManilaSpecCore defines the desired state of Manila. This version is used by OpenStackControlplane
type ManilaSpecCore struct {
ManilaSpecBase `json:",inline"`

// +kubebuilder:validation:Required
// ManilaAPI - Spec definition for the API service of this Manila deployment
ManilaAPI ManilaAPITemplateCore `json:"manilaAPI"`

// +kubebuilder:validation:Required
// ManilaScheduler - Spec definition for the Scheduler service of this Manila deployment
ManilaScheduler ManilaSchedulerTemplateCore `json:"manilaScheduler"`

// +kubebuilder:validation:Optional
// ManilaShares - Map of chosen names to spec definitions for the Share(s) service(s) of this Manila deployment
ManilaShares map[string]ManilaShareTemplateCore `json:"manilaShares,omitempty"`
}

// ManilaSpecBase -
type ManilaSpecBase struct {
ManilaTemplate `json:",inline"`

// +kubebuilder:validation:Required
Expand Down Expand Up @@ -68,18 +102,6 @@ type ManilaSpec struct {
// to /etc/<service>/<service>.conf.d directory a custom config file.
CustomServiceConfig string `json:"customServiceConfig,omitempty"`

// +kubebuilder:validation:Required
// ManilaAPI - Spec definition for the API service of this Manila deployment
ManilaAPI ManilaAPITemplate `json:"manilaAPI"`

// +kubebuilder:validation:Required
// ManilaScheduler - Spec definition for the Scheduler service of this Manila deployment
ManilaScheduler ManilaSchedulerTemplate `json:"manilaScheduler"`

// +kubebuilder:validation:Optional
// ManilaShares - Map of chosen names to spec definitions for the Share(s) service(s) of this Manila deployment
ManilaShares map[string]ManilaShareTemplate `json:"manilaShares,omitempty"`

// +kubebuilder:validation:Optional
// ExtraMounts containing conf files and credentials
ExtraMounts []ManilaExtraVolMounts `json:"extraMounts,omitempty"`
Expand Down
13 changes: 13 additions & 0 deletions api/v1beta1/manila_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (r *Manila) Default() {

// Default - set defaults for this Manila spec
func (spec *ManilaSpec) Default() {
// only put container image validations here
if spec.ManilaAPI.ContainerImage == "" {
spec.ManilaAPI.ContainerImage = manilaDefaults.APIContainerImageURL
}
Expand All @@ -95,6 +96,12 @@ func (spec *ManilaSpec) Default() {
spec.ManilaShares[key] = manilaShare
}
}
spec.ManilaSpecBase.Default()

}

// Default - set defaults for this Manila spec base
func (spec *ManilaSpecBase) Default() {

if spec.DBPurge.Age == 0 {
spec.DBPurge.Age = manilaDefaults.DBPurgeAge
Expand All @@ -105,6 +112,12 @@ func (spec *ManilaSpec) Default() {
}
}

// Default - set defaults for this Manila spec core. This version is used by OpenStackControlplane
func (spec *ManilaSpecCore) Default() {

spec.ManilaSpecBase.Default()
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-manila-openstack-org-v1beta1-manila,mutating=false,failurePolicy=fail,sideEffects=None,groups=manila.openstack.org,resources=manilas,verbs=create;update,versions=v1beta1,name=vmanila.kb.io,admissionReviewVersions=v1

Expand Down
9 changes: 9 additions & 0 deletions api/v1beta1/manilaapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ import (

// ManilaAPITemplate defines the input parameter for the ManilaAPI service
type ManilaAPITemplate struct {
ManilaAPITemplateCore `json:",inline"`

// +kubebuilder:validation:Required
// ContainerImage - Manila API Container Image URL
ContainerImage string `json:"containerImage"`
}

// ManilaAPITemplateCore -
type ManilaAPITemplateCore struct {

// Common input parameters collected in the ManilaServiceTemplate
ManilaServiceTemplate `json:",inline"`
Expand Down
9 changes: 9 additions & 0 deletions api/v1beta1/manilascheduler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ import (

// ManilaSchedulerTemplate defines the input parameter for the ManilaScheduler service
type ManilaSchedulerTemplate struct {
ManilaSchedulerTemplateCore `json:",inline"`

// +kubebuilder:validation:Required
// ContainerImage - Manila API Container Image URL
ContainerImage string `json:"containerImage"`
}

// ManilaSchedulerTemplateCore -
type ManilaSchedulerTemplateCore struct {

// Common input parameters collected in the ManilaServiceTemplate
ManilaServiceTemplate `json:",inline"`
Expand Down
11 changes: 11 additions & 0 deletions api/v1beta1/manilashare_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ import (
// ManilaShareTemplate defines the input parameter for the ManilaShare service
type ManilaShareTemplate struct {

// Common input parameters collected in the ManilaServiceTemplate
ManilaShareTemplateCore `json:",inline"`

// +kubebuilder:validation:Required
// ContainerImage - Manila API Container Image URL
ContainerImage string `json:"containerImage"`
}

// ManilaShareTemplateCore -
type ManilaShareTemplateCore struct {

// Common input parameters collected in the ManilaServiceTemplate
ManilaServiceTemplate `json:",inline"`

Expand Down
117 changes: 103 additions & 14 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/functional/manila_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ var _ = Describe("Manila controller", func() {
})
It("has the expected container image defaults", func() {
manilaDefault := GetManila(manilaTest.Instance)
Expect(manilaDefault.Spec.ManilaAPI.ManilaServiceTemplate.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_MANILA_API_IMAGE_URL_DEFAULT", manilav1.ManilaAPIContainerImage)))
Expect(manilaDefault.Spec.ManilaScheduler.ManilaServiceTemplate.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_MANILA_SCHEDULER_IMAGE_URL_DEFAULT", manilav1.ManilaSchedulerContainerImage)))
Expect(manilaDefault.Spec.ManilaAPI.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_MANILA_API_IMAGE_URL_DEFAULT", manilav1.ManilaAPIContainerImage)))
Expect(manilaDefault.Spec.ManilaScheduler.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_MANILA_SCHEDULER_IMAGE_URL_DEFAULT", manilav1.ManilaSchedulerContainerImage)))
for _, share := range manilaDefault.Spec.ManilaShares {
Expect(share.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_MANILA_SHARE_IMAGE_URL_DEFAULT", manilav1.ManilaShareContainerImage)))
}
Expand Down

0 comments on commit def503c

Please sign in to comment.