Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly initialize AppNetworkStatus after invalid config was fixed #4267

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/pillar/cmd/zedrouter/appnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,29 @@ func (z *zedrouter) doAppNetworkModifyAppIntfNum(appID uuid.UUID,
}
return nil
}

// For app already deployed (before node reboot), keep using the same MAC address
// generator. Changing MAC addresses could break network config inside the app.
func (z *zedrouter) selectMACGeneratorForApp(status *types.AppNetworkStatus) error {
appKey := types.UuidToNumKey{UUID: status.UUIDandVersion.UUID}
macGenerator, _, err := z.appMACGeneratorMap.Get(appKey)
if err != nil || macGenerator == types.MACGeneratorUnspecified {
// New app or an existing app but without MAC generator ID persisted.
if z.localLegacyMACAddr {
// Use older node-scoped MAC address generator.
macGenerator = types.MACGeneratorNodeScoped
} else {
// Use newer (and preferred) globally-scoped MAC address generator.
macGenerator = types.MACGeneratorGloballyScoped
}
// Remember which MAC generator is being used for this app.
err = z.appMACGeneratorMap.Assign(appKey, macGenerator, false)
if err != nil {
err = fmt.Errorf("failed to persist MAC generator ID for app %s/%s: %v",
status.UUIDandVersion.UUID, status.DisplayName, err)
return err
}
}
status.MACGenerator = macGenerator
return nil
}
47 changes: 25 additions & 22 deletions pkg/pillar/cmd/zedrouter/pubsubhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,29 +502,12 @@ func (z *zedrouter) handleAppNetworkCreate(ctxArg interface{}, key string,
}
status.AppNum = appNum

// For app already deployed (before node reboot), keep using the same MAC address
// generator. Changing MAC addresses could break network config inside the app.
macGenerator, _, err := z.appMACGeneratorMap.Get(appNumKey)
if err != nil || macGenerator == types.MACGeneratorUnspecified {
// New app or an existing app but without MAC generator ID persisted.
if z.localLegacyMACAddr {
// Use older node-scoped MAC address generator.
macGenerator = types.MACGeneratorNodeScoped
} else {
// Use newer (and preferred) globally-scoped MAC address generator.
macGenerator = types.MACGeneratorGloballyScoped
}
// Remember which MAC generator is being used for this app.
err = z.appMACGeneratorMap.Assign(appNumKey, macGenerator, false)
if err != nil {
err = fmt.Errorf("failed to persist MAC generator ID for app %s/%s: %v",
config.UUIDandVersion.UUID, config.DisplayName, err)
z.log.Errorf("handleAppNetworkCreate(%v): %v", config.UUIDandVersion.UUID, err)
z.addAppNetworkError(&status, "handleAppNetworkCreate", err)
return
}
err = z.selectMACGeneratorForApp(&status)
if err != nil {
z.log.Errorf("handleAppNetworkCreate(%v): %v", config.UUIDandVersion.UUID, err)
z.addAppNetworkError(&status, "handleAppNetworkCreate", err)
return
}
status.MACGenerator = macGenerator
z.publishAppNetworkStatus(&status)

// Allocate application numbers on network instances.
Expand Down Expand Up @@ -585,6 +568,26 @@ func (z *zedrouter) handleAppNetworkModify(ctxArg interface{}, key string,
return
}

// Get or (less likely) allocate number to identify the application instance.
appNumKey := types.UuidToNumKey{UUID: newConfig.UUIDandVersion.UUID}
appNum, err := z.appNumAllocator.GetOrAllocate(appNumKey)
if err != nil {
err = fmt.Errorf("failed to allocate appNum for %s/%s: %v",
newConfig.UUIDandVersion.UUID, newConfig.DisplayName, err)
z.log.Errorf("handleAppNetworkModify(%v): %v", newConfig.UUIDandVersion.UUID, err)
z.addAppNetworkError(status, "handleAppNetworkModify", err)
return
}
status.AppNum = appNum

err = z.selectMACGeneratorForApp(status)
if err != nil {
z.log.Errorf("handleAppNetworkModify(%v): %v", newConfig.UUIDandVersion.UUID, err)
z.addAppNetworkError(status, "handleAppNetworkModify", err)
return
}
z.publishAppNetworkStatus(status)

// Update numbers allocated for application interfaces.
z.checkAppNetworkModifyAppIntfNums(newConfig, status)

Expand Down
Loading