@@ -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
287290func (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+ }
0 commit comments