Skip to content

Commit 0b2867b

Browse files
committed
fix: owner cluster handling
Signed-off-by: sivchari <[email protected]>
1 parent 34989ac commit 0b2867b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
154154
// Fetch the Cluster.
155155
cluster, err := util.GetOwnerCluster(ctx, r.Client, kcp.ObjectMeta)
156156
if err != nil {
157-
if apierrors.IsNotFound(err) {
158-
log.Info("Cluster Controller has not yet set OwnerRef")
159-
return ctrl.Result{}, nil
157+
if !apierrors.IsNotFound(err) {
158+
log.Error(err, "Failed to retrieve owner Cluster from the API Server")
159+
return ctrl.Result{}, err
160160
}
161-
log.Error(err, "Failed to retrieve owner Cluster from the API Server")
162-
return ctrl.Result{}, err
161+
}
162+
if apierrors.IsNotFound(err) || cluster == nil {
163+
log.Info("Cluster Controller has not yet set OwnerRef")
164+
return ctrl.Result{}, nil
163165
}
164166

165167
log = log.WithValues("Cluster", klog.KObj(cluster))

controlplane/kubeadm/internal/controllers/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func TestReconcileNoCluster(t *testing.T) {
343343
}
344344

345345
_, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)})
346-
g.Expect(err).To(HaveOccurred())
346+
g.Expect(err).ToNot(HaveOccurred())
347347

348348
machineList := &clusterv1.MachineList{}
349349
g.Expect(fakeClient.List(ctx, machineList, client.InNamespace(metav1.NamespaceDefault))).To(Succeed())

0 commit comments

Comments
 (0)