Skip to content

Commit

Permalink
fix: check condition for controlplane ready
Browse files Browse the repository at this point in the history
Whilst testing ClusterClass it was noticed that the
status.controlplaneready field isn't being set to true. However, the
condition isn't being set to true.

This change will check both the status field and the condition. If
either are true then we will reconcile the CAPI cluster.

Signed-off-by: Richard Case <richard.case@suse.com>
  • Loading branch information
richardcase committed Oct 25, 2023
1 parent a06f1d6 commit 7a35f5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions internal/controllers/import_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 11 additions & 5 deletions util/predicates/cluster_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7a35f5f

Please sign in to comment.