@@ -679,13 +679,14 @@ var _ = Describe("IPPool manager", func() {
679679 )
680680
681681 type testCaseAllocateAddress struct {
682- ipPool * ipamv1.IPPool
683- ipClaim * ipamv1.IPClaim
684- addresses map [ipamv1.IPAddressStr ]string
685- expectedAddress ipamv1.IPAddressStr
686- expectedPrefix int
687- expectedGateway * ipamv1.IPAddressStr
688- expectError bool
682+ ipPool * ipamv1.IPPool
683+ ipClaim * ipamv1.IPClaim
684+ addresses map [ipamv1.IPAddressStr ]string
685+ expectedAddress ipamv1.IPAddressStr
686+ expectedPrefix int
687+ expectedGateway * ipamv1.IPAddressStr
688+ expectedDNSServers []ipamv1.IPAddressStr
689+ expectError bool
689690 }
690691
691692 DescribeTable ("Test AllocateAddress" ,
@@ -694,7 +695,7 @@ var _ = Describe("IPPool manager", func() {
694695 klogr .New (),
695696 )
696697 Expect (err ).NotTo (HaveOccurred ())
697- allocatedAddress , prefix , gateway , err := ipPoolMgr .allocateAddress (
698+ allocatedAddress , prefix , gateway , dnsServers , err := ipPoolMgr .allocateAddress (
698699 tc .ipClaim , tc .addresses ,
699700 )
700701 if tc .expectError {
@@ -706,6 +707,7 @@ var _ = Describe("IPPool manager", func() {
706707 Expect (allocatedAddress ).To (Equal (tc .expectedAddress ))
707708 Expect (prefix ).To (Equal (tc .expectedPrefix ))
708709 Expect (* gateway ).To (Equal (* tc .expectedGateway ))
710+ Expect (dnsServers ).To (Equal (tc .expectedDNSServers ))
709711 },
710712 Entry ("Empty pools" , testCaseAllocateAddress {
711713 ipPool : & ipamv1.IPPool {
@@ -727,13 +729,19 @@ var _ = Describe("IPPool manager", func() {
727729 End : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.20" )),
728730 Prefix : 26 ,
729731 Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.1.1" )),
732+ DNSServers : []ipamv1.IPAddressStr {
733+ ipamv1 .IPAddressStr ("8.8.8.8" ),
734+ },
730735 },
731736 },
732737 PreAllocations : map [string ]ipamv1.IPAddressStr {
733738 "TestRef" : ipamv1 .IPAddressStr ("192.168.0.15" ),
734739 },
735740 Prefix : 24 ,
736741 Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.1" )),
742+ DNSServers : []ipamv1.IPAddressStr {
743+ ipamv1 .IPAddressStr ("8.8.4.4" ),
744+ },
737745 },
738746 },
739747 ipClaim : & ipamv1.IPClaim {
@@ -743,7 +751,10 @@ var _ = Describe("IPPool manager", func() {
743751 },
744752 expectedAddress : ipamv1 .IPAddressStr ("192.168.0.15" ),
745753 expectedGateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.1" )),
746- expectedPrefix : 24 ,
754+ expectedDNSServers : []ipamv1.IPAddressStr {
755+ ipamv1 .IPAddressStr ("8.8.4.4" ),
756+ },
757+ expectedPrefix : 24 ,
747758 }),
748759 Entry ("One pool, with start and existing address" , testCaseAllocateAddress {
749760 ipPool : & ipamv1.IPPool {
@@ -780,10 +791,16 @@ var _ = Describe("IPPool manager", func() {
780791 End : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.20" )),
781792 Prefix : 24 ,
782793 Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.1" )),
794+ DNSServers : []ipamv1.IPAddressStr {
795+ ipamv1 .IPAddressStr ("8.8.8.8" ),
796+ },
783797 },
784798 },
785799 Prefix : 26 ,
786800 Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.1.1" )),
801+ DNSServers : []ipamv1.IPAddressStr {
802+ ipamv1 .IPAddressStr ("8.8.4.4" ),
803+ },
787804 },
788805 },
789806 ipClaim : & ipamv1.IPClaim {
@@ -797,7 +814,50 @@ var _ = Describe("IPPool manager", func() {
797814 },
798815 expectedAddress : ipamv1 .IPAddressStr ("192.168.0.13" ),
799816 expectedGateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.1" )),
800- expectedPrefix : 24 ,
817+ expectedDNSServers : []ipamv1.IPAddressStr {
818+ ipamv1 .IPAddressStr ("8.8.8.8" ),
819+ },
820+ expectedPrefix : 24 ,
821+ }),
822+ Entry ("two pools, with subnet and override prefix in first" , testCaseAllocateAddress {
823+ ipPool : & ipamv1.IPPool {
824+ Spec : ipamv1.IPPoolSpec {
825+ Pools : []ipamv1.Pool {
826+ ipamv1.Pool {
827+ Start : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.10" )),
828+ End : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.0.10" )),
829+ Prefix : 24 ,
830+ Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.1.1" )),
831+ DNSServers : []ipamv1.IPAddressStr {
832+ ipamv1 .IPAddressStr ("8.8.8.8" ),
833+ },
834+ },
835+ ipamv1.Pool {
836+ Subnet : (* ipamv1 .IPSubnetStr )(pointer .StringPtr ("192.168.1.10/24" )),
837+ },
838+ },
839+ Prefix : 26 ,
840+ Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.2.1" )),
841+ DNSServers : []ipamv1.IPAddressStr {
842+ ipamv1 .IPAddressStr ("8.8.4.4" ),
843+ },
844+ },
845+ },
846+ ipClaim : & ipamv1.IPClaim {
847+ ObjectMeta : metav1.ObjectMeta {
848+ Name : "TestRef" ,
849+ },
850+ },
851+ addresses : map [ipamv1.IPAddressStr ]string {
852+ ipamv1 .IPAddressStr ("192.168.1.11" ): "bcde" ,
853+ ipamv1 .IPAddressStr ("192.168.0.10" ): "abcd" ,
854+ },
855+ expectedAddress : ipamv1 .IPAddressStr ("192.168.1.12" ),
856+ expectedGateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.2.1" )),
857+ expectedDNSServers : []ipamv1.IPAddressStr {
858+ ipamv1 .IPAddressStr ("8.8.4.4" ),
859+ },
860+ expectedPrefix : 26 ,
801861 }),
802862 Entry ("two pools, with subnet and override prefix" , testCaseAllocateAddress {
803863 ipPool : & ipamv1.IPPool {
@@ -811,10 +871,16 @@ var _ = Describe("IPPool manager", func() {
811871 Subnet : (* ipamv1 .IPSubnetStr )(pointer .StringPtr ("192.168.1.10/24" )),
812872 Prefix : 24 ,
813873 Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.1.1" )),
874+ DNSServers : []ipamv1.IPAddressStr {
875+ ipamv1 .IPAddressStr ("8.8.8.8" ),
876+ },
814877 },
815878 },
816879 Prefix : 26 ,
817880 Gateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.2.1" )),
881+ DNSServers : []ipamv1.IPAddressStr {
882+ ipamv1 .IPAddressStr ("8.8.4.4" ),
883+ },
818884 },
819885 },
820886 ipClaim : & ipamv1.IPClaim {
@@ -828,7 +894,10 @@ var _ = Describe("IPPool manager", func() {
828894 },
829895 expectedAddress : ipamv1 .IPAddressStr ("192.168.1.12" ),
830896 expectedGateway : (* ipamv1 .IPAddressStr )(pointer .StringPtr ("192.168.1.1" )),
831- expectedPrefix : 24 ,
897+ expectedDNSServers : []ipamv1.IPAddressStr {
898+ ipamv1 .IPAddressStr ("8.8.8.8" ),
899+ },
900+ expectedPrefix : 24 ,
832901 }),
833902 Entry ("Exhausted pools start" , testCaseAllocateAddress {
834903 ipPool : & ipamv1.IPPool {
0 commit comments