@@ -832,11 +832,18 @@ var _ = Describe("Multi Homing", func() {
832832
833833 Context ("and networkAttachmentDefinition is modified" , func () {
834834 const (
835- expectedChangedMTU = 1600
835+ expectedChangedMTU = 1600
836+ newDesiredRange = "60.128.0.192/28" // Desired IPs from 60.128.0.192 to 60.128.0.207
837+ excludedSubnetLowerRange1 = "60.128.0.0/25" // Excludes IPs from 60.128.0.0 to 60.128.0.127
838+ excludedSubnetLowerRange2 = "60.128.0.128/26" // Excludes IPs from 60.128.0.128 to 60.128.0.191
839+ excludedSubnetUpperRange1 = "60.128.0.208/28" // Excludes IPs from 60.128.0.208 to 60.128.0.223
840+ excludedSubnetUpperRange2 = "60.128.0.224/27" // Excludes IPs from 60.128.0.224 to 60.128.0.255
836841 )
837842 BeforeEach (func () {
838843 By ("setting new MTU" )
839844 netConfig .mtu = expectedChangedMTU
845+ By ("setting new subnets to leave a smaller range" )
846+ netConfig .excludeCIDRs = []string {excludedSubnetLowerRange1 , excludedSubnetLowerRange2 , excludedSubnetUpperRange1 , excludedSubnetUpperRange2 }
840847 p := []byte (fmt .Sprintf (`[{"op":"replace","path":"/spec/config","value":%q}]` , generateNADSpec (netConfig )))
841848 Expect (patchNADSpec (nadClient , netConfig .name , netConfig .namespace , p )).To (Succeed ())
842849 })
@@ -863,6 +870,32 @@ var _ = Describe("Multi Homing", func() {
863870 return nil
864871 }).Should (Succeed (), "pod MTU should be properly configured" )
865872 })
873+
874+ It ("allocates the pod's secondary interface IP in the new range after NetworkAttachmentDefinition reconcile" , func () {
875+ By ("asserting the pod's secondary interface IP is properly configured" )
876+ Eventually (func () error {
877+ clientPodConfig := podConfiguration {
878+ name : clientPodName + "-" + randStr (10 ),
879+ namespace : f .Namespace .Name ,
880+ attachments : []nadapi.NetworkSelectionElement {{Name : secondaryNetworkName }},
881+ }
882+ kickstartPod (cs , clientPodConfig )
883+
884+ clientIP , err := podIPForAttachment (cs , clientPodConfig .namespace , clientPodConfig .name , netConfig .name , 0 )
885+ if err != nil {
886+ return err
887+ }
888+
889+ // In order to prevent the pod from interfering with the test, deleting it before retrying
890+ if err := inRange (newDesiredRange , clientIP ); err != nil {
891+ if delErr := cs .CoreV1 ().Pods (clientPodConfig .namespace ).Delete (context .Background (), clientPodConfig .name , metav1.DeleteOptions {}); delErr != nil {
892+ err = errors .Join (err , fmt .Errorf ("pod delete failed: %w" , delErr ))
893+ }
894+ return err
895+ }
896+ return nil
897+ }).Should (Succeed (), "pod's secondary NIC is not allocated in the desired range" )
898+ })
866899 })
867900
868901 Context ("with multi network policy blocking the traffic" , func () {
0 commit comments