Skip to content

Commit b7ce09f

Browse files
authored
Add join VNET call for every AZR NC unpublish call (#2983)
* add join vnet call for every AZR nc unpublish call * add missing return * linter fix * add comment
1 parent fc933e2 commit b7ce09f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cns/restserver/api.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/Azure/azure-container-networking/cns/types"
2121
"github.com/Azure/azure-container-networking/cns/wireserver"
2222
"github.com/Azure/azure-container-networking/common"
23+
"github.com/Azure/azure-container-networking/nmagent"
2324
"github.com/pkg/errors"
2425
)
2526

@@ -1029,7 +1030,20 @@ func (service *HTTPRestService) unpublishNetworkContainer(w http.ResponseWriter,
10291030

10301031
ctx := r.Context()
10311032

1032-
if !service.isNetworkJoined(req.NetworkID) {
1033+
var unpublishBody nmagent.DeleteContainerRequest
1034+
if req.DeleteNetworkContainerRequestBody != nil {
1035+
err = json.Unmarshal(req.DeleteNetworkContainerRequestBody, &unpublishBody)
1036+
if err != nil {
1037+
http.Error(w, fmt.Sprintf("could not unmarshal delete network container body: %v", err), http.StatusBadRequest)
1038+
return
1039+
}
1040+
}
1041+
1042+
/* For AZR scenarios, if NMAgent is restarted, it loses state and does not know what VNETs to subscribe to.
1043+
As it no longer has VNET state, delete nc calls would fail. We need to add join VNET call for all AZR
1044+
nc unpublish calls just like publish nc calls.
1045+
*/
1046+
if unpublishBody.AZREnabled || !service.isNetworkJoined(req.NetworkID) {
10331047
joinResp, err := service.wsproxy.JoinNetwork(ctx, req.NetworkID) //nolint:govet // ok to shadow
10341048
if err != nil {
10351049
resp := cns.UnpublishNetworkContainerResponse{
@@ -1062,7 +1076,7 @@ func (service *HTTPRestService) unpublishNetworkContainer(w http.ResponseWriter,
10621076
}
10631077

10641078
service.setNetworkStateJoined(req.NetworkID)
1065-
logger.Printf("[Azure-CNS] joined vnet %s during nc %s unpublish. wireserver response: %v", req.NetworkID, req.NetworkContainerID, string(joinBytes))
1079+
logger.Printf("[Azure-CNS] joined vnet %s during nc %s unpublish. AZREnabled: %t, wireserver response: %v", req.NetworkID, req.NetworkContainerID, unpublishBody.AZREnabled, string(joinBytes))
10661080
}
10671081

10681082
publishResp, err := service.wsproxy.UnpublishNC(ctx, ncParams, req.DeleteNetworkContainerRequestBody)

0 commit comments

Comments
 (0)