Skip to content

Commit

Permalink
Check agent deployment based on ready state
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Jul 8, 2024
1 parent b37d451 commit c91f099
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 3 additions & 2 deletions internal/controllers/import_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/import_controller_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/import_controller_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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())

Expand Down
14 changes: 14 additions & 0 deletions internal/rancher/provisioning/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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{})
}

0 comments on commit c91f099

Please sign in to comment.