Skip to content

Commit 25c19b5

Browse files
committed
Don't error when the cluster-access secret is not available.
1 parent 834b16d commit 25c19b5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

controllers/clusterbootstrapconfig_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
corev1 "k8s.io/api/core/v1"
26+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/labels"
2829
"k8s.io/apimachinery/pkg/runtime"
@@ -55,7 +56,7 @@ func NewClusterBootstrapConfigReconciler(c client.Client, s *runtime.Scheme) *Cl
5556
}
5657

5758
// TODO: make this configurable on the Spec
58-
var requeueAfterTime = time.Minute * 2
59+
var requeueAfterTime = time.Second * 32
5960

6061
//+kubebuilder:rbac:groups=capi.weave.works,resources=clusterbootstrapconfigs,verbs=get;list;watch;create;update;patch;delete
6162
//+kubebuilder:rbac:groups=capi.weave.works,resources=clusterbootstrapconfigs/status,verbs=get;update;patch
@@ -88,6 +89,11 @@ func (r *ClusterBootstrapConfigReconciler) Reconcile(ctx context.Context, req ct
8889
clusterName := types.NamespacedName{Name: c.GetName(), Namespace: c.GetNamespace()}
8990
clusterClient, err := r.clientForCluster(ctx, clusterName)
9091
if err != nil {
92+
if apierrors.IsNotFound(err) {
93+
logger.Info("waiting for cluster access secret to be available")
94+
return ctrl.Result{RequeueAfter: requeueAfterTime}, nil
95+
}
96+
9197
return ctrl.Result{}, fmt.Errorf("failed to create client for cluster %s: %w", clusterName, err)
9298
}
9399

@@ -97,6 +103,7 @@ func (r *ClusterBootstrapConfigReconciler) Reconcile(ctx context.Context, req ct
97103
}
98104
if !ready {
99105
logger.Info("waiting for control plane to be ready", "cluster", clusterName)
106+
100107
return ctrl.Result{RequeueAfter: time.Minute * 2}, nil
101108
}
102109
}

controllers/clusterbootstrapconfig_controller_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,35 @@ func TestReconcile_when_cluster_not_ready(t *testing.T) {
5858
if l := len(jobs.Items); l != 0 {
5959
t.Fatalf("found %d jobs, want %d", l, 0)
6060
}
61+
}
62+
63+
func TestReconcile_when_cluster_secret_not_available(t *testing.T) {
64+
bc := makeTestClusterBootstrapConfig(func(c *capiv1alpha1.ClusterBootstrapConfig) {
65+
c.Spec.RequireClusterReady = true
66+
})
67+
cl := makeTestCluster(func(c *clusterv1.Cluster) {
68+
c.ObjectMeta.Labels = bc.Spec.ClusterSelector.MatchLabels
69+
c.Status.Phase = string(clusterv1.ClusterPhaseProvisioned)
70+
})
71+
reconciler := makeTestReconciler(t, bc, cl)
72+
73+
// This cheats by using the test client as the remote client to simplify
74+
// getting the value from the remote client.
75+
reconciler.configParser = func(b []byte) (client.Client, error) {
76+
return reconciler.Client, nil
77+
}
6178

79+
result, err := reconciler.Reconcile(context.TODO(), ctrl.Request{NamespacedName: types.NamespacedName{
80+
Name: bc.GetName(),
81+
Namespace: bc.GetNamespace(),
82+
}})
83+
if err != nil {
84+
t.Fatal(err)
85+
}
86+
87+
if result.RequeueAfter != requeueAfterTime {
88+
t.Fatalf("RequeueAfter got %v, want %v", result.RequeueAfter, requeueAfterTime)
89+
}
6290
}
6391

6492
func TestReconcile_when_cluster_ready(t *testing.T) {

0 commit comments

Comments
 (0)