Skip to content

Commit

Permalink
Wait for clusters to be marked as ready
Browse files Browse the repository at this point in the history
Previously, the remote assemblage controller was made to skip (and
come back to) a cluster when its kubeconfig secret is missing. This
accounts broadly for races in provisioning clusters, since ultimately
its the secret that matters.

However, with Cluster API providers its possible for a kubeconfig
secret to exist before the cluster is ready to be used. This situation
_also_ leads to long backoffs and apparent lack of responsiveness. To
mitigate that, this commit adds a similar mechanism to the above, at
another layer: clusters that are not marked as ready (in
`.status.controlPlaneReady`) are skipped. This is at the module (and
bootstrapmodule) level, because it's modules that react to clusters --
assemblages just refer to kubeconfig secrets.

Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
  • Loading branch information
squaremo committed Apr 13, 2022
1 parent 8e7416e commit 10e23fe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions module/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rules:
verbs:
- get
- list
- watch
- apiGroups:
- fleet.squaremo.dev
resources:
Expand Down
2 changes: 2 additions & 0 deletions module/controllers/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ var _ = Describe("bootstrap module controller", func() {
cluster.Namespace = namespace.Name
clusters[cluster.Name] = cluster
Expect(k8sClient.Create(context.TODO(), cluster)).To(Succeed())
cluster.Status.ControlPlaneReady = true
Expect(k8sClient.Status().Update(context.Background(), cluster)).To(Succeed())
}

})
Expand Down
7 changes: 7 additions & 0 deletions module/controllers/bootstrapmodule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ func (r *BootstrapModuleReconciler) Reconcile(ctx context.Context, req ctrl.Requ

clusters:
for _, cluster := range clusters.Items {
// Don't bother if the cluster isn't marked as ready yet. Creating an assemblage targeting
// an unready cluster means lots of failures and back-off.
if !cluster.Status.ControlPlaneReady {
// TODO: should this be a separate field in the summary, e.g., "waiting"?
log.Info("waiting for cluster to be ready", "name", cluster.GetName())
continue
}
summary.Total++
requiredAsm[cluster.GetName()] = struct{}{}

Expand Down
7 changes: 7 additions & 0 deletions module/controllers/module_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ func (r *ModuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

clusters:
for _, cluster := range clusters.Items {
// Don't bother if the cluster isn't marked as ready yet. Creating an assemblage targeting
// an unready cluster means lots of failures and back-off.
if !cluster.Status.ControlPlaneReady {
// TODO: should this be a separate field in the summary, e.g., "waiting"?
log.Info("waiting for cluster to be ready", "name", cluster.GetName())
continue
}
summary.Total++
// This loop makes sure every cluster that matches the
// selector has a remote assemblage with the latest definition
Expand Down
6 changes: 6 additions & 0 deletions module/controllers/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ var _ = Describe("modules", func() {
"environment": "production",
})
Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed())
cluster.Status.ControlPlaneReady = true
Expect(k8sClient.Status().Update(context.Background(), cluster)).To(Succeed())
}
})

Expand Down Expand Up @@ -177,6 +179,8 @@ var _ = Describe("modules", func() {
newCluster.Name = "newcluster"
newCluster.Namespace = namespace.Name
Expect(k8sClient.Create(context.TODO(), &newCluster)).To(Succeed())
newCluster.Status.ControlPlaneReady = true
Expect(k8sClient.Status().Update(context.Background(), &newCluster)).To(Succeed())

var newAsm fleetv1.ProxyAssemblage
Eventually(func() bool {
Expand Down Expand Up @@ -326,6 +330,8 @@ var _ = Describe("modules", func() {
cluster.Namespace = namespace.Name
cluster.Name = "clus-" + randString(5)
Expect(k8sClient.Create(context.TODO(), &cluster)).To(Succeed())
cluster.Status.ControlPlaneReady = true
Expect(k8sClient.Status().Update(context.Background(), &cluster)).To(Succeed())

module := fleetv1.Module{
Spec: fleetv1.ModuleSpec{
Expand Down

0 comments on commit 10e23fe

Please sign in to comment.