Skip to content

Commit fac9973

Browse files
committed
add test for when the claim was fulfilled and is deleted
1 parent ff393d5 commit fac9973

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

internal/controllers/ipaddressclaim_test.go

+48-23
Original file line numberDiff line numberDiff line change
@@ -1903,32 +1903,57 @@ var _ = Describe("IPAddressClaimReconciler", func() {
19031903
})
19041904

19051905
Context("When the cluster can not be retrieved", func() {
1906-
AfterEach(func() {
1907-
deleteClaim("test", namespace)
1908-
deleteNamespacedPool(poolName, namespace)
1906+
When("the claim is not fulfilled", func() {
1907+
AfterEach(func() {
1908+
deleteClaim("test", namespace)
1909+
deleteNamespacedPool(poolName, namespace)
1910+
})
1911+
It("does not allocate an address", func() {
1912+
claim := ipamv1.IPAddressClaim{
1913+
ObjectMeta: metav1.ObjectMeta{
1914+
Name: "test",
1915+
Namespace: namespace,
1916+
},
1917+
Spec: ipamv1.IPAddressClaimSpec{
1918+
ClusterName: clusterName,
1919+
PoolRef: corev1.TypedLocalObjectReference{
1920+
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
1921+
Kind: "InClusterIPPool",
1922+
Name: poolName,
1923+
},
1924+
},
1925+
}
1926+
Expect(k8sClient.Create(context.Background(), &claim)).To(Succeed())
1927+
Eventually(Get(&claim)).Should(Succeed())
1928+
1929+
addresses := ipamv1.IPAddressList{}
1930+
Consistently(ObjectList(&addresses, client.InNamespace(namespace))).
1931+
WithTimeout(5 * time.Second).WithPolling(100 * time.Millisecond).Should(
1932+
HaveField("Items", HaveLen(0)))
1933+
})
19091934
})
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,
1935+
1936+
When("the claim was fulfilled and is deleted", func() {
1937+
It("releases the IP address", func() {
1938+
// does not need to be paused, as the cluster just exists to allow the claim to be fulfilled before deleting the cluster again
1939+
cluster := clusterv1.Cluster{
1940+
ObjectMeta: metav1.ObjectMeta{
1941+
Name: clusterName,
1942+
Namespace: namespace,
19221943
},
1923-
},
1924-
}
1925-
Expect(k8sClient.Create(context.Background(), &claim)).To(Succeed())
1926-
Eventually(Get(&claim)).Should(Succeed())
1944+
}
1945+
Expect(k8sClient.Create(context.Background(), &cluster)).To(Succeed())
1946+
Eventually(Get(&cluster)).Should(Succeed())
1947+
claim := newClaim("test", namespace, "InClusterIPPool", poolName)
1948+
claim.Spec.ClusterName = clusterName
1949+
Expect(k8sClient.Create(context.Background(), &claim)).To(Succeed())
1950+
Eventually(Get(&claim)).Should(Succeed())
19271951

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)))
1952+
deleteCluster(clusterName, namespace)
1953+
1954+
Expect(k8sClient.Delete(context.Background(), &claim)).To(Succeed())
1955+
Eventually(Get(&claim)).Should(Not(Succeed()))
1956+
})
19321957
})
19331958
})
19341959

0 commit comments

Comments
 (0)