Skip to content

Commit b977c06

Browse files
committed
Consume Topology CR by reference
Allow Pod placement and scheduling to be made through the Topology CR integration introduced in [1]. - a new API parameter (TopologyRef) defined for each Component that allows to reference an existing Topology CRs in the same namespace - the operator logic that retrieves and processes the referenced Topology CR through the functions provided by lib-common [2] - StatefulSet configuration incorporates the processed Topology - a set of envTest to test the lifecycle (add/update/override/remove) of the resulting StatefulSets when a Topology is referenced webhooks are in place to prevent referencing a Topology from a different namespace (which is not supported). This patch is based on [3] by [email protected] [1] openstack-k8s-operators/infra-operator#325 [2] openstack-k8s-operators/lib-common#594 [3] openstack-k8s-operators/manila-operator#385 Jira: https://issues.redhat.com/browse/OSPRH-13274 Signed-off-by: John Fulton <[email protected]>
1 parent fa5a7a5 commit b977c06

38 files changed

+1025
-52
lines changed

api/bases/cinder.openstack.org_cinderapis.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,13 @@ spec:
663663
caBundleSecretName:
664664
type: string
665665
type: object
666+
topologyRef:
667+
properties:
668+
name:
669+
type: string
670+
namespace:
671+
type: string
672+
type: object
666673
transportURLSecret:
667674
type: string
668675
required:
@@ -706,6 +713,8 @@ spec:
706713
additionalProperties:
707714
type: string
708715
type: object
716+
lastAppliedTopology:
717+
type: string
709718
networkAttachments:
710719
additionalProperties:
711720
items:

api/bases/cinder.openstack.org_cinderbackups.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ spec:
599599
caBundleSecretName:
600600
type: string
601601
type: object
602+
topologyRef:
603+
properties:
604+
name:
605+
type: string
606+
namespace:
607+
type: string
608+
type: object
602609
transportURLSecret:
603610
type: string
604611
required:
@@ -636,6 +643,8 @@ spec:
636643
additionalProperties:
637644
type: string
638645
type: object
646+
lastAppliedTopology:
647+
type: string
639648
networkAttachments:
640649
additionalProperties:
641650
items:

api/bases/cinder.openstack.org_cinders.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ spec:
162162
caBundleSecretName:
163163
type: string
164164
type: object
165+
topologyRef:
166+
properties:
167+
name:
168+
type: string
169+
namespace:
170+
type: string
171+
type: object
165172
required:
166173
- containerImage
167174
type: object
@@ -219,6 +226,13 @@ spec:
219226
x-kubernetes-int-or-string: true
220227
type: object
221228
type: object
229+
topologyRef:
230+
properties:
231+
name:
232+
type: string
233+
namespace:
234+
type: string
235+
type: object
222236
required:
223237
- containerImage
224238
type: object
@@ -276,6 +290,13 @@ spec:
276290
x-kubernetes-int-or-string: true
277291
type: object
278292
type: object
293+
topologyRef:
294+
properties:
295+
name:
296+
type: string
297+
namespace:
298+
type: string
299+
type: object
279300
required:
280301
- containerImage
281302
type: object
@@ -335,6 +356,13 @@ spec:
335356
x-kubernetes-int-or-string: true
336357
type: object
337358
type: object
359+
topologyRef:
360+
properties:
361+
name:
362+
type: string
363+
namespace:
364+
type: string
365+
type: object
338366
required:
339367
- containerImage
340368
type: object
@@ -865,6 +893,13 @@ spec:
865893
serviceUser:
866894
default: cinder
867895
type: string
896+
topologyRef:
897+
properties:
898+
name:
899+
type: string
900+
namespace:
901+
type: string
902+
type: object
868903
required:
869904
- cinderAPI
870905
- cinderScheduler

api/bases/cinder.openstack.org_cinderschedulers.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ spec:
599599
caBundleSecretName:
600600
type: string
601601
type: object
602+
topologyRef:
603+
properties:
604+
name:
605+
type: string
606+
namespace:
607+
type: string
608+
type: object
602609
transportURLSecret:
603610
type: string
604611
required:
@@ -636,6 +643,8 @@ spec:
636643
additionalProperties:
637644
type: string
638645
type: object
646+
lastAppliedTopology:
647+
type: string
639648
networkAttachments:
640649
additionalProperties:
641650
items:

