Skip to content

Commit

Permalink
Expose Default and Validate functions on NovaSpecCore
Browse files Browse the repository at this point in the history
The higher level meta operator will include the NovaSpecCore now in the
OpenStackControlPlane CRD and therefore it needs to default and validate
that struct in its webhooks, so the necessary functions are exposed.
This patch manages to avoid duplicating the validation logic because the
the NovaSpecCore is now directly embedded in the NovaSpec and therefore
validations written for NovaSpecCore can be also called on NovaSpec
too.

Jira: OSPRH-4835
  • Loading branch information
gibizer authored and openshift-merge-bot[bot] committed Mar 12, 2024
1 parent b3fb3a0 commit bd65adc
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions api/v1beta1/nova_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ func (r *Nova) Default() {
r.Spec.Default()
}

// Default - set defaults for this Nova spec
// Default - set defaults for this NovaCore spec.
func (spec *NovaSpec) Default() {
spec.NovaImages.Default(novaDefaults)
spec.NovaSpecCore.Default()
}

// Default - set defaults for this Nova spec. Expected to be called from
// the higher level meta operator.
func (spec *NovaSpecCore) Default() {
// NOTE(gibi): this cannot be expressed as kubebuilder defaults as the
// MetadataServiceTemplate is used both in the cellTemplate and in the
// NovaSpec but we need different defaults in the two places
Expand Down Expand Up @@ -113,7 +118,7 @@ func (spec *NovaSpec) Default() {

var _ webhook.Validator = &Nova{}

func (r *NovaSpec) ValidateCellTemplates(basePath *field.Path) field.ErrorList {
func (r *NovaSpecCore) ValidateCellTemplates(basePath *field.Path) field.ErrorList {
var errors field.ErrorList

if _, ok := r.CellTemplates[Cell0Name]; !ok {
Expand Down Expand Up @@ -203,17 +208,22 @@ func (r *NovaSpec) ValidateCellTemplates(basePath *field.Path) field.ErrorList {
return errors
}

func (r *NovaSpec) ValidateAPIServiceTemplate(basePath *field.Path) field.ErrorList {
func (r *NovaSpecCore) ValidateAPIServiceTemplate(basePath *field.Path) field.ErrorList {
errors := ValidateAPIDefaultConfigOverwrite(
basePath.Child("apiServiceTemplate").Child("defaultConfigOverwrite"),
r.APIServiceTemplate.DefaultConfigOverwrite)
return errors
}

// ValidateCreate validates the NovaSpec during the webhook invocation. It is
// ValidateCreate validates the NovaSpec during the webhook invocation.
func (r *NovaSpec) ValidateCreate(basePath *field.Path) field.ErrorList {
return r.NovaSpecCore.ValidateCreate(basePath)
}

// ValidateCreate validates the NovaSpecCore during the webhook invocation. It is
// expected to be called by the validation webhook in the higher level meta
// operator
func (r *NovaSpec) ValidateCreate(basePath *field.Path) field.ErrorList {
func (r *NovaSpecCore) ValidateCreate(basePath *field.Path) field.ErrorList {
errors := r.ValidateCellTemplates(basePath)
errors = append(errors, r.ValidateAPIServiceTemplate(basePath)...)
errors = append(
Expand All @@ -238,10 +248,15 @@ func (r *Nova) ValidateCreate() (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate validates the NovaSpec during the webhook invocation. It is
// ValidateUpdate validates the NovaSpec during the webhook invocation.
func (r *NovaSpec) ValidateUpdate(old NovaSpec, basePath *field.Path) field.ErrorList {
return r.NovaSpecCore.ValidateUpdate(old.NovaSpecCore, basePath)
}

// ValidateUpdate validates the NovaSpecCore during the webhook invocation. It is
// expected to be called by the validation webhook in the higher level meta
// operator
func (r *NovaSpec) ValidateUpdate(old NovaSpec, basePath *field.Path) field.ErrorList {
func (r *NovaSpecCore) ValidateUpdate(old NovaSpecCore, basePath *field.Path) field.ErrorList {
errors := r.ValidateCellTemplates(basePath)
errors = append(errors, r.ValidateAPIServiceTemplate(basePath)...)
errors = append(
Expand Down

0 comments on commit bd65adc

Please sign in to comment.