Skip to content

Commit 2a9b132

Browse files
authored
Include body for unpublishNC calls to support AZR (#1826)
* initial delete NC changes to include body * initial delete NC changes to include body * lint error * initial delete NC changes to include body * initial delete NC changes to include body * lint error * test change * test change * add comment
1 parent 358de20 commit 2a9b132

File tree

7 files changed

+33
-21
lines changed

7 files changed

+33
-21
lines changed

cns/NetworkContainerContract.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,11 @@ func (p PublishNetworkContainerResponse) String() string {
529529

530530
// UnpublishNetworkContainerRequest specifies request to unpublish network container via NMAgent.
531531
type UnpublishNetworkContainerRequest struct {
532-
NetworkID string
533-
NetworkContainerID string
534-
JoinNetworkURL string
535-
DeleteNetworkContainerURL string
532+
NetworkID string
533+
NetworkContainerID string
534+
JoinNetworkURL string
535+
DeleteNetworkContainerURL string
536+
DeleteNetworkContainerRequestBody []byte
536537
}
537538

538539
// UnpublishNetworkContainerResponse specifies the response to unpublish network container request.

cns/fakes/wireserverproxyfake.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
type WireserverProxyFake struct {
1313
JoinNetworkFunc func(context.Context, string) (*http.Response, error)
1414
PublishNCFunc func(context.Context, cns.NetworkContainerParameters, []byte) (*http.Response, error)
15-
UnpublishNCFunc func(context.Context, cns.NetworkContainerParameters) (*http.Response, error)
15+
UnpublishNCFunc func(context.Context, cns.NetworkContainerParameters, []byte) (*http.Response, error)
1616
}
1717

1818
const defaultResponseBody = `{"httpStatusCode":"200"}`
@@ -41,9 +41,9 @@ func (w *WireserverProxyFake) PublishNC(ctx context.Context, ncParams cns.Networ
4141
return defaultResponse(), nil
4242
}
4343

44-
func (w *WireserverProxyFake) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters) (*http.Response, error) {
44+
func (w *WireserverProxyFake) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error) {
4545
if w.UnpublishNCFunc != nil {
46-
return w.UnpublishNCFunc(ctx, ncParams)
46+
return w.UnpublishNCFunc(ctx, ncParams, payload)
4747
}
4848

4949
return defaultResponse(), nil

cns/restserver/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ func (service *HTTPRestService) unpublishNetworkContainer(w http.ResponseWriter,
12981298
logger.Printf("[Azure-CNS] joined vnet %s during nc %s unpublish. wireserver response: %v", req.NetworkID, req.NetworkContainerID, string(joinBytes))
12991299
}
13001300

1301-
publishResp, err := service.wsproxy.UnpublishNC(ctx, ncParams)
1301+
publishResp, err := service.wsproxy.UnpublishNC(ctx, ncParams, req.DeleteNetworkContainerRequestBody)
13021302
if err != nil {
13031303
resp := cns.UnpublishNetworkContainerResponse{
13041304
Response: cns.Response{

cns/restserver/api_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ func TestUnpublishNCViaCNS(t *testing.T) {
955955

956956
func TestUnpublishNCViaCNS401(t *testing.T) {
957957
wsproxy := fakes.WireserverProxyFake{
958-
UnpublishNCFunc: func(_ context.Context, _ cns.NetworkContainerParameters) (*http.Response, error) {
958+
UnpublishNCFunc: func(_ context.Context, _ cns.NetworkContainerParameters, i []byte) (*http.Response, error) {
959959
return &http.Response{
960960
StatusCode: http.StatusOK,
961961
Body: io.NopCloser(bytes.NewBufferString(`{"httpStatusCode":"401"}`)),
@@ -974,10 +974,11 @@ func TestUnpublishNCViaCNS401(t *testing.T) {
974974
joinNetworkURL := "http://" + nmagentEndpoint + "/dummyVnetURL"
975975

976976
unpublishNCRequest := &cns.UnpublishNetworkContainerRequest{
977-
NetworkID: networkID,
978-
NetworkContainerID: networkContainerID,
979-
JoinNetworkURL: joinNetworkURL,
980-
DeleteNetworkContainerURL: deleteNetworkContainerURL,
977+
NetworkID: networkID,
978+
NetworkContainerID: networkContainerID,
979+
JoinNetworkURL: joinNetworkURL,
980+
DeleteNetworkContainerURL: deleteNetworkContainerURL,
981+
DeleteNetworkContainerRequestBody: []byte("{}"),
981982
}
982983

983984
var body bytes.Buffer
@@ -1035,10 +1036,11 @@ func unpublishNCViaCNS(networkID, networkContainerID, deleteNetworkContainerURL
10351036
joinNetworkURL := "http://" + nmagentEndpoint + "/dummyVnetURL"
10361037

10371038
unpublishNCRequest := &cns.UnpublishNetworkContainerRequest{
1038-
NetworkID: networkID,
1039-
NetworkContainerID: networkContainerID,
1040-
JoinNetworkURL: joinNetworkURL,
1041-
DeleteNetworkContainerURL: deleteNetworkContainerURL,
1039+
NetworkID: networkID,
1040+
NetworkContainerID: networkContainerID,
1041+
JoinNetworkURL: joinNetworkURL,
1042+
DeleteNetworkContainerURL: deleteNetworkContainerURL,
1043+
DeleteNetworkContainerRequestBody: []byte("{}"),
10421044
}
10431045

10441046
var body bytes.Buffer

cns/restserver/restserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type nmagentClient interface {
4747
type wireserverProxy interface {
4848
JoinNetwork(ctx context.Context, vnetID string) (*http.Response, error)
4949
PublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error)
50-
UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters) (*http.Response, error)
50+
UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error)
5151
}
5252

5353
// HTTPRestService represents http listener for CNS - Container Networking Service.

cns/wireserver/proxy.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ func (p *Proxy) PublishNC(ctx context.Context, ncParams cns.NetworkContainerPara
5757
return resp, nil
5858
}
5959

60-
func (p *Proxy) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters) (*http.Response, error) {
60+
func (p *Proxy) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error) {
6161
reqURL := fmt.Sprintf(unpublishNCURLFmt, p.Host, ncParams.AssociatedInterfaceID, ncParams.NCID, ncParams.AuthToken)
6262

63-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, bytes.NewBufferString(`""`))
63+
// a POST to wireserver must contain a body. For legacy purposes,
64+
// an empty json string (two quote characters) should be sent by default.
65+
body := []byte(`""`)
66+
if len(payload) > 0 {
67+
body = payload
68+
}
69+
70+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, bytes.NewBuffer(body))
6471
if err != nil {
6572
return nil, errors.Wrap(err, "wireserver proxy: unpublish nc: could not build http request")
6673
}

nmagent/requests.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ var _ Request = DeleteContainerRequest{}
278278
// DeleteContainerRequest represents all information necessary to request that
279279
// NMAgent delete a particular network container
280280
type DeleteContainerRequest struct {
281-
NCID string `json:"-"` // the Network Container ID
281+
NCID string `json:"-"` // the Network Container ID
282+
AzID uint `json:"azID"` // home AZ of the Network Container
283+
EnableAZR bool `json:"enableAZR"` // whether AZR is enabled or not
282284

283285
// PrimaryAddress is the primary customer address of the interface in the
284286
// management VNET

0 commit comments

Comments
 (0)