From 87d6ab088a264c162909bc6381c465b63ab68cb0 Mon Sep 17 00:00:00 2001 From: AzureAhai Date: Wed, 1 Nov 2023 13:44:27 -0700 Subject: [PATCH] Stateless CNI changes. --- cns/NetworkContainerContract.go | 2 +- cns/client/client.go | 6 +++--- network/endpoint.go | 1 + network/manager.go | 7 +++---- network/manager_mock.go | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cns/NetworkContainerContract.go b/cns/NetworkContainerContract.go index fc303dda00..5947183662 100644 --- a/cns/NetworkContainerContract.go +++ b/cns/NetworkContainerContract.go @@ -36,7 +36,7 @@ const ( PathDebugRestData = "/debug/restdata" NumberOfCPUCores = NumberOfCPUCoresPath NMAgentSupportedAPIs = NmAgentSupportedApisPath - EndpointApi = EndpointPath + EndpointAPI = EndpointPath ) // NetworkContainer Prefixes diff --git a/cns/client/client.go b/cns/client/client.go index 5966bd2a16..2ee524cfb9 100644 --- a/cns/client/client.go +++ b/cns/client/client.go @@ -45,7 +45,7 @@ var clientPaths = []string{ cns.DeleteNetworkContainer, cns.NetworkContainersURLPath, cns.GetHomeAz, - cns.EndpointApi, + cns.EndpointAPI, } type do interface { @@ -1026,7 +1026,7 @@ func (c *Client) GetHomeAz(ctx context.Context) (*cns.GetHomeAzResponse, error) // GetEndpoint calls the EndpointHandlerAPI in CNS to retrieve the state of a given EndpointID func (c *Client) GetEndpoint(ctx context.Context, endpointID string) (*restserver.GetEndpointResponse, error) { // build the request - u := c.routes[cns.EndpointApi] + u := c.routes[cns.EndpointAPI] uString := u.String() + endpointID req, err := http.NewRequestWithContext(ctx, http.MethodGet, uString, http.NoBody) if err != nil { @@ -1071,7 +1071,7 @@ func (c *Client) UpdateEndpoint(ctx context.Context, endpointID, hnsID, vethName return nil, errors.Wrap(err, "failed to encode updateEndpoint") } - u := c.routes[cns.EndpointApi] + u := c.routes[cns.EndpointAPI] uString := u.String() + endpointID req, err := http.NewRequestWithContext(ctx, http.MethodPatch, uString, &body) if err != nil { diff --git a/network/endpoint.go b/network/endpoint.go index ab873e92d0..13c373050d 100644 --- a/network/endpoint.go +++ b/network/endpoint.go @@ -91,6 +91,7 @@ type EndpointInfo struct { NATInfo []policy.NATInfo NICType cns.NICType SkipDefaultRoutes bool + HNSEndpointID string } // RouteInfo contains information about an IP route. diff --git a/network/manager.go b/network/manager.go index 853b309a86..3d86d42319 100644 --- a/network/manager.go +++ b/network/manager.go @@ -98,7 +98,7 @@ type NetworkManager interface { FindNetworkIDFromNetNs(netNs string) (string, error) GetNumEndpointsByContainerID(containerID string) int - CreateEndpoint(client apipaClient, networkID string, epInfo *EndpointInfo) error + CreateEndpoint(client apipaClient, networkID string, epInfo []*EndpointInfo) error DeleteEndpoint(networkID string, endpointID string, epInfo *EndpointInfo) error GetEndpointInfo(networkID string, endpointID string) (*EndpointInfo, error) GetAllEndpoints(networkID string) (map[string]*EndpointInfo, error) @@ -386,8 +386,7 @@ func (nm *networkManager) CreateEndpoint(cli apipaClient, networkID string, epIn epInfo[0].Data[VlanIDKey] = nw.VlanId } } - - _, err = nw.newEndpoint(cli, nm.netlink, nm.plClient, nm.netio, nm.nsClient, epInfo) + ep, err := nw.newEndpoint(cli, nm.netlink, nm.plClient, nm.netio, nm.nsClient, epInfo) if err != nil { return err } @@ -467,7 +466,7 @@ func (nm *networkManager) DeleteEndpointState(networkID string, epInfo *Endpoint NetworkContainerID: epInfo.Id, } logger.Info("Deleting endpoint with", zap.String("Endpoint Info: ", epInfo.PrettyString()), zap.String("HNISID : ", ep.HnsId)) - return nw.deleteEndpointImpl(netlink.NewNetlink(), platform.NewExecClient(logger), nil, ep) + return nw.deleteEndpointImpl(netlink.NewNetlink(), platform.NewExecClient(logger), nil, nil, ep) } // GetEndpointInfo returns information about the given endpoint. diff --git a/network/manager_mock.go b/network/manager_mock.go index f82c302828..04773131c0 100644 --- a/network/manager_mock.go +++ b/network/manager_mock.go @@ -66,7 +66,7 @@ func (nm *MockNetworkManager) CreateEndpoint(_ apipaClient, _ string, epInfos [] } // DeleteEndpoint mock -func (nm *MockNetworkManager) DeleteEndpoint(networkID string, endpointID string, ep *EndpointInfo) error { +func (nm *MockNetworkManager) DeleteEndpoint(_, endpointID string, ep *EndpointInfo) error { delete(nm.TestEndpointInfoMap, endpointID) return nil }