-
Notifications
You must be signed in to change notification settings - Fork 165
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
app number free on underlay network #2285
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -896,6 +896,7 @@ func handleAppNetworkCreate(ctxArg interface{}, key string, configArg interface{ | |
|
||
// allocate application numbers on underlay network | ||
if err := appNumsOnUNetAllocate(ctx, &config); err != nil { | ||
status.PendingAdd = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bugfix. Please do as separate PR. |
||
addError(ctx, &status, "handleAppNetworkCreate", err) | ||
return | ||
} | ||
|
@@ -1486,67 +1487,30 @@ func handleAppNetworkModify(ctxArg interface{}, key string, | |
// We need to make sure we update any network instance references which | ||
// have changed, but we need to do that when the status is not Activated, | ||
// hence the order depends on the state. | ||
if !config.Activate && status.Activated { | ||
doInactivateAppNetwork(ctx, status) | ||
checkAppNetworkModifyUNetAppNum(ctx, config, status) | ||
appNetworkDoCopyNetworksToStatus(ctx, config, status) | ||
} else if config.Activate && !status.Activated { | ||
checkAppNetworkModifyUNetAppNum(ctx, config, status) | ||
appNetworkDoCopyNetworksToStatus(ctx, config, status) | ||
doActivate(ctx, config, status) // We check any error below | ||
} else if !status.Activated { | ||
if !status.Activated { | ||
// need not handle ACL changes in deactivated state | ||
Comment on lines
+1490
to
+1491
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how these changes make the code any easier to read and understand. |
||
checkAppNetworkModifyUNetAppNum(ctx, config, status) | ||
// Just copy in config | ||
appNetworkDoCopyNetworksToStatus(ctx, config, status) | ||
} else { | ||
// during modify, copy the collect stats IP to status and | ||
// check to see if need to launch the process | ||
appCheckStatsCollect(ctx, &config, status) | ||
|
||
// Check which underlays have changes while active | ||
// that require bringing them down and up | ||
for i := range config.UnderlayNetworkList { | ||
ulNum := i + 1 | ||
log.Tracef("handleModify ulNum %d\n", ulNum) | ||
ulConfig := &config.UnderlayNetworkList[i] | ||
oldulConfig := &oldConfig.UnderlayNetworkList[i] | ||
ulStatus := &status.UnderlayNetworkList[i] | ||
if ulConfig.Network == ulStatus.Network && | ||
ulConfig.AppIPAddr.Equal(ulStatus.AppIPAddr) && | ||
ulConfig.AppMacAddr.String() == ulStatus.AppMacAddr.String() { | ||
// Save new config then process any ACL changes | ||
ulStatus.UnderlayNetworkConfig = *ulConfig | ||
doAppNetworkModifyUNetAcls(ctx, status, ulConfig, | ||
oldulConfig, ulStatus, ipsets, false) | ||
continue | ||
} | ||
appNetworkDoInactivateUnderlayNetwork(ctx, status, | ||
ulStatus, ipsets) | ||
|
||
if ulConfig.Network != ulStatus.Network { | ||
log.Functionf("checkAppNetworkModifyUNetAppNum(%v) for %s: change from %s to %s", | ||
config.UUIDandVersion, config.DisplayName, | ||
ulStatus.Network, ulConfig.Network) | ||
// update the reference to the network instance | ||
err := doAppNetworkModifyUNetAppNum(ctx, | ||
status.UUIDandVersion.UUID, | ||
ulConfig, ulStatus) | ||
if err != nil { | ||
log.Errorf("handleAppNetworkModify: AppNum failed for %s: %v", | ||
config.DisplayName, err) | ||
addError(ctx, status, "handleModify", err) | ||
} | ||
} | ||
// Save new config | ||
ulStatus.UnderlayNetworkConfig = *ulConfig | ||
|
||
err := appNetworkDoActivateUnderlayNetwork( | ||
ctx, config, status, ipsets, ulConfig, ulNum) | ||
if err != nil { | ||
// addError already done | ||
log.Errorf("handleAppNetworkModify: Underlay Network activation failed for %s: %v", | ||
config.DisplayName, err) | ||
} | ||
if config.Activate { | ||
doActivate(ctx, config, status) // We check any error below | ||
} | ||
} else { // activated | ||
if config.Activate { | ||
// during modify, copy the collect stats IP to status and | ||
// check to see if need to launch the process | ||
appCheckStatsCollect(ctx, &config, status) | ||
|
||
// handle any underlay specific change, may need to | ||
// deactivate/activate a specific underlay network for | ||
// network/addr changes | ||
doAppNetworkModifyUnderlayNetworks(ctx, status, | ||
config, oldConfig, ipsets, false) | ||
} else { | ||
// deactivate will clear ACLs also | ||
doInactivateAppNetwork(ctx, status) | ||
checkAppNetworkModifyUNetAppNum(ctx, config, status) | ||
appNetworkDoCopyNetworksToStatus(ctx, config, status) | ||
} | ||
} | ||
|
||
|
@@ -1621,6 +1585,59 @@ func doAppNetworkSanityCheckForModify(ctx *zedrouterContext, | |
return nil | ||
} | ||
|
||
// for activated/active case | ||
func doAppNetworkModifyUnderlayNetworks( | ||
ctx *zedrouterContext, | ||
status *types.AppNetworkStatus, | ||
config types.AppNetworkConfig, | ||
oldConfig types.AppNetworkConfig, | ||
ipsets []string, force bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The forice argument is unused. Are there other unused arguments? |
||
for i := range config.UnderlayNetworkList { | ||
ulNum := i + 1 | ||
log.Tracef("handleModify(%s), ulNum %d\n", config.DisplayName, ulNum) | ||
ulConfig := &config.UnderlayNetworkList[i] | ||
oldulConfig := &oldConfig.UnderlayNetworkList[i] | ||
ulStatus := &status.UnderlayNetworkList[i] | ||
if uuid.Equal(ulConfig.Network, ulStatus.Network) && | ||
ulConfig.AppIPAddr.Equal(ulStatus.AppIPAddr) && | ||
ulConfig.AppMacAddr.String() == ulStatus.AppMacAddr.String() { | ||
// Save new config then process any ACL changes | ||
ulStatus.UnderlayNetworkConfig = *ulConfig | ||
doAppNetworkModifyUNetAcls(ctx, status, ulConfig, | ||
oldulConfig, ulStatus, ipsets, false) | ||
continue | ||
} | ||
appNetworkDoInactivateUnderlayNetwork(ctx, status, | ||
ulStatus, ipsets) | ||
|
||
//TBD:XXX may be also trigger app num changes for static/dynamic ipAddr | ||
if !uuid.Equal(ulConfig.Network, ulStatus.Network) { | ||
log.Functionf("doAppNetworkModifyUnderlayNetworks(%v) for %s: change from %s to %s", | ||
config.UUIDandVersion, config.DisplayName, | ||
ulStatus.Network, ulConfig.Network) | ||
// update the reference to the network instance | ||
err := doAppNetworkModifyUNetAppNum(ctx, | ||
status.UUIDandVersion.UUID, | ||
ulConfig, ulStatus) | ||
if err != nil { | ||
log.Errorf("handleAppNetworkModify: AppNum failed for %s: %v", | ||
config.DisplayName, err) | ||
addError(ctx, status, "handleModify", err) | ||
} | ||
} | ||
// Save new config | ||
ulStatus.UnderlayNetworkConfig = *ulConfig | ||
|
||
err := appNetworkDoActivateUnderlayNetwork( | ||
ctx, config, status, ipsets, ulConfig, ulNum) | ||
if err != nil { | ||
// addError already done | ||
log.Errorf("handleAppNetworkModify: Underlay Network activation failed for %s: %v", | ||
config.DisplayName, err) | ||
} | ||
} | ||
} | ||
|
||
func doAppNetworkModifyUNetAcls( | ||
ctx *zedrouterContext, | ||
status *types.AppNetworkStatus, | ||
|
@@ -1719,9 +1736,7 @@ func doAppNetworkModifyUNetAppNum( | |
networkID := ulConfig.Network | ||
oldNetworkID := ulStatus.Network | ||
// release the app number on old network | ||
if _, err := appNumOnUNetGet(ctx, oldNetworkID, appID); err == nil { | ||
appNumOnUNetFree(ctx, oldNetworkID, appID) | ||
} | ||
appNumOnNetworkInstanceRelease(ctx, oldNetworkID, appID) | ||
// allocate an app number on new network | ||
isStatic := (ulConfig.AppIPAddr != nil) | ||
if _, err := appNumOnUNetAllocate(ctx, networkID, appID, | ||
|
@@ -1771,19 +1786,6 @@ func handleDelete(ctx *zedrouterContext, key string, | |
|
||
appNumFree(ctx, status.UUIDandVersion.UUID) | ||
appNumsOnUNetFree(ctx, status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to explain to me the difference between the abstraction provided by ipaddronunet.go and appnumsonunet.go. With your changes it is extremely hard to see where the freeing of various resources happen since there is no consistent abstraction. And if there is no such abstraction the easiest to read is the have the indivual calls at the top layer and not introduce intermediate functions; the functions should follow an intentional abstraction as supposed to just being collections of code. |
||
// Did this free up any last references against any Network Instance Status? | ||
for ulNum := 0; ulNum < len(status.UnderlayNetworkList); ulNum++ { | ||
ulStatus := &status.UnderlayNetworkList[ulNum] | ||
netstatus := lookupNetworkInstanceStatus(ctx, ulStatus.Network.String()) | ||
if netstatus != nil { | ||
if maybeNetworkInstanceDelete(ctx, netstatus) { | ||
log.Functionf("post appNumsOnUNetFree(%v) for %s deleted %s", | ||
status.UUIDandVersion, status.DisplayName, | ||
netstatus.Key()) | ||
} | ||
} | ||
} | ||
|
||
log.Functionf("handleDelete done for %s\n", status.DisplayName) | ||
} | ||
|
||
|
@@ -1922,12 +1924,6 @@ func appNetworkDoInactivateUnderlayNetwork( | |
|
||
netstatus.RemoveVif(log, ulStatus.Vif) | ||
publishNetworkInstanceStatus(ctx, netstatus) | ||
if maybeNetworkInstanceDelete(ctx, netstatus) { | ||
log.Noticef("deleted network instance %s", netstatus.Key()) | ||
} else { | ||
// publish the changes to network instance status | ||
publishNetworkInstanceStatus(ctx, netstatus) | ||
} | ||
Comment on lines
-1925
to
-1930
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you know this isn't required? |
||
} | ||
|
||
func pkillUserArgs(userName string, match string, printOnError bool) { | ||
|
@@ -2358,6 +2354,9 @@ func checkAppNetworkErrorAndStartTimer(ctx *zedrouterContext) { | |
// When hit error while creating, set a timer for 60 sec and come back to retry | ||
log.Functionf("checkAppNetworkErrorAndStartTimer: set timer\n") | ||
ctx.appNetCreateTimer = time.NewTimer(60 * time.Second) | ||
// may be multiple config entries, need not try scheduling again | ||
// just return | ||
return | ||
Comment on lines
+2357
to
+2359
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this change do in this PR? |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to do this when you didn't call appNumOnUNetFree?