Skip to content

Commit a73e6c1

Browse files
Merge pull request #1316 from fmount/toporef
Consume a top-level TopologyRef
2 parents 3adcc28 + 3a6a7dd commit a73e6c1

32 files changed

Lines changed: 355 additions & 1 deletion

apis/bases/core.openstack.org_openstackcontrolplanes.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17418,6 +17418,13 @@ spec:
1741817418
type: object
1741917419
type: object
1742017420
type: object
17421+
topologyRef:
17422+
properties:
17423+
name:
17424+
type: string
17425+
namespace:
17426+
type: string
17427+
type: object
1742117428
required:
1742217429
- secret
1742317430
- storageClass

apis/core/v1beta1/openstackcontrolplane_types.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646
swiftv1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
4747
telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
4848
rabbitmqv2 "github.com/rabbitmq/cluster-operator/v2/api/v1beta1"
49-
49+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
5050
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5151
)
5252

@@ -211,6 +211,11 @@ type OpenStackControlPlaneSpec struct {
211211
// template Section, the globally defined ExtraMounts are ignored and
212212
// overridden for the operator which has this section already.
213213
ExtraMounts []OpenStackExtraVolMounts `json:"extraMounts,omitempty"`
214+
215+
// +kubebuilder:validation:Optional
216+
// TopologyRef to apply the Topology defined by the associated CR referenced
217+
// by name
218+
TopologyRef *topologyv1.TopoRef `json:"topologyRef,omitempty"`
214219
}
215220

216221
// TLSSection defines the desired state of TLS configuration
@@ -927,6 +932,11 @@ func (instance *OpenStackControlPlane) InitConditions() {
927932
// Also add the overall status condition as Unknown
928933
condition.UnknownCondition(condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage),
929934
)
935+
// Init Topology condition if there's a reference
936+
if instance.Spec.TopologyRef != nil {
937+
c := condition.UnknownCondition(condition.TopologyReadyCondition, condition.InitReason, condition.TopologyReadyInitMessage)
938+
cl.Set(c)
939+
}
930940
// initialize conditions used later as Status=Unknown
931941
instance.Status.Conditions.Init(&cl)
932942
}

apis/core/v1beta1/openstackcontrolplane_webhook.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
octaviav1 "github.com/openstack-k8s-operators/octavia-operator/api/v1beta1"
5656
swiftv1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
5757
telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
58+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
5859
)
5960

6061
var ctlplaneWebhookClient client.Client
@@ -117,6 +118,11 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
117118
}
118119

