@@ -36,33 +36,33 @@ func TestReconcileIPAddresses_CreateDefaultClaim(t *testing.T) {
3636 require .NoError (t , err )
3737 require .True (t , requeue )
3838 requireConditionIsFalse (t , machineScope .ProxmoxMachine , infrav1 .VMProvisionedCondition )
39-
4039}
4140
4241func TestReconcileIPAddresses_CreateAdditionalClaim (t * testing.T ) {
4342 machineScope , _ , kubeClient := setupReconcilerTest (t )
4443
45- pool0 := corev1.TypedLocalObjectReference {APIGroup : ptr .To ("ipam.cluster.x-k8s.io" ), Kind : "InClusterIPPool" , Name : "custom" }
44+ defaultPool := corev1.TypedLocalObjectReference {APIGroup : ptr .To ("ipam.cluster.x-k8s.io" ), Kind : "InClusterIPPool" , Name : "custom" }
45+
4646 machineScope .ProxmoxMachine .Spec .Network = & infrav1.NetworkSpec {
4747 NetworkDevices : []infrav1.NetworkDevice {
48- {Name : ptr .To ("net0" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {pool0 }}},
48+ {Name : ptr .To ("net0" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {defaultPool }}},
4949 {Name : ptr .To ("net1" ), InterfaceConfig : infrav1.InterfaceConfig {}},
5050 },
5151 }
52+
5253 vm := newStoppedVM ()
5354 vm .VirtualMachineConfig .Tags = ipTag
5455 machineScope .SetVirtualMachine (vm )
5556
5657 createIPPools (t , kubeClient , machineScope )
57- createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , & pool0 )
58+ createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , & defaultPool )
5859
5960 requeue , err := reconcileIPAddresses (context .Background (), machineScope )
6061 require .NotNil (t , machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ])
6162 require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ]), infrav1.IPAddresses {IPV4 : []string {"10.10.10.10" }, IPV6 : nil })
6263 require .NoError (t , err )
6364 require .True (t , requeue )
6465 requireConditionIsFalse (t , machineScope .ProxmoxMachine , infrav1 .VMProvisionedCondition )
65-
6666}
6767
6868/*func TestReconcileIPAddresses_AddIPTag(t *testing.T) {
@@ -82,16 +82,21 @@ func TestReconcileIPAddresses_CreateAdditionalClaim(t *testing.T) {
8282
8383func TestReconcileIPAddresses_SetIPAddresses (t * testing.T ) {
8484 machineScope , _ , kubeClient := setupReconcilerTest (t )
85+
86+ defaultPool := corev1.TypedLocalObjectReference {APIGroup : ptr .To ("ipam.cluster.x-k8s.io" ), Kind : "InClusterIPPool" , Name : "default" }
87+ extraPool0 := corev1.TypedLocalObjectReference {APIGroup : ptr .To ("ipam.cluster.x-k8s.io" ), Kind : "GlobalInClusterIPPool" , Name : "additional" }
88+
8589 machineScope .ProxmoxMachine .Spec .Network = & infrav1.NetworkSpec {
8690 NetworkDevices : []infrav1.NetworkDevice {
87- {Name : ptr .To ("net1" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {{Kind : "GlobalInClusterIPPool" , Name : "custom" }}}},
91+ {Name : ptr .To ("net0" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {defaultPool }}},
92+ {Name : ptr .To ("net1" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {extraPool0 }}},
8893 },
8994 }
9095 vm := newStoppedVM ()
9196 vm .VirtualMachineConfig .Tags = ipTag
9297 machineScope .SetVirtualMachine (vm )
93- createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , nil )
94- createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" , nil )
98+ createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , & defaultPool )
99+ createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" , & extraPool0 )
95100 createIPPools (t , kubeClient , machineScope )
96101
97102 requeue , err := reconcileIPAddresses (context .Background (), machineScope )
@@ -100,12 +105,11 @@ func TestReconcileIPAddresses_SetIPAddresses(t *testing.T) {
100105 require .True (t , requeue )
101106
102107 require .NotNil (t , machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ])
103- require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ]), infrav1.IPAddresses {IPV4 : []string {"10.10.10.10" }, IPV6 : [] string {} })
108+ require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ]), infrav1.IPAddresses {IPV4 : []string {"10.10.10.10" }, IPV6 : nil })
104109 require .NotNil (t , machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ])
105- require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ]), infrav1.IPAddresses {IPV4 : []string {"10.100.10.10" }, IPV6 : [] string {} })
110+ require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ]), infrav1.IPAddresses {IPV4 : []string {"10.100.10.10" }, IPV6 : nil })
106111
107112 requireConditionIsFalse (t , machineScope .ProxmoxMachine , infrav1 .VMProvisionedCondition )
108-
109113}
110114
111115/*func TestReconcileIPAddresses_MultipleDevices(t *testing.T) {
@@ -145,22 +149,24 @@ fmt.Println("reconcileIPAddresses", requeue, err)
145149
146150func TestReconcileIPAddresses_IPV6 (t * testing.T ) {
147151 machineScope , _ , kubeClient := setupReconcilerTest (t )
148- machineScope . InfraCluster . ProxmoxCluster . Spec . IPv6Config = & infrav1. IPConfigSpec {
149- Addresses : [] string { "fe80::/64" },
150- Prefix : 64 ,
151- Gateway : "fe80::1" ,
152- }
152+
153+ defaultPool := corev1. TypedLocalObjectReference { APIGroup : ptr . To ( "ipam.cluster.x-k8s.io" ), Kind : "InClusterIPPool" , Name : "default" }
154+ defaultPoolV6 := corev1. TypedLocalObjectReference { APIGroup : ptr . To ( "ipam.cluster.x-k8s.io" ), Kind : "InClusterIPPool" , Name : "defaultV6" }
155+ extraPool0 := corev1. TypedLocalObjectReference { APIGroup : ptr . To ( "ipam.cluster.x-k8s.io" ), Kind : "GlobalInClusterIPPool" , Name : "additional" }
156+
153157 machineScope .ProxmoxMachine .Spec .Network = & infrav1.NetworkSpec {
154158 NetworkDevices : []infrav1.NetworkDevice {
155- {Name : ptr .To ("net1" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {{Kind : "GlobalInClusterIPPool" , Name : "custom" }}}},
159+ {Name : ptr .To ("net0" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {defaultPool , defaultPoolV6 }}},
160+ {Name : ptr .To ("net1" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {extraPool0 }}},
156161 },
157162 }
163+
158164 vm := newStoppedVM ()
159165 vm .VirtualMachineConfig .Tags = ipTag
160166 machineScope .SetVirtualMachine (vm )
161- createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , nil )
162- createIP6AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "fe80::1" , nil )
163- createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" , nil )
167+ createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , & defaultPool )
168+ createIP6AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "fe80::1" , & defaultPoolV6 )
169+ createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" , & extraPool0 )
164170 createIPPools (t , kubeClient , machineScope )
165171
166172 requeue , err := reconcileIPAddresses (context .Background (), machineScope )
@@ -170,7 +176,7 @@ func TestReconcileIPAddresses_IPV6(t *testing.T) {
170176 require .NotNil (t , machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ])
171177 require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ]), infrav1.IPAddresses {IPV4 : []string {"10.10.10.10" }, IPV6 : []string {"fe80::1" }})
172178 require .NotNil (t , machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ])
173- require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ]), infrav1.IPAddresses {IPV4 : []string {"10.100.10.10" }, IPV6 : [] string {} })
179+ require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ]), infrav1.IPAddresses {IPV4 : []string {"10.100.10.10" }, IPV6 : nil })
174180
175181 requireConditionIsFalse (t , machineScope .ProxmoxMachine , infrav1 .VMProvisionedCondition )
176182}
@@ -183,21 +189,33 @@ func TestReconcileIPAddresses_MachineIPPoolRef(t *testing.T) {
183189 {Name : ptr .To ("net1" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {{Kind : "GlobalInClusterIPPool" , Name : "custom-additional-ips" }}}},
184190 },
185191 }
192+
193+ defaultPool := corev1.TypedLocalObjectReference {APIGroup : ptr .To ("ipam.cluster.x-k8s.io" ), Kind : "InClusterIPPool" , Name : "default" }
194+ extraPool0 := corev1.TypedLocalObjectReference {APIGroup : ptr .To ("ipam.cluster.x-k8s.io" ), Kind : "GlobalInClusterIPPool" , Name : "additional" }
195+
196+ machineScope .ProxmoxMachine .Spec .Network = & infrav1.NetworkSpec {
197+ NetworkDevices : []infrav1.NetworkDevice {
198+ {Name : ptr .To ("net0" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {defaultPool }}},
199+ {Name : ptr .To ("net1" ), InterfaceConfig : infrav1.InterfaceConfig {IPPoolRef : []corev1.TypedLocalObjectReference {extraPool0 }}},
200+ },
201+ }
202+
186203 vm := newStoppedVM ()
187204 vm .VirtualMachineConfig .Tags = ipTag
188205 machineScope .SetVirtualMachine (vm )
189- createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , nil )
190- createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" , nil )
206+
207+ createIP4AddressResource (t , kubeClient , machineScope , infrav1 .DefaultNetworkDevice , "10.10.10.10" , & defaultPool )
208+ createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" , & extraPool0 )
191209 createIPPools (t , kubeClient , machineScope )
192210
193211 requeue , err := reconcileIPAddresses (context .Background (), machineScope )
194212 require .NoError (t , err )
195213 require .True (t , requeue )
196214
197215 require .NotNil (t , machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ])
198- require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ]), infrav1.IPAddresses {IPV4 : []string {"10.10.10.10" }, IPV6 : [] string {} })
216+ require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net0" ]), infrav1.IPAddresses {IPV4 : []string {"10.10.10.10" }, IPV6 : nil })
199217 require .NotNil (t , machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ])
200- require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ]), infrav1.IPAddresses {IPV4 : []string {"10.100.10.10" }, IPV6 : [] string {} })
218+ require .Equal (t , * (machineScope .ProxmoxMachine .Status .IPAddresses ["net1" ]), infrav1.IPAddresses {IPV4 : []string {"10.100.10.10" }, IPV6 : nil })
201219
202220 requireConditionIsFalse (t , machineScope .ProxmoxMachine , infrav1 .VMProvisionedCondition )
203221}
0 commit comments