api/bases/cinder.openstack.org_cindervolumes.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ spec:
600600
caBundleSecretName:
601601
type: string
602602
type: object
603+
topologyRef:
604+
properties:
605+
name:
606+
type: string
607+
namespace:
608+
type: string
609+
type: object
603610
transportURLSecret:
604611
type: string
605612
required:
@@ -637,6 +644,8 @@ spec:
637644
additionalProperties:
638645
type: string
639646
type: object
647+
lastAppliedTopology:
648+
type: string
640649
networkAttachments:
641650
additionalProperties:
642651
items:

api/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module github.com/openstack-k8s-operators/cinder-operator/api
33
go 1.21
44

55
require (
6-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e
6+
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250210183624-a8bf66784d6d
7+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250205143454-43504d7ad19a
78
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e
89
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
9-
k8s.io/api v0.29.10
10-
k8s.io/apimachinery v0.29.10
10+
k8s.io/api v0.29.13
11+
k8s.io/apimachinery v0.29.13
1112
sigs.k8s.io/controller-runtime v0.17.6
1213
)
1314

@@ -16,7 +17,6 @@ require (
1617
github.com/cespare/xxhash/v2 v2.2.0 // indirect
1718
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1819
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
19-
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
2020
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
2121
github.com/fsnotify/fsnotify v1.7.0 // indirect
2222
github.com/go-logr/logr v1.4.2 // indirect
@@ -55,9 +55,9 @@ require (
5555
gopkg.in/inf.v0 v0.9.1 // indirect
5656
gopkg.in/yaml.v2 v2.4.0 // indirect
5757
gopkg.in/yaml.v3 v3.0.1 // indirect
58-
k8s.io/apiextensions-apiserver v0.29.10 // indirect
59-
k8s.io/client-go v0.29.10 // indirect
60-
k8s.io/component-base v0.29.10 // indirect
58+
k8s.io/apiextensions-apiserver v0.29.13 // indirect
59+
k8s.io/client-go v0.29.13 // indirect
60+
k8s.io/component-base v0.29.13 // indirect
6161
k8s.io/klog/v2 v2.120.1 // indirect
6262
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect
6363
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect

api/go.sum

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
7373
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
7474
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7575
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
76-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e h1:hf4kVQBkyG79WcHBxdQ25QrDBbGFdarebS1Tc0Xclq4=
77-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
76+
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250210183624-a8bf66784d6d h1:JuIcZjfFUH9G68MR9F62xBK4eS5F2P5nKVCoDXFrvQM=
77+
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250210183624-a8bf66784d6d/go.mod h1:kkjcOSZ7jkHbVzxJd0nDQzjB+vqafuAMgSf7AnEXydw=
78+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250205143454-43504d7ad19a h1:3LuUgB85VxGD6lmVOeZelYEASmytkrzaudU014PN7xw=
79+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250205143454-43504d7ad19a/go.mod h1:KxnNSUk15llkKTSq/bQEE7pnc0IMk44fxhoBRpimMa8=
7880
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=
7981
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w=
8082
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -179,16 +181,16 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
179181
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
180182
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
181183
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
182-
k8s.io/api v0.29.10 h1:Fao3HOxccbGRC1HZtXD+Y41xJhP0tEToVo5W7EEUBm0=
183-
k8s.io/api v0.29.10/go.mod h1:rF0sRh64w1hMNAVGh4YYniSxODyHye3GLmymAbWBDvY=
184-
k8s.io/apiextensions-apiserver v0.29.10 h1:2k2AHrWgs4S+07HrOjEdcyrQ/UqYlvBi6uon1fox1KE=
185-
k8s.io/apiextensions-apiserver v0.29.10/go.mod h1:3rrJC52bW5frHf10N3JvaDpl++hgrzD9Gs6IZpKWMoc=
186-
k8s.io/apimachinery v0.29.10 h1:57OLNqOJUgp5KlRRY3JOBFOTTa5Rt/LVkmKiiN2cvaQ=
187-
k8s.io/apimachinery v0.29.10/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
188-
k8s.io/client-go v0.29.10 h1:hPmG1pmKslRhmCIzVd90sA58B0sJwNwduNgXFWsFqhI=
189-
k8s.io/client-go v0.29.10/go.mod h1:gnMCQiRXGL9K0VtlW8gTkhzptGrHm2BJ4qBbujNemc4=
190-
k8s.io/component-base v0.29.10 h1:YQrQ/bpzGPGqIPEPaBzxjH0/1DJOI+yZPZNbbz7ZCBY=
191-
k8s.io/component-base v0.29.10/go.mod h1:IbwsBob2DnYiAONsSHIuYenchqcDycbHSLHrXshuLgM=
184+
k8s.io/api v0.29.13 h1:VkMIbjJw1t2VgTatg8ggzI93LOfFa8z8SzAYzXtWuEg=
185+
k8s.io/api v0.29.13/go.mod h1:fBWhXqqE25b46PZEVA2DXN2EuhNg1ZT3VRyb5JitLG8=
186+
k8s.io/apiextensions-apiserver v0.29.13 h1:3xsTohNwndx4NJjgqoi5VuBPWeG4yY4VXOF62ugXvhU=
187+
k8s.io/apiextensions-apiserver v0.29.13/go.mod h1:plxNh3qMNsiMo4svQtkVp47n+2/rwm/c8FTJYR6rikQ=
188+
k8s.io/apimachinery v0.29.13 h1:a7I4uQtlfaL+UTRGFhl8lLd2nHBR7qt+axhQLtpLYMg=
189+
k8s.io/apimachinery v0.29.13/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
190+
k8s.io/client-go v0.29.13 h1:M2scR9NWGlzI2YoIxTgwx2N3OA+dXqN87zsM4tvewmA=
191+
k8s.io/client-go v0.29.13/go.mod h1:BBzF0Pr78Y8DM20j22E6tOMwTBpFaKnSnn6N0pNe4VE=
192+
k8s.io/component-base v0.29.13 h1:RbksXVzXYYYvmOCArMKIkxna5eTt6DjI4Zy/4H3JFLo=
193+
k8s.io/component-base v0.29.13/go.mod h1:pjMLwLNxDg0JvXRc69GIFUEawiZEtDzm0yAJ5+Naj9s=
192194
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
193195
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
194196
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 h1:qVoMaQV5t62UUvHe16Q3eb2c5HPzLHYzsi0Tu/xLndo=

api/v1beta1/cinder_types.go

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

@@ -104,6 +105,11 @@ type CinderSpecBase struct {
104105
// +kubebuilder:validation:Minimum=10
105106
// APITimeout for HAProxy, Apache, and rpc_response_timeout
106107
APITimeout int `json:"apiTimeout"`
108+
109+
// +kubebuilder:validation:Optional
110+
// TopologyRef to apply the Topology defined by the associated CR referenced
111+
// by name
112+
TopologyRef *topologyv1.TopoRef `json:"topologyRef,omitempty"`
107113
}
108114

109115
// CinderSpecCore the same as CinderSpec without ContainerImage references

api/v1beta1/cinder_webhook.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
3030
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
31+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
3132
apierrors "k8s.io/apimachinery/pkg/api/errors"
3233
"k8s.io/apimachinery/pkg/runtime"
3334
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -139,6 +140,8 @@ func (r *Cinder) ValidateCreate() (admission.Warnings, error) {
139140
var allErrs field.ErrorList
140141
basePath := field.NewPath("spec")
141142

143+
allErrs = r.Spec.ValidateCinderTopology(basePath, r.Namespace)
144+
142145
// Validate cinderVolume name is valid
143146
// CinderVolume name is <cinder name>-volume-<volume name>
144147
// The CinderVolume controller creates StatefulSet for volume service to run.
@@ -205,6 +208,8 @@ func (r *Cinder) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
205208
var allErrs field.ErrorList
206209
basePath := field.NewPath("spec")
207210

211+
allErrs = r.Spec.ValidateCinderTopology(basePath, r.Namespace)
212+
208213
// Validate cinderVolume name is valid
209214
// CinderVolume name is <cinder name>-volume-<volume name>
210215
// The CinderVolume controller creates StatefulSet for volume service to run.
@@ -305,3 +310,54 @@ func GetCrMaxLengthCorrection(name string) int {
305310

306311
return (defaultCrMaxLengthCorrection + len(name) + 8)
307312
}
313+
314+
// ValidateCinderTopology - Returns an ErrorList if the Topology is referenced
315+
// on a different namespace
316+
func (spec *CinderSpec) ValidateCinderTopology(basePath *field.Path, namespace string) field.ErrorList {
317+
var allErrs field.ErrorList
318+
319+
// When a TopologyRef CR is referenced, fail if a different Namespace is
320+
// referenced because is not supported
321+
if spec.TopologyRef != nil {
322+
if err := topologyv1.ValidateTopologyNamespace(spec.TopologyRef.Namespace, *basePath, namespace); err != nil {
323+
allErrs = append(allErrs, err)
324+
}
325+
}
326+
327+
// When a TopologyRef CR is referenced with an override to CinderAPI, fail
328+
// if a different Namespace is referenced because not supported
329+
if spec.CinderAPI.TopologyRef != nil {
330+
if err := topologyv1.ValidateTopologyNamespace(spec.CinderAPI.TopologyRef.Namespace, *basePath, namespace); err != nil {
331+
allErrs = append(allErrs, err)
332+
}
333+
}
334+
335+
// When a TopologyRef CR is referenced with an override to CinderScheduler,
336+
// fail if a different Namespace is referenced because not supported
337+
if spec.CinderScheduler.TopologyRef != nil {
338+
if err := topologyv1.ValidateTopologyNamespace(spec.CinderScheduler.TopologyRef.Namespace, *basePath, namespace); err != nil {
339+
allErrs = append(allErrs, err)
340+
}
341+
}
342+
343+
// When a TopologyRef CR is referenced with an override to an instance of
344+
// CinderVolumes, fail if a different Namespace is referenced because not
345+
// supported
346+
for _, ms := range spec.CinderVolumes {
347+
if ms.TopologyRef != nil {
348+
if err := topologyv1.ValidateTopologyNamespace(ms.TopologyRef.Namespace, *basePath, namespace); err != nil {
349+
allErrs = append(allErrs, err)
350+
}
351+
}
352+
}
353+
354+
// When a TopologyRef CR is referenced with an override to CinderBackup, fail
355+
// if a different Namespace is referenced because not supported
356+
if spec.CinderBackup.TopologyRef != nil {
357+
if err := topologyv1.ValidateTopologyNamespace(spec.CinderBackup.TopologyRef.Namespace, *basePath, namespace); err != nil {
358+
allErrs = append(allErrs, err)
359+
}
360+
}
361+
362+
return allErrs
363+
}

api/v1beta1/cinderapi_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ type CinderAPIStatus struct {
112112
// controller has not started processing the latest changes, and the status
113113
// and its conditions are likely stale.
114114
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
115+
116+
// LastAppliedTopology - the last applied Topology
117+
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
115118
}
116119

117120
//+kubebuilder:object:root=true

api/v1beta1/cinderbackup_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ type CinderBackupStatus struct {
9494
// controller has not started processing the latest changes, and the status
9595
// and its conditions are likely stale.
9696
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
97+
98+
// LastAppliedTopology - the last applied Topology
99+
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
97100
}
98101

99102
//+kubebuilder:object:root=true

api/v1beta1/cinderscheduler_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ type CinderSchedulerStatus struct {
9494
// controller has not started processing the latest changes, and the status
9595
// and its conditions are likely stale.
9696
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
97+
98+
// LastAppliedTopology - the last applied Topology
99+
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
97100
}
98101

99102
//+kubebuilder:object:root=true

api/v1beta1/cindervolume_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ type CinderVolumeStatus struct {
100100
// controller has not started processing the latest changes, and the status
101101
// and its conditions are likely stale.
102102
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
103+
104+
// LastAppliedTopology - the last applied Topology
105+
LastAppliedTopology string `json:"lastAppliedTopology,omitempty"`
103106
}
104107

105108
//+kubebuilder:object:root=true

api/v1beta1/common_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1beta1
1818

1919
import (
2020
corev1 "k8s.io/api/core/v1"
21+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2122
)
2223

2324
// CinderTemplate defines common input parameters used by all Cinder services
@@ -71,6 +72,11 @@ type CinderServiceTemplate struct {
7172
// +kubebuilder:validation:Optional
7273
// NetworkAttachments is a list of NetworkAttachment resource names to expose the services to the given network
7374
NetworkAttachments []string `json:"networkAttachments,omitempty"`
75+
76+
// +kubebuilder:validation:Optional
77+
// TopologyRef to apply the Topology defined by the associated CR referenced
78+
// by name
79+
TopologyRef *topologyv1.TopoRef `json:"topologyRef,omitempty"`
7480
}
7581

7682
// PasswordSelector to identify the DB and AdminUser password from the Secret

0 commit comments

Comments
 (0)