@@ -196,6 +196,10 @@ func getNetworkConfigDataForDevice(ctx context.Context, machineScope *scope.Mach
196196 dns := machineScope .InfraCluster .ProxmoxCluster .Spec .DNSServers
197197 ip := IPAddressWithPrefix (ipAddr .Spec .Address , ipAddr .Spec .Prefix )
198198 gw := ipAddr .Spec .Gateway
199+ metric , err := findIPAddressGatewayMetric (ctx , machineScope , ipAddr )
200+ if err != nil {
201+ return nil , errors .Wrapf (err , "error converting metric annotation, kind=%s, name=%s" , ipAddr .Spec .PoolRef .Kind , ipAddr .Spec .PoolRef .Name )
202+ }
199203
200204 cloudinitNetworkConfigData := & cloudinit.NetworkConfigData {
201205 MacAddress : macAddress ,
@@ -205,9 +209,11 @@ func getNetworkConfigDataForDevice(ctx context.Context, machineScope *scope.Mach
205209 // If it's an IPv6 address, we must set Gateway6 and IPV6Address instead
206210 if strings .Contains (ip , ":" ) {
207211 cloudinitNetworkConfigData .Gateway6 = gw
212+ cloudinitNetworkConfigData .Metric6 = metric
208213 cloudinitNetworkConfigData .IPV6Address = ip
209214 } else {
210215 cloudinitNetworkConfigData .Gateway = gw
216+ cloudinitNetworkConfigData .Metric = metric
211217 cloudinitNetworkConfigData .IPAddress = ip
212218 }
213219
@@ -241,6 +247,7 @@ func getDefaultNetworkDevice(ctx context.Context, machineScope *scope.MachineSco
241247 default :
242248 config .IPV6Address = conf .IPV6Address
243249 config .Gateway6 = conf .Gateway6
250+ config .Metric6 = conf .Metric6
244251 }
245252 }
246253
@@ -279,17 +286,28 @@ func getCommonInterfaceConfig(ctx context.Context, machineScope *scope.MachineSc
279286 if err != nil {
280287 return errors .Wrapf (err , "unable to find IPAddress, device=%s" , ifname )
281288 }
289+ metric , err := findIPAddressGatewayMetric (ctx , machineScope , ipAddr )
290+ if err != nil {
291+ return errors .Wrapf (err , "error converting metric annotation, kind=%s, name=%s" , ipAddr .Spec .PoolRef .Kind , ipAddr .Spec .PoolRef .Name )
292+ }
293+
282294 ciconfig .IPAddress = IPAddressWithPrefix (ipAddr .Spec .Address , ipAddr .Spec .Prefix )
283295 ciconfig .Gateway = ipAddr .Spec .Gateway
296+ ciconfig .Metric = metric
284297 }
285298 if ifconfig .IPv6PoolRef != nil && ciconfig .IPV6Address == "" {
286299 var ifname = fmt .Sprintf ("%s-%s" , ciconfig .Name , infrav1alpha1 .DefaultSuffix + "6" )
287300 ipAddr , err := findIPAddress (ctx , machineScope , ifname )
288301 if err != nil {
289302 return errors .Wrapf (err , "unable to find IPAddress, device=%s" , ifname )
290303 }
304+ metric , err := findIPAddressGatewayMetric (ctx , machineScope , ipAddr )
305+ if err != nil {
306+ return errors .Wrapf (err , "error converting metric annotation, kind=%s, name=%s" , ipAddr .Spec .PoolRef .Kind , ipAddr .Spec .PoolRef .Name )
307+ }
291308 ciconfig .IPV6Address = IPAddressWithPrefix (ipAddr .Spec .Address , ipAddr .Spec .Prefix )
292309 ciconfig .Gateway6 = ipAddr .Spec .Gateway
310+ ciconfig .Metric6 = metric
293311 }
294312
295313 return nil
0 commit comments