119120
allWarn, allErrs = r.ValidateCreateServices(basePath)
121+
122+
if err := r.ValidateTopology(basePath); err != nil {
123+
allErrs = append(allErrs, err)
124+
}
125+
120126
if len(allErrs) != 0 {
121127
return allWarn, apierrors.NewInvalid(
122128
schema.GroupKind{Group: "core.openstack.org", Kind: "OpenStackControlPlane"},
@@ -141,6 +147,10 @@ func (r *OpenStackControlPlane) ValidateUpdate(old runtime.Object) (admission.Wa
141147
allErrs = append(allErrs, err...)
142148
}
143149

150+
if err := r.ValidateTopology(basePath); err != nil {
151+
allErrs = append(allErrs, err)
152+
}
153+
144154
if len(allErrs) != 0 {
145155
return nil, apierrors.NewInvalid(
146156
schema.GroupKind{Group: "core.openstack.org", Kind: "OpenStackControlPlane"},
@@ -971,3 +981,14 @@ func validateTLSOverrideSpec(override **route.OverrideSpec, basePath *field.Path
971981

972982
return allErrs
973983
}
984+
985+
func (r *OpenStackControlPlane) ValidateTopology(basePath *field.Path) *field.Error {
986+
// When a TopologyRef CR is referenced, fail if a different Namespace is
987+
// referenced because is not supported
988+
if r.Spec.TopologyRef != nil {
989+
if err := topologyv1.ValidateTopologyNamespace(r.Spec.TopologyRef.Namespace, *basePath, r.Namespace); err != nil {
990+
return err
991+
}
992+
}
993+
return nil
994+
}

apis/core/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.

bindata/crds/crds.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17582,6 +17582,13 @@ spec:
1758217582
type: object
1758317583
type: object
1758417584
type: object
17585+
topologyRef:
17586+
properties:
17587+
name:
17588+
type: string
17589+
namespace:
17590+
type: string
17591+
type: object
1758517592
required:
1758617593
- secret
1758717594
- storageClass

bindata/rbac/rbac.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,15 @@ rules:
871871
- patch
872872
- update
873873
- watch
874+
- apiGroups:
875+
- topology.openstack.org
876+
resources:
877+
- topologies
878+
verbs:
879+
- get
880+
- list
881+
- update
882+
- watch
874883
---
875884
apiVersion: rbac.authorization.k8s.io/v1
876885
kind: ClusterRole

config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17418,6 +17418,13 @@ spec:
1741817418
type: object
1741917419
type: object
1742017420
type: object
17421+
topologyRef:
17422+
properties:
17423+
name:
17424+
type: string
17425+
namespace:
17426+
type: string
17427+
type: object
1742117428
required:
1742217429
- secret
1742317430
- storageClass

config/rbac/role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,12 @@ rules:
828828
- patch
829829
- update
830830
- watch
831+
- apiGroups:
832+
- topology.openstack.org
833+
resources:
834+
- topologies
835+
verbs:
836+
- get
837+
- list
838+
- update
839+
- watch

controllers/core/openstackcontrolplane_controller.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import (
3232
ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1"
3333
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
3434
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
35+
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
3536
common_helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
3637
corev1 "k8s.io/api/core/v1"
3738

3839
designatev1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1"
40+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
3941
manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1"
4042
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
4143
neutronv1 "github.com/openstack-k8s-operators/neutron-operator/api/v1beta1"
@@ -115,6 +117,7 @@ func (r *OpenStackControlPlaneReconciler) GetLogger(ctx context.Context) logr.Lo
115117
// +kubebuilder:rbac:groups=cert-manager.io,resources=issuers,verbs=get;list;watch;create;update;patch;delete;
116118
// +kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete;
117119
// +kubebuilder:rbac:groups=config.openshift.io,resources=networks,verbs=get;list;watch;
120+
// +kubebuilder:rbac:groups=topology.openstack.org,resources=topologies,verbs=get;list;watch;update
118121

119122
// Reconcile is part of the main kubernetes reconciliation loop which aims to
120123
// move the current state of the cluster closer to the desired state.
@@ -285,6 +288,21 @@ func (r *OpenStackControlPlaneReconciler) reconcileOVNControllers(ctx context.Co
285288
}
286289

287290
func (r *OpenStackControlPlaneReconciler) reconcileNormal(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *common_helper.Helper) (ctrl.Result, error) {
291+
if instance.Spec.TopologyRef != nil {
292+
if err := r.checkTopologyRef(ctx, helper,
293+
instance.Spec.TopologyRef, instance.Namespace); err != nil {
294+
instance.Status.Conditions.Set(condition.FalseCondition(
295+
condition.TopologyReadyCondition,
296+
condition.ErrorReason,
297+
condition.SeverityWarning,
298+
condition.TopologyReadyErrorMessage,
299+
err.Error()))
300+
return ctrl.Result{}, fmt.Errorf("waiting for Topology requirements: %w", err)
301+
}
302+
// TopologyRef != nil and exists and we're able to get it
303+
instance.Status.Conditions.MarkTrue(condition.TopologyReadyCondition, condition.TopologyReadyMessage)
304+
}
305+
288306
ctrlResult, err := openstack.ReconcileCAs(ctx, instance, helper)
289307
if err != nil {
290308
return ctrl.Result{}, err
@@ -637,3 +655,25 @@ func (r *OpenStackControlPlaneReconciler) findObjectsForSrc(ctx context.Context,
637655

638656
return requests
639657
}
658+
659+
// Verify the referenced topology exists
660+
func (r *OpenStackControlPlaneReconciler) checkTopologyRef(
661+
ctx context.Context,
662+
h *helper.Helper,
663+
topologyRef *topologyv1.TopoRef,
664+
namespace string,
665+
) error {
666+
if topologyRef.Namespace == "" {
667+
topologyRef.Namespace = namespace
668+
}
669+
_, _, err := topologyv1.GetTopologyByName(
670+
ctx,
671+
h,
672+
topologyRef.Name,
673+
topologyRef.Namespace,
674+
)
675+
if err != nil {
676+
return err
677+
}
678+
return nil
679+
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
networkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
4242
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
4343
redisv1 "github.com/openstack-k8s-operators/infra-operator/apis/redis/v1beta1"
44+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
4445
ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1"
4546
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
4647
manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1"
@@ -129,6 +130,7 @@ func init() {
129130
utilruntime.Must(machineconfig.AddToScheme(scheme))
130131
utilruntime.Must(k8s_networkv1.AddToScheme(scheme))
131132
utilruntime.Must(operatorv1beta1.AddToScheme(scheme))
133+
utilruntime.Must(topologyv1.AddToScheme(scheme))
132134
// +kubebuilder:scaffold:scheme
133135
}
134136

0 commit comments

Comments
 (0)