diff --git a/internal/controllers/import_controller.go b/internal/controllers/import_controller.go index 5d4280af..465f4f7f 100644 --- a/internal/controllers/import_controller.go +++ b/internal/controllers/import_controller.go @@ -43,6 +43,7 @@ import ( "sigs.k8s.io/cluster-api/util/predicates" "github.com/rancher/turtles/feature" + managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" "github.com/rancher/turtles/util" turtlesannotations "github.com/rancher/turtles/util/annotations" @@ -250,8 +251,8 @@ func (r *CAPIImportReconciler) reconcileNormal(ctx context.Context, capiCluster log.Info("found cluster name", "name", rancherCluster.Status.ClusterName) - if rancherCluster.Status.AgentDeployed { - log.Info("agent already deployed, no action needed") + if conditions.IsTrue(rancherCluster, managementv3.ClusterConditionReady) { + log.Info("agent is ready, no action needed") return ctrl.Result{}, nil } diff --git a/internal/controllers/import_controller_v3.go b/internal/controllers/import_controller_v3.go index 3fa92000..96a16d76 100644 --- a/internal/controllers/import_controller_v3.go +++ b/internal/controllers/import_controller_v3.go @@ -314,8 +314,8 @@ func (r *CAPIImportManagementV3Reconciler) reconcileNormal(ctx context.Context, log.Info("Successfully propagated labels to Rancher cluster") } - if conditions.IsTrue(rancherCluster, managementv3.ClusterConditionAgentDeployed) { - log.Info("agent already deployed, no action needed") + if conditions.IsTrue(rancherCluster, managementv3.ClusterConditionReady) { + log.Info("agent is ready, no action needed") return ctrl.Result{}, nil } diff --git a/internal/controllers/import_controller_v3_test.go b/internal/controllers/import_controller_v3_test.go index 53010ac0..5eca51b5 100644 --- a/internal/controllers/import_controller_v3_test.go +++ b/internal/controllers/import_controller_v3_test.go @@ -332,8 +332,8 @@ var _ = Describe("reconcile CAPI Cluster", func() { cluster := rancherClusters.Items[0] Expect(cluster.Name).To(ContainSubstring("c-")) - conditions.Set(&cluster, conditions.TrueCondition(managementv3.ClusterConditionAgentDeployed)) - Expect(conditions.IsTrue(&cluster, managementv3.ClusterConditionAgentDeployed)).To(BeTrue()) + conditions.Set(&cluster, conditions.TrueCondition(managementv3.ClusterConditionReady)) + Expect(conditions.IsTrue(&cluster, managementv3.ClusterConditionReady)).To(BeTrue()) Expect(cl.Status().Update(ctx, &cluster)).To(Succeed()) _, err := r.Reconcile(ctx, reconcile.Request{ @@ -477,8 +477,8 @@ var _ = Describe("reconcile CAPI Cluster", func() { Eventually(ctx, func(g Gomega) { g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(rancherCluster), rancherCluster)).To(Succeed()) - conditions.Set(rancherCluster, conditions.TrueCondition(managementv3.ClusterConditionAgentDeployed)) - g.Expect(conditions.IsTrue(rancherCluster, managementv3.ClusterConditionAgentDeployed)).To(BeTrue()) + conditions.Set(rancherCluster, conditions.TrueCondition(managementv3.ClusterConditionReady)) + g.Expect(conditions.IsTrue(rancherCluster, managementv3.ClusterConditionReady)).To(BeTrue()) g.Expect(cl.Status().Update(ctx, rancherCluster)).To(Succeed()) }).Should(Succeed()) diff --git a/internal/rancher/provisioning/v1/cluster.go b/internal/rancher/provisioning/v1/cluster.go index 5453b002..f229c08e 100644 --- a/internal/rancher/provisioning/v1/cluster.go +++ b/internal/rancher/provisioning/v1/cluster.go @@ -18,6 +18,8 @@ package v1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) // Cluster is the struct representing a Rancher Cluster. @@ -41,6 +43,8 @@ type ClusterStatus struct { ClusterName string `json:"clusterName,omitempty"` AgentDeployed bool `json:"agentDeployed,omitempty"` Ready bool `json:"ready,omitempty"` + + Conditions clusterv1.Conditions `json:"conditions,omitempty"` } // ClusterList contains a list of ClusterList. @@ -51,6 +55,16 @@ type ClusterList struct { Items []Cluster `json:"items"` } +// GetConditions method to implement capi conditions getter interface. +func (c *Cluster) GetConditions() clusterv1.Conditions { + return c.Status.Conditions +} + +// SetConditions method to implement capi conditions setter interface. +func (c *Cluster) SetConditions(conditions clusterv1.Conditions) { + c.Status.Conditions = conditions +} + func init() { SchemeBuilder.Register(&Cluster{}, &ClusterList{}) }