@@ -1903,32 +1903,57 @@ var _ = Describe("IPAddressClaimReconciler", func() {
1903
1903
})
1904
1904
1905
1905
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
+ })
1909
1934
})
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 ,
1922
1943
},
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 ())
1927
1951
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
+ })
1932
1957
})
1933
1958
})
1934
1959
0 commit comments