Skip to content

Commit 806ce4d

Browse files
authored
Merge pull request #296 from kubernetes-sigs/fix/cluster-paused-deletion
Ignore cluster not found on claim deletion
2 parents 0e2a6d4 + aa79738 commit 806ce4d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

internal/controllers/ipaddressclaim_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,36 @@ var _ = Describe("IPAddressClaimReconciler", func() {
19021902
})
19031903
})
19041904

1905+
Context("When the cluster can not be retrieved", func() {
1906+
AfterEach(func() {
1907+
deleteClaim("test", namespace)
1908+
deleteNamespacedPool(poolName, namespace)
1909+
})
1910+
It("When the cluster cannot be retrieved", func() {
1911+
claim := ipamv1.IPAddressClaim{
1912+
ObjectMeta: metav1.ObjectMeta{
1913+
Name: "test",
1914+
Namespace: namespace,
1915+
},
1916+
Spec: ipamv1.IPAddressClaimSpec{
1917+
ClusterName: clusterName,
1918+
PoolRef: corev1.TypedLocalObjectReference{
1919+
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
1920+
Kind: "InClusterIPPool",
1921+
Name: poolName,
1922+
},
1923+
},
1924+
}
1925+
Expect(k8sClient.Create(context.Background(), &claim)).To(Succeed())
1926+
Eventually(Get(&claim)).Should(Succeed())
1927+
1928+
addresses := ipamv1.IPAddressList{}
1929+
Consistently(ObjectList(&addresses, client.InNamespace(namespace))).
1930+
WithTimeout(5 * time.Second).WithPolling(100 * time.Millisecond).Should(
1931+
HaveField("Items", HaveLen(0)))
1932+
})
1933+
})
1934+
19051935
Context("When the ipaddressclaim spec.clusterName reference a paused cluster via cluster label", func() {
19061936
AfterEach(func() {
19071937
deleteClaim("test", namespace)

pkg/ipamutil/reconciler.go

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func (r *ClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ct
139139
}
140140
if err != nil {
141141
if apierrors.IsNotFound(err) {
142+
if !claim.ObjectMeta.DeletionTimestamp.IsZero() {
143+
return ctrl.Result{}, r.reconcileDelete(ctx, claim)
144+
}
142145
log.Info("IPAddressClaim linked to a cluster that is not found, unable to determine cluster's paused state, skipping reconciliation")
143146
return ctrl.Result{}, nil
144147
}

0 commit comments

Comments
 (0)