Skip to content

Commit 3f48774

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 3f48774

29 files changed

+595
-11
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: 9 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
@@ -929,6 +936,8 @@ spec:
929936
additionalProperties:
930937
type: string
931938
type: object
939+
lastAppliedTopology:
940+
type: string
932941
observedGeneration:
933942
format: int64
934943
type: integer

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/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: 58 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"
@@ -156,6 +157,8 @@ func (r *Cinder) ValidateCreate() (admission.Warnings, error) {
156157
GetCrMaxLengthCorrection(r.Name)) // omit issue with statefulset pod label "controller-revision-hash": "<statefulset_name>-<hash>"
157158
allErrs = append(allErrs, err...)
158159

160+
allErrs = r.Spec.ValidateCinderTopology(basePath, r.Namespace)
161+
159162
if err := r.Spec.ValidateCreate(basePath); err != nil {
160163
allErrs = append(allErrs, err...)
161164
}
@@ -222,6 +225,8 @@ func (r *Cinder) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
222225
GetCrMaxLengthCorrection(r.Name)) // omit issue with statefulset pod label "controller-revision-hash": "<statefulset_name>-<hash>"
223226
allErrs = append(allErrs, err...)
224227

228+
allErrs = r.Spec.ValidateCinderTopology(basePath, r.Namespace)
229+
225230
if err := r.Spec.ValidateUpdate(oldCinder.Spec, basePath); err != nil {
226231
allErrs = append(allErrs, err...)
227232
}
@@ -305,3 +310,56 @@ 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 an instance of
355+
// CinderBackup, fail if a different Namespace is referenced because not
356+
// supported
357+
for _, ms := range spec.CinderBackup {
358+
if ms.TopologyRef != nil {
359+
if err := topologyv1.ValidateTopologyNamespace(ms.TopologyRef.Namespace, *basePath, namespace); err != nil {
360+
allErrs = append(allErrs, err)
361+
}
362+
}
363+
}
364+
return allErrs
365+
}

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

api/v1beta1/zz_generated.deepcopy.go

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

config/crd/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:

config/crd/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:

0 commit comments

Comments
 (0)