Skip to content

Commit faf88a7

Browse files
committed
Update glanceAPI controller to consume topology functions from lib-common
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 <[email protected]>
1 parent 105e69c commit faf88a7

10 files changed

+134
-166
lines changed

api/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ require (
7070
// mschuppert: map to latest commit from release-4.16 tag
7171
// must consistent within modules and service operators
7272
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging
73+
74+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20250121110137-f3ec1120ae76

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
1212
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
1313
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
1414
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
15+
github.com/fmount/lib-common/modules/common v0.0.0-20250121110137-f3ec1120ae76 h1:VgQX9qER2j01WQcm7eNEeKh5yCMTFnpNxk4J3ORcNL0=
16+
github.com/fmount/lib-common/modules/common v0.0.0-20250121110137-f3ec1120ae76/go.mod h1:u4alaJJ8JWGlQlUOCIOjmuZf6WknH5qc9Z1TXT2VHTQ=
1517
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1618
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
1719
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
@@ -77,8 +79,6 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
7779
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
7880
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250120135015-2a1b8e167212 h1:6CSlrFvo9sDtJowI/hB9ZYdqhZdmpz2Gzz4EaqtlNpM=
7981
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250120135015-2a1b8e167212/go.mod h1:TDaE7BVQvJwJGFm33R6xcPTeF8LKAnMh+a1ho+YqJHs=
80-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250120114122-4bcef17ff6fa h1:gzvO0w21wkyeex1UaD+AaYEuqEId/oYnARaxE4kATNc=
81-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250120114122-4bcef17ff6fa/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
8282
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=
8383
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w=
8484
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

api/v1beta1/common_types.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
2323
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2424
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
25+
"github.com/openstack-k8s-operators/lib-common/modules/common/topology"
2526
corev1 "k8s.io/api/core/v1"
2627
)
2728

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

6364
// +kubebuilder:validation:Optional
64-
// Topology to apply the Policy defined by the associated CR referenced by
65-
// name
66-
Topology *TopologyRef `json:"topologyRef,omitempty"`
65+
// TopologyRef to apply the Policy defined by the associated CR referenced
66+
// by name
67+
TopologyRef *topology.Topology `json:"topologyRef,omitempty"`
6768

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

116-
// TopologyRef -
117-
type TopologyRef struct {
118-
// +kubebuilder:validation:Optional
119-
// Name - The Topology CR name that Glance references
120-
Name string `json:"name"`
121-
122-
// +kubebuilder:validation:Optional
123-
// Namespace - The Namespace to fetch the Topology CR referenced
124-
// NOTE: Namespace currently points by default to the same namespace where
125-
// Glance is deployed. Customizing the namespace is not supported and
126-
// webhooks prevent editing this field to a value different from the
127-
// current project
128-
Namespace string `json:"namespace,omitempty"`
129-
}
130-
131117
// Storage -
132118
type Storage struct {
133119
// +kubebuilder:validation:Optional

api/v1beta1/glance_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2121
"github.com/openstack-k8s-operators/lib-common/modules/storage"
22+
"github.com/openstack-k8s-operators/lib-common/modules/common/topology"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
2425

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

7576
// +kubebuilder:validation:Optional
76-
// Topology to apply the Policy defined by the associated CR referenced by
77-
// name
78-
Topology *TopologyRef `json:"topologyRef,omitempty"`
77+
// TopologyRef to apply the Policy defined by the associated CR referenced
78+
// by name
79+
TopologyRef *topology.Topology `json:"topologyRef,omitempty"`
7980

8081
// +kubebuilder:validation:Optional
8182
// +kubebuilder:default=false

api/v1beta1/glance_webhook.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,16 @@ func (r *Glance) ValidateCreate() (admission.Warnings, error) {
219219
var allErrs field.ErrorList
220220
basePath := field.NewPath("spec")
221221

222-
// When a Topology CR is referenced, fail if a different Namespace is
222+
// When a TopologyRef CR is referenced, fail if a different Namespace is
223223
// referenced because is not supported
224-
if r.Spec.Topology != nil {
225-
if err := topologyv1.ValidateTopologyNamespace(r.Spec.Topology.Namespace, *basePath, r.Namespace); err != nil {
224+
if r.Spec.TopologyRef != nil {
225+
if err := topologyv1.ValidateTopologyNamespace(r.Spec.TopologyRef.Namespace, *basePath, r.Namespace); err != nil {
226226
allErrs = append(allErrs, err)
227227
}
228228
}
229229
for key, glanceAPI := range r.Spec.GlanceAPIs {
230-
if glanceAPI.Topology != nil {
231-
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.Topology.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
230+
if glanceAPI.TopologyRef != nil {
231+
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.TopologyRef.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
232232
allErrs = append(allErrs, err)
233233
}
234234
}
@@ -320,16 +320,16 @@ func (r *Glance) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
320320
var allErrs field.ErrorList
321321
basePath := field.NewPath("spec")
322322

323-
// When a Topology CR is referenced, fail if a different Namespace is
323+
// When a TopologyRef CR is referenced, fail if a different Namespace is
324324
// referenced because is not supported
325-
if r.Spec.Topology != nil {
326-
if err := topologyv1.ValidateTopologyNamespace(r.Spec.Topology.Namespace, *basePath, r.Namespace); err != nil {
325+
if r.Spec.TopologyRef != nil {
326+
if err := topologyv1.ValidateTopologyNamespace(r.Spec.TopologyRef.Namespace, *basePath, r.Namespace); err != nil {
327327
allErrs = append(allErrs, err)
328328
}
329329
}
330330
for key, glanceAPI := range r.Spec.GlanceAPIs {
331-
if glanceAPI.Topology != nil {
332-
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.Topology.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
331+
if glanceAPI.TopologyRef != nil {
332+
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.TopologyRef.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
333333
allErrs = append(allErrs, err)
334334
}
335335
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 7 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/glance_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ func (r *GlanceReconciler) apiDeploymentCreateOrUpdate(
869869

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

876876
// Add the API name to the GlanceAPI instance as a label

0 commit comments

Comments
 (0)