fix: only set gateway if set in context (opennebula)

Fix the network config setup.

Signed-off-by: Christian WALDBILLIG <christian@waldbillig.io>
Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
Christian WALDBILLIG 2024-02-22 23:52:32 +01:00 committed by Andrey Smirnov
parent 4575dd8e74
commit c79d69c2e2
No known key found for this signature in database
GPG Key ID: FE042E3D4085A811

View File

@ -127,27 +127,29 @@ func (o *OpenNebula) ParseMetadata(st state.State, oneContextPlain []byte) (*run
},
)
// Parse gateway address and create RouteSpecSpec entry
gateway, err := netip.ParseAddr(oneContext[ifaceName+"_GATEWAY"])
if err != nil {
return nil, fmt.Errorf("failed to parse gateway ip: %w", err)
if oneContext[ifaceName+"_GATEWAY"] != "" {
// Parse gateway address and create RouteSpecSpec entry
gateway, err := netip.ParseAddr(oneContext[ifaceName+"_GATEWAY"])
if err != nil {
return nil, fmt.Errorf("failed to parse gateway ip: %w", err)
}
route := network.RouteSpecSpec{
ConfigLayer: network.ConfigPlatform,
Gateway: gateway,
OutLinkName: ifaceNameLower,
Table: nethelpers.TableMain,
Protocol: nethelpers.ProtocolStatic,
Type: nethelpers.TypeUnicast,
Family: nethelpers.FamilyInet4,
Priority: network.DefaultRouteMetric,
}
route.Normalize()
networkConfig.Routes = append(networkConfig.Routes, route)
}
route := network.RouteSpecSpec{
ConfigLayer: network.ConfigPlatform,
Gateway: gateway,
OutLinkName: ifaceNameLower,
Table: nethelpers.TableMain,
Protocol: nethelpers.ProtocolStatic,
Type: nethelpers.TypeUnicast,
Family: nethelpers.FamilyInet4,
Priority: network.DefaultRouteMetric,
}
route.Normalize()
networkConfig.Routes = append(networkConfig.Routes, route)
// Parse DNS servers
dnsServers := strings.Fields(oneContext[ifaceName+"_DNS"])