diff --git a/internal/controllers/import_controller.go b/internal/controllers/import_controller.go index fce4c171..3adcc798 100644 --- a/internal/controllers/import_controller.go +++ b/internal/controllers/import_controller.go @@ -46,6 +46,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/controllers/remote" + "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/predicates" utilyaml "sigs.k8s.io/cluster-api/util/yaml" @@ -166,8 +167,9 @@ func (r *CAPIImportReconciler) Reconcile(ctx context.Context, req ctrl.Request) log = log.WithValues("cluster", capiCluster.Name) - // Wait for controlplane to be ready - if !capiCluster.Status.ControlPlaneReady { + // Wait for controlplane to be ready. This should never be false as the predicates + // do the filtering. + if !capiCluster.Status.ControlPlaneReady && !conditions.IsTrue(capiCluster, clusterv1.ControlPlaneReadyCondition) { log.Info("clusters control plane is not ready, requeue") return ctrl.Result{RequeueAfter: defaultRequeueDuration}, nil } diff --git a/util/predicates/cluster_predicates.go b/util/predicates/cluster_predicates.go index 084495ac..ac1f761a 100644 --- a/util/predicates/cluster_predicates.go +++ b/util/predicates/cluster_predicates.go @@ -26,6 +26,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/util/conditions" "github.com/rancher-sandbox/rancher-turtles/util" "github.com/rancher-sandbox/rancher-turtles/util/annotations" @@ -95,14 +96,19 @@ func processIfClusterReadyControlPlane(logger logr.Logger, obj client.Object) bo return false } - if !cluster.Status.ControlPlaneReady { - log.V(4).Info("Cluster does not have a ready control plane, will not attempt to map resource") - return false + if cluster.Status.ControlPlaneReady { + log.V(6).Info("Cluster has a ready control plane, will attempt to map resource") + return true + } + + if conditions.IsTrue(cluster, clusterv1.ControlPlaneReadyCondition) { + log.V(6).Info("Cluster has a ready control plane condition, will attempt to map resource") + return true } - log.V(6).Info("Cluster has a ready control plane, will attempt to map resource") + log.V(4).Info("Cluster does not have a ready control plane, will not attempt to map resource") - return true + return false } // ClusterOrNamespaceWithImportLabel returns a predicate that returns true only if the provided resource is a cluster and