@@ -161,12 +161,21 @@ func getNetworkConfigDataForDevice(ctx context.Context, machineScope *scope.Mach
161161 ip := IPAddressWithPrefix (ipAddr .Spec .Address , ipAddr .Spec .Prefix )
162162 gw := ipAddr .Spec .Gateway
163163
164- return & cloudinit.NetworkConfigData {
164+ cloudinitNetworkConfigData := & cloudinit.NetworkConfigData {
165165 MacAddress : macAddress ,
166- IPAddress : ip ,
167- Gateway : gw ,
168166 DNSServers : dns ,
169- }, nil
167+ }
168+
169+ // If it's an IPv6 address, we must set Gateway6 and IPV6Address instead
170+ if strings .Contains (ip , ":" ) {
171+ cloudinitNetworkConfigData .Gateway6 = gw
172+ cloudinitNetworkConfigData .IPV6Address = ip
173+ } else {
174+ cloudinitNetworkConfigData .Gateway = gw
175+ cloudinitNetworkConfigData .IPAddress = ip
176+ }
177+
178+ return cloudinitNetworkConfigData , nil
170179}
171180
172181func getDefaultNetworkDevice (ctx context.Context , machineScope * scope.MachineScope ) ([]cloudinit.NetworkConfigData , error ) {
@@ -194,8 +203,8 @@ func getDefaultNetworkDevice(ctx context.Context, machineScope *scope.MachineSco
194203 case config .MacAddress != conf .MacAddress :
195204 return nil , errors .New ("default network device ipv4 and ipv6 have different mac addresses" )
196205 default :
197- config .IPV6Address = conf .IPAddress
198- config .Gateway6 = conf .Gateway
206+ config .IPV6Address = conf .IPV6Address
207+ config .Gateway6 = conf .Gateway6
199208 }
200209 }
201210
@@ -238,8 +247,8 @@ func getAdditionalNetworkDevices(ctx context.Context, machineScope *scope.Machin
238247 case config .MacAddress != conf .MacAddress :
239248 return nil , errors .New ("additional network device ipv4 and ipv6 have different mac addresses" )
240249 default :
241- config .IPV6Address = conf .IPAddress
242- config .Gateway6 = conf .Gateway
250+ config .IPV6Address = conf .IPV6Address
251+ config .Gateway6 = conf .Gateway6
243252 }
244253 }
245254
0 commit comments