Skip to content

Commit

Permalink
Align LastAppliedTopology to TopologyRef interface
Browse files Browse the repository at this point in the history
While TopologyRef is able to reference Name and namespace, we currently
only save TopologyRef.Name to .Status.LastAppliedTopology. This patch
aligns both interfaces to use the same type in the same form. In
addition, some logic is moved to infra-operator because is common to all
operators, and this patch also adopts this new form.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Feb 26, 2025
1 parent 6167332 commit ad1bcb6
Show file tree
Hide file tree
Showing 50 changed files with 685 additions and 416 deletions.
14 changes: 13 additions & 1 deletion api/bases/nova.openstack.org_novaapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,19 @@ spec:
type: object
lastAppliedTopology:
description: LastAppliedTopology - the last applied Topology
type: string
properties:
name:
description: Name - The Topology CR name that the Service references
type: string
namespace:
description: |-
Namespace - The Namespace to fetch the Topology CR referenced
NOTE: Namespace currently points by default to the same namespace where
the Service is deployed. Customizing the namespace is not supported and
webhooks prevent editing this field to a value different from the
current project
type: string
type: object
networkAttachments:
additionalProperties:
items:
Expand Down
14 changes: 13 additions & 1 deletion api/bases/nova.openstack.org_novacomputes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,19 @@ spec:
type: object
lastAppliedTopology:
description: LastAppliedTopology - the last applied Topology
type: string
properties:
name:
description: Name - The Topology CR name that the Service references
type: string
namespace:
description: |-
Namespace - The Namespace to fetch the Topology CR referenced
NOTE: Namespace currently points by default to the same namespace where
the Service is deployed. Customizing the namespace is not supported and
webhooks prevent editing this field to a value different from the
current project
type: string
type: object
networkAttachments:
additionalProperties:
items:
Expand Down
14 changes: 13 additions & 1 deletion api/bases/nova.openstack.org_novaconductors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,19 @@ spec:
type: object
lastAppliedTopology:
description: LastAppliedTopology - the last applied Topology
type: string
properties:
name:
description: Name - The Topology CR name that the Service references
type: string
namespace:
description: |-
Namespace - The Namespace to fetch the Topology CR referenced
NOTE: Namespace currently points by default to the same namespace where
the Service is deployed. Customizing the namespace is not supported and
webhooks prevent editing this field to a value different from the
current project
type: string
type: object
networkAttachments:
additionalProperties:
items:
Expand Down
14 changes: 13 additions & 1 deletion api/bases/nova.openstack.org_novametadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,19 @@ spec:
type: object
lastAppliedTopology:
description: LastAppliedTopology - the last applied Topology
type: string
properties:
name:
description: Name - The Topology CR name that the Service references
type: string
namespace:
description: |-
Namespace - The Namespace to fetch the Topology CR referenced
NOTE: Namespace currently points by default to the same namespace where
the Service is deployed. Customizing the namespace is not supported and
webhooks prevent editing this field to a value different from the
current project
type: string
type: object
networkAttachments:
additionalProperties:
items:
Expand Down
14 changes: 13 additions & 1 deletion api/bases/nova.openstack.org_novanovncproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,19 @@ spec:
type: object
lastAppliedTopology:
description: LastAppliedTopology - the last applied Topology
type: string
properties:
name:
description: Name - The Topology CR name that the Service references
type: string
namespace:
description: |-
Namespace - The Namespace to fetch the Topology CR referenced
NOTE: Namespace currently points by default to the same namespace where
the Service is deployed. Customizing the namespace is not supported and
webhooks prevent editing this field to a value different from the
current project
type: string
type: object
networkAttachments:
additionalProperties:
items:
Expand Down
14 changes: 13 additions & 1 deletion api/bases/nova.openstack.org_novaschedulers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,19 @@ spec:
type: object
lastAppliedTopology:
description: LastAppliedTopology - the last applied Topology
type: string
properties:
name:
description: Name - The Topology CR name that the Service references
type: string
namespace:
description: |-
Namespace - The Namespace to fetch the Topology CR referenced
NOTE: Namespace currently points by default to the same namespace where
the Service is deployed. Customizing the namespace is not supported and
webhooks prevent editing this field to a value different from the
current project
type: string
type: object
networkAttachments:
additionalProperties:
items:
Expand Down
1 change: 1 addition & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/google/go-cmp v0.6.0
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250226120707-ee102640a845
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250225220922-3ead38b7284f
github.com/robfig/cron/v3 v3.0.1
k8s.io/api v0.29.14
Expand Down
2 changes: 2 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250226120707-ee102640a845 h1:18Si6z23Spv94fEkJZRC3Pzjk6UmkzzaiVdaqoAVc3o=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250226120707-ee102640a845/go.mod h1:jZ74v7V5JcKjSIgGWyrunPVMTuyw6SBBfp7f74RDrSo=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250225220922-3ead38b7284f h1:3JVxp1FhQw62xYc/tnA04uPn9WCUTYupWucRQJeTy54=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250225220922-3ead38b7284f/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
34 changes: 19 additions & 15 deletions api/v1beta1/nova_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,21 @@ func (r *NovaSpecCore) ValidateCellTemplates(basePath *field.Path, namespace str
)
}
if cell.MetadataServiceTemplate.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(
cell.MetadataServiceTemplate.TopologyRef.Namespace,
*cellPath.Child("metadataServiceTemplate"),
namespace,
); err != nil {
errors = append(errors, err)
}
errors = append(
errors,
cell.MetadataServiceTemplate.ValidateMetadataTopology(
cellPath.Child("metadataServiceTemplate"),
namespace,
))
}

