Skip to content

Commit

Permalink
Ignore cluster not found on claim deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbenjemaa committed Oct 15, 2024
1 parent 0e2a6d4 commit aa79738
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/controllers/ipaddressclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,36 @@ var _ = Describe("IPAddressClaimReconciler", func() {
})
})

Context("When the cluster can not be retrieved", func() {
AfterEach(func() {
deleteClaim("test", namespace)
deleteNamespacedPool(poolName, namespace)
})
It("When the cluster cannot be retrieved", func() {
claim := ipamv1.IPAddressClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
},
Spec: ipamv1.IPAddressClaimSpec{
ClusterName: clusterName,
PoolRef: corev1.TypedLocalObjectReference{
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
Kind: "InClusterIPPool",
Name: poolName,
},
},
}
Expect(k8sClient.Create(context.Background(), &claim)).To(Succeed())
Eventually(Get(&claim)).Should(Succeed())

addresses := ipamv1.IPAddressList{}
Consistently(ObjectList(&addresses, client.InNamespace(namespace))).
WithTimeout(5 * time.Second).WithPolling(100 * time.Millisecond).Should(
HaveField("Items", HaveLen(0)))
})
})

Context("When the ipaddressclaim spec.clusterName reference a paused cluster via cluster label", func() {
AfterEach(func() {
deleteClaim("test", namespace)
Expand Down
3 changes: 3 additions & 0 deletions pkg/ipamutil/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func (r *ClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ct
}
if err != nil {
if apierrors.IsNotFound(err) {
if !claim.ObjectMeta.DeletionTimestamp.IsZero() {
return ctrl.Result{}, r.reconcileDelete(ctx, claim)
}
log.Info("IPAddressClaim linked to a cluster that is not found, unable to determine cluster's paused state, skipping reconciliation")
return ctrl.Result{}, nil
}
Expand Down

0 comments on commit aa79738

Please sign in to comment.