Skip to content

Commit

Permalink
CNS - Remove vnet join cache check during NC publish (#1946)
Browse files Browse the repository at this point in the history
removing vnet join cache check during nc publish, such that join is always attempted during publish. this is the classic behavior circa cns v1.4.37
  • Loading branch information
ramiro-gamarra authored May 5, 2023
1 parent 7f223f2 commit a14eb1f
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions cns/restserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,42 +1206,40 @@ func (service *HTTPRestService) publishNetworkContainer(w http.ResponseWriter, r

ctx := r.Context()

if !service.isNetworkJoined(req.NetworkID) {
joinResp, err := service.wsproxy.JoinNetwork(ctx, req.NetworkID) //nolint:govet // ok to shadow
if err != nil {
resp := cns.PublishNetworkContainerResponse{
Response: cns.Response{
ReturnCode: types.NetworkJoinFailed,
Message: fmt.Sprintf("failed to join network %s: %v", req.NetworkID, err),
},
PublishErrorStr: err.Error(),
}
respondJSON(w, http.StatusOK, resp) // legacy behavior
logger.Response(service.Name, resp, resp.Response.ReturnCode, err)
return
joinResp, err := service.wsproxy.JoinNetwork(ctx, req.NetworkID) //nolint:govet // ok to shadow
if err != nil {
resp := cns.PublishNetworkContainerResponse{
Response: cns.Response{
ReturnCode: types.NetworkJoinFailed,
Message: fmt.Sprintf("failed to join network %s: %v", req.NetworkID, err),
},
PublishErrorStr: err.Error(),
}
respondJSON(w, http.StatusOK, resp) // legacy behavior
logger.Response(service.Name, resp, resp.Response.ReturnCode, err)
return
}

joinBytes, _ := io.ReadAll(joinResp.Body)
_ = joinResp.Body.Close()
joinBytes, _ := io.ReadAll(joinResp.Body)
_ = joinResp.Body.Close()

if joinResp.StatusCode != http.StatusOK {
resp := cns.PublishNetworkContainerResponse{
Response: cns.Response{
ReturnCode: types.NetworkJoinFailed,
Message: fmt.Sprintf("failed to join network %s. did not get 200 from wireserver", req.NetworkID),
},
PublishStatusCode: joinResp.StatusCode,
PublishResponseBody: joinBytes,
}
respondJSON(w, http.StatusOK, resp) // legacy behavior
logger.Response(service.Name, resp, resp.Response.ReturnCode, nil)
return
if joinResp.StatusCode != http.StatusOK {
resp := cns.PublishNetworkContainerResponse{
Response: cns.Response{
ReturnCode: types.NetworkJoinFailed,
Message: fmt.Sprintf("failed to join network %s. did not get 200 from wireserver", req.NetworkID),
},
PublishStatusCode: joinResp.StatusCode,
PublishResponseBody: joinBytes,
}

service.setNetworkStateJoined(req.NetworkID)
logger.Printf("[Azure-CNS] joined vnet %s during nc %s publish. wireserver response: %v", req.NetworkID, req.NetworkContainerID, string(joinBytes))
respondJSON(w, http.StatusOK, resp) // legacy behavior
logger.Response(service.Name, resp, resp.Response.ReturnCode, nil)
return
}

service.setNetworkStateJoined(req.NetworkID)
logger.Printf("[Azure-CNS] joined vnet %s during nc %s publish. wireserver response: %v", req.NetworkID, req.NetworkContainerID, string(joinBytes))

publishResp, err := service.wsproxy.PublishNC(ctx, ncParams, req.CreateNetworkContainerRequestBody)
if err != nil {
resp := cns.PublishNetworkContainerResponse{
Expand Down

0 comments on commit a14eb1f

Please sign in to comment.