if cell.NoVNCProxyServiceTemplate.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(
cell.NoVNCProxyServiceTemplate.TopologyRef.Namespace,
*cellPath.Child("noVNCProxyServiceTemplate"),
namespace,
); err != nil {
errors = append(errors, err)
}
errors = append(
errors,
cell.NoVNCProxyServiceTemplate.ValidateNoVNCProxyTopology(
cellPath.Child("noVNCProxyServiceTemplate"),
namespace,
))
}

errors = append(
Expand Down Expand Up @@ -229,6 +227,12 @@ func (r *NovaSpecCore) ValidateCellTemplates(basePath *field.Path, namespace str
errors, computeTemplate.ValidateDefaultConfigOverwrite(
cellPath.Child("novaComputeTemplates").Key(computeName))...,
)
if computeTemplate.TopologyRef != nil {
errors = append(
errors, computeTemplate.ValidateComputeTopology(
cellPath.Child("novaComputeTemplates").Key(computeName),
namespace))
}
}
}

Expand Down Expand Up @@ -301,7 +305,7 @@ func (r *NovaSpecCore) ValidateUpdate(old NovaSpecCore, basePath *field.Path, na
errors,
r.MetadataServiceTemplate.ValidateDefaultConfigOverwrite(
basePath.Child("metadataServiceTemplate"))...)

// Validate referenced topology for top-level services
errors = append(errors, r.ValidateNovaSpecTopology(basePath, namespace)...)
return errors
}
Expand Down
17 changes: 16 additions & 1 deletion api/v1beta1/novaapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ type NovaAPIStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// LastAppliedTopology - the last applied Topology
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
LastAppliedTopology *topologyv1.TopoRef `json:"lastAppliedTopology,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -239,3 +239,18 @@ func (s NovaAPIStatus) GetConditions() condition.Conditions {
func (n NovaAPI) GetSecret() string {
return n.Spec.Secret
}

// GetSpecTopologyRef - Returns the LastAppliedTopology Set in the Status
func (instance *NovaAPI) GetSpecTopologyRef() *topologyv1.TopoRef {
return instance.Spec.TopologyRef
}

// GetLastAppliedTopology - Returns the LastAppliedTopology Set in the Status
func (instance *NovaAPI) GetLastAppliedTopology() *topologyv1.TopoRef {
return instance.Status.LastAppliedTopology
}

// SetLastAppliedTopology - Sets the LastAppliedTopology value in the Status
func (instance *NovaAPI) SetLastAppliedTopology(topologyRef *topologyv1.TopoRef) {
instance.Status.LastAppliedTopology = topologyRef
}
12 changes: 12 additions & 0 deletions api/v1beta1/novaapi_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ func ValidateAPIDefaultConfigOverwrite(
defaultConfigOverwrite,
[]string{"policy.yaml", "api-paste.ini"})
}

// Validate validates the referenced TopoRef.Namespace.
func (r *NovaAPITemplate) ValidateAPITopology(
basePath *field.Path,
namespace string,
) *field.Error {
if err := topologyv1.ValidateTopologyNamespace(
r.TopologyRef.Namespace, *basePath, namespace); err != nil {
return err
}
return nil
}
17 changes: 16 additions & 1 deletion api/v1beta1/novacompute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type NovaComputeStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// LastAppliedTopology - the last applied Topology
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
LastAppliedTopology *topologyv1.TopoRef `json:"lastAppliedTopology,omitempty"`
}

// NovaComputeCellStatus defines state of NovaCompute in cell
Expand Down Expand Up @@ -239,3 +239,18 @@ func NewNovaComputeSpec(

return novaComputeSpec
}

// GetSpecTopologyRef - Returns the LastAppliedTopology Set in the Status
func (instance *NovaCompute) GetSpecTopologyRef() *topologyv1.TopoRef {
return instance.Spec.TopologyRef
}

// GetLastAppliedTopology - Returns the LastAppliedTopology Set in the Status
func (instance *NovaCompute) GetLastAppliedTopology() *topologyv1.TopoRef {
return instance.Status.LastAppliedTopology
}

// SetLastAppliedTopology - Sets the LastAppliedTopology value in the Status
func (instance *NovaCompute) SetLastAppliedTopology(topologyRef *topologyv1.TopoRef) {
instance.Status.LastAppliedTopology = topologyRef
}
12 changes: 12 additions & 0 deletions api/v1beta1/novacompute_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
)

// NovaComputeDefaults -
Expand Down Expand Up @@ -216,3 +217,14 @@ func ValidateNovaComputeCell0(basePath *field.Path, mapLength int) field.ErrorLi
}
return errors
}

func (r *NovaComputeTemplate) ValidateComputeTopology(
basePath *field.Path,
namespace string,
) *field.Error {
if err := topologyv1.ValidateTopologyNamespace(
r.TopologyRef.Namespace, *basePath, namespace); err != nil {
return err
}
return nil
}
17 changes: 16 additions & 1 deletion api/v1beta1/novaconductor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type NovaConductorStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// LastAppliedTopology - the last applied Topology
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
LastAppliedTopology *topologyv1.TopoRef `json:"lastAppliedTopology,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -258,3 +258,18 @@ func (n NovaConductor) GetKeystoneUser() string {
func (n NovaConductor) GetCABundleSecretName() string {
return n.Spec.TLS.CaBundleSecretName
}

