@@ -1916,6 +1916,125 @@ var _ = Describe("IPPool manager", func() {
19161916 expectedGateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
19171917 expectedPrefix : 24 ,
19181918 }),
1919+ Entry ("One pool, with start and existing address, ipAddress annotation present" , testCaseAllocateAddress {
1920+ ipPool : & ipamv1.IPPool {
1921+ Spec : ipamv1.IPPoolSpec {
1922+ Pools : []ipamv1.Pool {
1923+ {
1924+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
1925+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
1926+ },
1927+ },
1928+ Prefix : 24 ,
1929+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
1930+ },
1931+ },
1932+ ipClaim : & ipamv1.IPClaim {
1933+ ObjectMeta : metav1.ObjectMeta {
1934+ Name : "TestRef" ,
1935+ Annotations : map [string ]string {
1936+ IPAddressAnnotation : "192.168.0.16" ,
1937+ },
1938+ },
1939+ },
1940+ addresses : map [ipamv1.IPAddressStr ]string {
1941+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
1942+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
1943+ },
1944+ expectedAddress : ipamv1 .IPAddressStr ("192.168.0.16" ),
1945+ expectedGateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
1946+ expectedPrefix : 24 ,
1947+ }),
1948+ Entry ("One pool, with start and existing address, ipAddress annotation present but already acquired" , testCaseAllocateAddress {
1949+ ipPool : & ipamv1.IPPool {
1950+ Spec : ipamv1.IPPoolSpec {
1951+ Pools : []ipamv1.Pool {
1952+ {
1953+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
1954+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
1955+ },
1956+ },
1957+ Prefix : 24 ,
1958+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
1959+ },
1960+ },
1961+ ipClaim : & ipamv1.IPClaim {
1962+ ObjectMeta : metav1.ObjectMeta {
1963+ Name : "TestRef" ,
1964+ Annotations : map [string ]string {
1965+ IPAddressAnnotation : "192.168.0.11" ,
1966+ },
1967+ },
1968+ },
1969+ addresses : map [ipamv1.IPAddressStr ]string {
1970+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
1971+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
1972+ },
1973+ expectError : true ,
1974+ }),
1975+
1976+ Entry ("One pool, with start and existing address, ipAddress annotation present and requested ipAddress in preAllocations with conflicting ipclaim name" , testCaseAllocateAddress {
1977+ ipPool : & ipamv1.IPPool {
1978+ Spec : ipamv1.IPPoolSpec {
1979+ Pools : []ipamv1.Pool {
1980+ {
1981+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
1982+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
1983+ },
1984+ },
1985+ Prefix : 24 ,
1986+ PreAllocations : map [string ]ipamv1.IPAddressStr {
1987+ "TestRef" : ipamv1 .IPAddressStr ("192.168.0.15" ),
1988+ },
1989+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
1990+ },
1991+ },
1992+ ipClaim : & ipamv1.IPClaim {
1993+ ObjectMeta : metav1.ObjectMeta {
1994+ Name : "TestRef" ,
1995+ Annotations : map [string ]string {
1996+ IPAddressAnnotation : "192.168.0.16" ,
1997+ },
1998+ },
1999+ },
2000+ addresses : map [ipamv1.IPAddressStr ]string {
2001+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
2002+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
2003+ },
2004+ expectError : true ,
2005+ }),
2006+ Entry ("One pool, with start and existing address, ipAddress annotation present and requested ipAddress in preAllocations with non-conflicting ipclaim name" , testCaseAllocateAddress {
2007+ ipPool : & ipamv1.IPPool {
2008+ Spec : ipamv1.IPPoolSpec {
2009+ Pools : []ipamv1.Pool {
2010+ {
2011+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
2012+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
2013+ },
2014+ },
2015+ Prefix : 24 ,
2016+ PreAllocations : map [string ]ipamv1.IPAddressStr {
2017+ "TestRef" : ipamv1 .IPAddressStr ("192.168.0.16" ),
2018+ },
2019+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2020+ },
2021+ },
2022+ ipClaim : & ipamv1.IPClaim {
2023+ ObjectMeta : metav1.ObjectMeta {
2024+ Name : "TestRef" ,
2025+ Annotations : map [string ]string {
2026+ IPAddressAnnotation : "192.168.0.16" ,
2027+ },
2028+ },
2029+ },
2030+ addresses : map [ipamv1.IPAddressStr ]string {
2031+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
2032+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
2033+ },
2034+ expectedAddress : ipamv1 .IPAddressStr ("192.168.0.16" ),
2035+ expectedGateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2036+ expectedPrefix : 24 ,
2037+ }),
19192038 Entry ("One pool, with subnet and override prefix" , testCaseAllocateAddress {
19202039 ipPool : & ipamv1.IPPool {
19212040 Spec : ipamv1.IPPoolSpec {
@@ -2230,6 +2349,124 @@ var _ = Describe("IPPool manager", func() {
22302349 expectedGateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
22312350 expectedPrefix : 24 ,
22322351 }),
2352+ Entry ("One pool, with start and existing address, ipAddress annotation" , testCapiCaseAllocateAddress {
2353+ ipPool : & ipamv1.IPPool {
2354+ Spec : ipamv1.IPPoolSpec {
2355+ Pools : []ipamv1.Pool {
2356+ {
2357+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
2358+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
2359+ },
2360+ },
2361+ Prefix : 24 ,
2362+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2363+ },
2364+ },
2365+ ipAddressClaim : & capipamv1.IPAddressClaim {
2366+ ObjectMeta : metav1.ObjectMeta {
2367+ Name : "TestRef" ,
2368+ Annotations : map [string ]string {
2369+ IPAddressAnnotation : "192.168.0.16" ,
2370+ },
2371+ },
2372+ },
2373+ addresses : map [ipamv1.IPAddressStr ]string {
2374+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
2375+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
2376+ },
2377+ expectedAddress : ipamv1 .IPAddressStr ("192.168.0.16" ),
2378+ expectedGateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2379+ expectedPrefix : 24 ,
2380+ }),
2381+ Entry ("One pool, with start and existing address, ipAddress annotation but already acquired" , testCapiCaseAllocateAddress {
2382+ ipPool : & ipamv1.IPPool {
2383+ Spec : ipamv1.IPPoolSpec {
2384+ Pools : []ipamv1.Pool {
2385+ {
2386+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
2387+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
2388+ },
2389+ },
2390+ Prefix : 24 ,
2391+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2392+ },
2393+ },
2394+ ipAddressClaim : & capipamv1.IPAddressClaim {
2395+ ObjectMeta : metav1.ObjectMeta {
2396+ Name : "TestRef" ,
2397+ Annotations : map [string ]string {
2398+ IPAddressAnnotation : "192.168.0.12" ,
2399+ },
2400+ },
2401+ },
2402+ addresses : map [ipamv1.IPAddressStr ]string {
2403+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
2404+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
2405+ },
2406+ expectError : true ,
2407+ }),
2408+ Entry ("One pool, with start and existing address, ipAddress annotation present and requested ipAddress in preAllocations with conflicting ipclaim name" , testCapiCaseAllocateAddress {
2409+ ipPool : & ipamv1.IPPool {
2410+ Spec : ipamv1.IPPoolSpec {
2411+ Pools : []ipamv1.Pool {
2412+ {
2413+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
2414+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
2415+ },
2416+ },
2417+ Prefix : 24 ,
2418+ PreAllocations : map [string ]ipamv1.IPAddressStr {
2419+ "TestRef" : ipamv1 .IPAddressStr ("192.168.0.15" ),
2420+ },
2421+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2422+ },
2423+ },
2424+ ipAddressClaim : & capipamv1.IPAddressClaim {
2425+ ObjectMeta : metav1.ObjectMeta {
2426+ Name : "TestRef" ,
2427+ Annotations : map [string ]string {
2428+ IPAddressAnnotation : "192.168.0.16" ,
2429+ },
2430+ },
2431+ },
2432+ addresses : map [ipamv1.IPAddressStr ]string {
2433+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
2434+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
2435+ },
2436+ expectError : true ,
2437+ }),
2438+ Entry ("One pool, with start and existing address, ipAddress annotation present and requested ipAddress in preAllocations with non-conflicting ipclaim name" , testCapiCaseAllocateAddress {
2439+ ipPool : & ipamv1.IPPool {
2440+ Spec : ipamv1.IPPoolSpec {
2441+ Pools : []ipamv1.Pool {
2442+ {
2443+ Start : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.11" )),
2444+ End : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.20" )),
2445+ },
2446+ },
2447+ Prefix : 24 ,
2448+ PreAllocations : map [string ]ipamv1.IPAddressStr {
2449+ "TestRef" : ipamv1 .IPAddressStr ("192.168.0.16" ),
2450+ },
2451+ Gateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2452+ },
2453+ },
2454+ ipAddressClaim : & capipamv1.IPAddressClaim {
2455+ ObjectMeta : metav1.ObjectMeta {
2456+ Name : "TestRef" ,
2457+ Annotations : map [string ]string {
2458+ IPAddressAnnotation : "192.168.0.16" ,
2459+ },
2460+ },
2461+ },
2462+ addresses : map [ipamv1.IPAddressStr ]string {
2463+ ipamv1 .IPAddressStr ("192.168.0.12" ): "bcde" ,
2464+ ipamv1 .IPAddressStr ("192.168.0.11" ): "abcd" ,
2465+ },
2466+ expectedAddress : ipamv1 .IPAddressStr ("192.168.0.16" ),
2467+ expectedGateway : (* ipamv1 .IPAddressStr )(ptr .To ("192.168.0.1" )),
2468+ expectedPrefix : 24 ,
2469+ }),
22332470 Entry ("One pool, with subnet and override prefix" , testCapiCaseAllocateAddress {
22342471 ipPool : & ipamv1.IPPool {
22352472 Spec : ipamv1.IPPoolSpec {
0 commit comments