Skip to content

Commit

Permalink
Update glanceAPI controller to consume topology functions from lib-co…
Browse files Browse the repository at this point in the history
…mmon

This patch updates the glance-operator to consume a TopologyRef struct
and the related functions from lib-common [1]. This allows to avoid
code duplication while spreading the pattern across the board.

[1] openstack-k8s-operators/lib-common#594

Signed-off-by: Francesco Pantano <fpantano@redhat.com>
  • Loading branch information
fmount committed Jan 23, 2025
1 parent 105e69c commit b781ecc
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 166 deletions.
2 changes: 2 additions & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ require (
// mschuppert: map to latest commit from release-4.16 tag
// must consistent within modules and service operators
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging

replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20250123151610-bfe0d1005744
4 changes: 2 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fmount/lib-common/modules/common v0.0.0-20250123151610-bfe0d1005744 h1:SPYpBHHk9DGppkGF/YRR4V1elJuchyuR0hyrwzHinc4=
github.com/fmount/lib-common/modules/common v0.0.0-20250123151610-bfe0d1005744/go.mod h1:u4alaJJ8JWGlQlUOCIOjmuZf6WknH5qc9Z1TXT2VHTQ=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
Expand Down Expand Up @@ -77,8 +79,6 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250120135015-2a1b8e167212 h1:6CSlrFvo9sDtJowI/hB9ZYdqhZdmpz2Gzz4EaqtlNpM=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250120135015-2a1b8e167212/go.mod h1:TDaE7BVQvJwJGFm33R6xcPTeF8LKAnMh+a1ho+YqJHs=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250120114122-4bcef17ff6fa h1:gzvO0w21wkyeex1UaD+AaYEuqEId/oYnARaxE4kATNc=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250120114122-4bcef17ff6fa/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
22 changes: 4 additions & 18 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
"github.com/openstack-k8s-operators/lib-common/modules/common/topology"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -61,9 +62,9 @@ type GlanceAPITemplate struct {
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// Topology to apply the Policy defined by the associated CR referenced by
// name
Topology *TopologyRef `json:"topologyRef,omitempty"`
// TopologyRef to apply the Policy defined by the associated CR referenced
// by name
TopologyRef *topology.Ref `json:"topologyRef,omitempty"`

// +kubebuilder:validation:Optional
// CustomServiceConfig - customize the service config using this parameter to change service defaults,
Expand Down Expand Up @@ -113,21 +114,6 @@ type GlanceAPITemplate struct {
APITimeout int `json:"apiTimeout,omitempty"`
}

// TopologyRef -
type TopologyRef struct {
// +kubebuilder:validation:Optional
// Name - The Topology CR name that Glance references
Name string `json:"name"`

// +kubebuilder:validation:Optional
// Namespace - The Namespace to fetch the Topology CR referenced
// NOTE: Namespace currently points by default to the same namespace where
// Glance is deployed. Customizing the namespace is not supported and
// webhooks prevent editing this field to a value different from the
// current project
Namespace string `json:"namespace,omitempty"`
}

// Storage -
type Storage struct {
// +kubebuilder:validation:Optional
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/glance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/storage"
"github.com/openstack-k8s-operators/lib-common/modules/common/topology"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -73,9 +74,9 @@ type GlanceSpecCore struct {
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// Topology to apply the Policy defined by the associated CR referenced by
// name
Topology *TopologyRef `json:"topologyRef,omitempty"`
// TopologyRef to apply the Policy defined by the associated CR referenced
// by name
TopologyRef *topology.Ref `json:"topologyRef,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Expand Down
20 changes: 10 additions & 10 deletions api/v1beta1/glance_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ func (r *Glance) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList
basePath := field.NewPath("spec")

// When a Topology CR is referenced, fail if a different Namespace is
// When a TopologyRef CR is referenced, fail if a different Namespace is
// referenced because is not supported
if r.Spec.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.Topology.Namespace, *basePath, r.Namespace); err != nil {
if r.Spec.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.TopologyRef.Namespace, *basePath, r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
for key, glanceAPI := range r.Spec.GlanceAPIs {
if glanceAPI.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.Topology.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
if glanceAPI.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.TopologyRef.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
Expand Down Expand Up @@ -320,16 +320,16 @@ func (r *Glance) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
var allErrs field.ErrorList
basePath := field.NewPath("spec")

// When a Topology CR is referenced, fail if a different Namespace is
// When a TopologyRef CR is referenced, fail if a different Namespace is
// referenced because is not supported
if r.Spec.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.Topology.Namespace, *basePath, r.Namespace); err != nil {
if r.Spec.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.TopologyRef.Namespace, *basePath, r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
for key, glanceAPI := range r.Spec.GlanceAPIs {
if glanceAPI.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.Topology.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
if glanceAPI.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.TopologyRef.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
Expand Down
28 changes: 7 additions & 21 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 controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ func (r *GlanceReconciler) apiDeploymentCreateOrUpdate(

// If topology is not present in the underlying GlanceAPI,
// inherit from the top-level CR
if apiSpec.GlanceAPITemplate.Topology == nil {
apiSpec.GlanceAPITemplate.Topology = instance.Spec.Topology
if apiSpec.GlanceAPITemplate.TopologyRef == nil {
apiSpec.GlanceAPITemplate.TopologyRef = instance.Spec.TopologyRef
}

// Add the API name to the GlanceAPI instance as a label
Expand Down
Loading

0 comments on commit b781ecc

Please sign in to comment.