// GetSpecTopologyRef - Returns the LastAppliedTopology Set in the Status
func (instance *NovaConductor) GetSpecTopologyRef() *topologyv1.TopoRef {
return instance.Spec.TopologyRef
}

// GetLastAppliedTopology - Returns the LastAppliedTopology Set in the Status
func (instance *NovaConductor) GetLastAppliedTopology() *topologyv1.TopoRef {
return instance.Status.LastAppliedTopology
}

// SetLastAppliedTopology - Sets the LastAppliedTopology value in the Status
func (instance *NovaConductor) SetLastAppliedTopology(topologyRef *topologyv1.TopoRef) {
instance.Status.LastAppliedTopology = topologyRef
}
17 changes: 16 additions & 1 deletion api/v1beta1/novametadata_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type NovaMetadataStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// LastAppliedTopology - the last applied Topology
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
LastAppliedTopology *topologyv1.TopoRef `json:"lastAppliedTopology,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -299,3 +299,18 @@ func NewNovaMetadataSpec(
func (n NovaMetadata) GetSecret() string {
return n.Spec.Secret
}

// GetSpecTopologyRef - Returns the LastAppliedTopology Set in the Status
func (instance *NovaMetadata) GetSpecTopologyRef() *topologyv1.TopoRef {
return instance.Spec.TopologyRef
}

// GetLastAppliedTopology - Returns the LastAppliedTopology Set in the Status
func (instance *NovaMetadata) GetLastAppliedTopology() *topologyv1.TopoRef {
return instance.Status.LastAppliedTopology
}

// SetLastAppliedTopology - Sets the LastAppliedTopology value in the Status
func (instance *NovaMetadata) SetLastAppliedTopology(topologyRef *topologyv1.TopoRef) {
instance.Status.LastAppliedTopology = topologyRef
}
12 changes: 12 additions & 0 deletions api/v1beta1/novametadata_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
)

// NovaMetadataDefaults -
Expand Down Expand Up @@ -158,3 +159,14 @@ func ValidateMetadataDefaultConfigOverwrite(
return ValidateDefaultConfigOverwrite(
basePath, defaultConfigOverwrite, []string{"api-paste.ini"})
}

func (r *NovaMetadataTemplate) ValidateMetadataTopology(
basePath *field.Path,
namespace string,
) *field.Error {
if err := topologyv1.ValidateTopologyNamespace(
r.TopologyRef.Namespace, *basePath, namespace); err != nil {
return err
}
return nil
}
Loading

0 comments on commit ad1bcb6

Please sign in to comment.