Skip to content

Commit

Permalink
do not always resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-zededa committed Dec 4, 2024
1 parent 42e3e4f commit 5f34b33
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions pkg/pillar/cmd/zedrouter/networkinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,11 @@ func (z *zedrouter) getNIBridgeConfig(
}
}

func (z *zedrouter) getNIPortConfig(
status *types.NetworkInstanceStatus) (portConfigs []nireconciler.Port) {
if len(status.Ports) == 0 {
// Air-gapped
return nil
}
for _, portLL := range status.Ports {
port := z.deviceNetworkStatus.LookupPortByLogicallabel(portLL)
if port == nil {
continue
}
ntpServerIPs, ntpServerDomainsOrIPs := types.GetNTPServers(*z.deviceNetworkStatus, port.IfName)
func (z *zedrouter) attachNTPServersToPortConfigs(portConfigs []nireconciler.Port, status *types.NetworkInstanceStatus) {
for i := range portConfigs {
pc := &portConfigs[i]
ntpServerIPs, ntpServerDomainsOrIPs := types.GetNTPServers(*z.deviceNetworkStatus, pc.IfName)

ntpServers := make([]net.IP, 0, len(ntpServerDomainsOrIPs))
for _, ntpServer := range ntpServerDomainsOrIPs {
ip := net.ParseIP(ntpServer)
Expand All @@ -129,6 +122,22 @@ func (z *zedrouter) getNIPortConfig(
ntpServers = append(ntpServers, ntpServerIPs...)
generics.FilterDuplicatesFn(ntpServers, netutils.EqualIPs)

pc.NTPServers = ntpServers
}
}

func (z *zedrouter) getNIPortConfig(
status *types.NetworkInstanceStatus) (portConfigs []nireconciler.Port) {
if len(status.Ports) == 0 {
// Air-gapped
return nil
}
for _, portLL := range status.Ports {
port := z.deviceNetworkStatus.LookupPortByLogicallabel(portLL)
if port == nil {
continue
}
basicNTPServerIPs, _ := types.GetNTPServers(*z.deviceNetworkStatus, port.IfName)
portConfigs = append(portConfigs, nireconciler.Port{
LogicalLabel: port.Logicallabel,
SharedLabels: port.SharedLabels,
Expand All @@ -137,7 +146,7 @@ func (z *zedrouter) getNIPortConfig(
MTU: port.MTU,
DhcpType: port.Dhcp,
DNSServers: types.GetDNSServers(*z.deviceNetworkStatus, port.IfName),
NTPServers: ntpServers,
NTPServers: basicNTPServerIPs,
})
}
return portConfigs
Expand Down Expand Up @@ -519,8 +528,10 @@ func (z *zedrouter) updateNIRoutePort(route types.IPRouteConfig, port string,
func (z *zedrouter) doActivateNetworkInstance(config types.NetworkInstanceConfig,
status *types.NetworkInstanceStatus) {
// Create network instance inside the network stack.
bridgeConfig := z.getNIBridgeConfig(status)
z.attachNTPServersToPortConfigs(bridgeConfig.Ports, status)
niRecStatus, err := z.niReconciler.AddNI(
z.runCtx, config, z.getNIBridgeConfig(status))
z.runCtx, config, bridgeConfig)
if err != nil {
z.log.Errorf("Failed to activate network instance %s: %v", status.UUID, err)
status.ReconcileErr.SetErrorNow(err.Error())
Expand Down Expand Up @@ -564,8 +575,10 @@ func (z *zedrouter) doInactivateNetworkInstance(status *types.NetworkInstanceSta

func (z *zedrouter) doUpdateActivatedNetworkInstance(config types.NetworkInstanceConfig,
status *types.NetworkInstanceStatus) {
bridgeConfig := z.getNIBridgeConfig(status)
niRecStatus, err := z.niReconciler.UpdateNI(
z.runCtx, config, z.getNIBridgeConfig(status))
z.runCtx, config, bridgeConfig)
z.attachNTPServersToPortConfigs(bridgeConfig.Ports, status)
if err != nil {
z.log.Errorf("Failed to update activated network instance %s: %v",
status.UUID, err)
Expand Down

0 comments on commit 5f34b33

Please sign in to comment.