From dfa3c468c19ed7c684a625020cf7d72122373462 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Thu, 1 Oct 2020 12:42:10 -0700 Subject: [PATCH 01/11] fix cni error --- cni/network/multitenancy.go | 18 ++++++++--------- cni/network/network.go | 36 ++++++++++++++++++++++------------ cni/network/network_windows.go | 24 ++++++++++++++++++----- cns/cnsclient/cnsclient.go | 29 ++++++++++++++++++--------- 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index 4472f63e63..a715e63807 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -51,7 +51,7 @@ func getContainerNetworkConfiguration( nwCfg *cni.NetworkConfig, podName string, podNamespace string, - ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) { + ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, bool, error) { var podNameWithoutSuffix string if !nwCfg.EnableExactMatchForPodName { @@ -68,24 +68,24 @@ func getContainerNetworkConfigurationInternal( address string, namespace string, podName string, - ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) { + ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, bool, error) { cnsClient, err := cnsclient.GetCnsClient() if err != nil { log.Printf("Failed to get CNS client. Error: %v", err) - return nil, nil, net.IPNet{}, err + return nil, nil, net.IPNet{}, false, err } podInfo := cns.KubernetesPodInfo{PodName: podName, PodNamespace: namespace} orchestratorContext, err := json.Marshal(podInfo) if err != nil { log.Printf("Marshalling KubernetesPodInfo failed with %v", err) - return nil, nil, net.IPNet{}, err + return nil, nil, net.IPNet{}, false, err } - networkConfig, err := cnsClient.GetNetworkConfiguration(orchestratorContext) + networkConfig, isNotFoundError, err := cnsClient.GetNetworkConfiguration(orchestratorContext) if err != nil { log.Printf("GetNetworkConfiguration failed with %v", err) - return nil, nil, net.IPNet{}, err + return nil, nil, net.IPNet{}, isNotFoundError, err } log.Printf("Network config received from cns %+v", networkConfig) @@ -94,10 +94,10 @@ func getContainerNetworkConfigurationInternal( if subnetPrefix == nil { errBuf := fmt.Sprintf("Interface not found for this ip %v", networkConfig.PrimaryInterfaceIdentifier) log.Printf(errBuf) - return nil, nil, net.IPNet{}, fmt.Errorf(errBuf) + return nil, nil, net.IPNet{}, true, fmt.Errorf(errBuf) } - return convertToCniResult(networkConfig, ifName), networkConfig, *subnetPrefix, nil + return convertToCniResult(networkConfig, ifName), networkConfig, *subnetPrefix, false, nil } func convertToCniResult(networkConfig *cns.GetNetworkContainerResponse, ifName string) *cniTypesCurr.Result { @@ -211,7 +211,7 @@ func GetMultiTenancyCNIResult( ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, *cniTypesCurr.Result, error) { if nwCfg.MultiTenancy { - result, cnsNetworkConfig, subnetPrefix, err := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) + result, cnsNetworkConfig, subnetPrefix, _, err := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) if err != nil { log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v", k8sPodName, k8sNamespace, err) return nil, nil, net.IPNet{}, nil, err diff --git a/cni/network/network.go b/cni/network/network.go index 093d812426..be84dd9499 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -385,7 +385,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { log.Printf("Result from multitenancy %+v", result) // Initialize values from network config. - networkId, err := getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg) + networkId, _, err := getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg) if err != nil { log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) return err @@ -709,7 +709,8 @@ func (plugin *netPlugin) Get(args *cniSkel.CmdArgs) error { } // Initialize values from network config. - if networkId, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg); err != nil { + if networkId, _, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg); err != nil { + // TODO: Ideally we should return from here only. log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) } @@ -754,15 +755,16 @@ func (plugin *netPlugin) Get(args *cniSkel.CmdArgs) error { // Delete handles CNI delete commands. func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error { var ( - err error - nwCfg *cni.NetworkConfig - k8sPodName string - k8sNamespace string - networkId string - nwInfo network.NetworkInfo - epInfo *network.EndpointInfo - cniMetric telemetry.AIMetric - msg string + err error + nwCfg *cni.NetworkConfig + k8sPodName string + k8sNamespace string + networkId string + nwInfo network.NetworkInfo + epInfo *network.EndpointInfo + cniMetric telemetry.AIMetric + msg string + isNotFoundErr bool ) startTime := time.Now() @@ -796,8 +798,16 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error { } // Initialize values from network config. - if networkId, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg); err != nil { + networkId, isNotFoundErr, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg) + + // If error is not found error, then we ignore it, to comply with CNI SPEC. + if err != nil { log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) + + if !isNotFoundErr { + err = plugin.Errorf("Failed to extract network name from network config. error: %v", err) + return err + } } endpointId := GetEndpointID(args) @@ -1002,7 +1012,7 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error { return plugin.Errorf(err.Error()) } - if targetNetworkConfig, err = cnsClient.GetNetworkConfiguration(orchestratorContext); err != nil { + if targetNetworkConfig, _, err = cnsClient.GetNetworkConfiguration(orchestratorContext); err != nil { log.Printf("GetNetworkConfiguration failed with %v", err) return plugin.Errorf(err.Error()) } diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index ab4b7c19ab..81abdf0447 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -153,19 +153,33 @@ func updateSubnetPrefix(cnsNwConfig *cns.GetNetworkContainerResponse, subnetPref return nil } -func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (networkName string, err error) { +func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (string, bool, error) { + var ( + networkName string + err error + isNotFoundErr bool + cnsNetworkConfig *cns.GetNetworkContainerResponse + ) + networkName = nwCfg.Name err = nil + isNotFoundErr = false + if nwCfg.MultiTenancy { determineWinVer() if len(strings.TrimSpace(podName)) == 0 || len(strings.TrimSpace(podNs)) == 0 { err = fmt.Errorf("POD info cannot be empty. PodName: %s, PodNamespace: %s", podName, podNs) - return + return networkName, isNotFoundErr, err } - _, cnsNetworkConfig, _, err := getContainerNetworkConfiguration(nwCfg, podName, podNs, ifName) + _, cnsNetworkConfig, _, isNotFoundErr, err = getContainerNetworkConfiguration(nwCfg, podName, podNs, ifName) if err != nil { - log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v", podName, podNs, err) + log.Printf( + "GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v, isNotFoundErr: %v", + podName, + podNs, + err, + isNotFoundErr) } else { var subnet net.IPNet if err = updateSubnetPrefix(cnsNetworkConfig, &subnet); err == nil { @@ -177,7 +191,7 @@ func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (ne } } - return + return networkName, isNotFoundErr, err } func setupInfraVnetRoutingForMultitenancy( diff --git a/cns/cnsclient/cnsclient.go b/cns/cnsclient/cnsclient.go index 06954565d8..bb92558b9d 100644 --- a/cns/cnsclient/cnsclient.go +++ b/cns/cnsclient/cnsclient.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/Azure/azure-container-networking/cns" + "github.com/Azure/azure-container-networking/cns/restserver" "github.com/Azure/azure-container-networking/log" ) @@ -51,8 +52,14 @@ func GetCnsClient() (*CNSClient, error) { } // GetNetworkConfiguration Request to get network config. -func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) (*cns.GetNetworkContainerResponse, error) { - var body bytes.Buffer +func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) ( + *cns.GetNetworkContainerResponse, bool, error) { + var ( + body bytes.Buffer + isNotFoundError bool + ) + + isNotFoundError = false httpc := &http.Client{} url := cnsClient.connectionURL + cns.GetNetworkContainerByOrchestratorContext @@ -65,13 +72,13 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) err := json.NewEncoder(&body).Encode(payload) if err != nil { log.Errorf("encoding json failed with %v", err) - return nil, err + return nil, isNotFoundError, err } res, err := httpc.Post(url, contentTypeJSON, &body) if err != nil { log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error()) - return nil, err + return nil, isNotFoundError, err } defer res.Body.Close() @@ -79,7 +86,7 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) if res.StatusCode != http.StatusOK { errMsg := fmt.Sprintf("[Azure CNSClient] GetNetworkConfiguration invalid http status code: %v", res.StatusCode) log.Errorf(errMsg) - return nil, fmt.Errorf(errMsg) + return nil, isNotFoundError, fmt.Errorf(errMsg) } var resp cns.GetNetworkContainerResponse @@ -87,15 +94,19 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) err = json.NewDecoder(res.Body).Decode(&resp) if err != nil { log.Errorf("[Azure CNSClient] Error received while parsing GetNetworkConfiguration response resp:%v err:%v", res.Body, err.Error()) - return nil, err + return nil, isNotFoundError, err } if resp.Response.ReturnCode != 0 { - log.Errorf("[Azure CNSClient] GetNetworkConfiguration received error response :%v", resp.Response.Message) - return nil, fmt.Errorf(resp.Response.Message) + isNotFoundError = (resp.Response.ReturnCode == restserver.UnknownContainerID) + log.Errorf( + "[Azure CNSClient] GetNetworkConfiguration received error response :%v , isNotFoundError : %v", + resp.Response.Message, + isNotFoundError) + return nil, isNotFoundError, fmt.Errorf(resp.Response.Message) } - return &resp, nil + return &resp, isNotFoundError, nil } // CreateHostNCApipaEndpoint creates an endpoint in APIPA network for host container connectivity. From 3180ab1eb18fb55b18276d0ef5dea29542314dac Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Thu, 1 Oct 2020 19:55:21 -0700 Subject: [PATCH 02/11] fix linux build --- cni/network/network_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cni/network/network_linux.go b/cni/network/network_linux.go index a8dfda1474..b37252179b 100644 --- a/cni/network/network_linux.go +++ b/cni/network/network_linux.go @@ -134,6 +134,6 @@ func updateSubnetPrefix(cnsNetworkConfig *cns.GetNetworkContainerResponse, subne return nil } -func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (string, error) { - return nwCfg.Name, nil +func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (string, bool, error) { + return nwCfg.Name, false, nil } From 1207d16ce27e73da68b1a52a49f5e873ea75510d Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Thu, 8 Oct 2020 17:47:47 -0700 Subject: [PATCH 03/11] Address raimro feedback --- cni/network/multitenancy.go | 27 ++++++++++++++------------- cni/network/network.go | 5 +++-- cni/network/network_windows.go | 8 ++++++-- cns/cnsclient/cnsclient.go | 25 +++++++++++++------------ 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index a715e63807..fd7794b8da 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -11,6 +11,7 @@ import ( "github.com/Azure/azure-container-networking/cni" "github.com/Azure/azure-container-networking/cns" "github.com/Azure/azure-container-networking/cns/cnsclient" + "github.com/Azure/azure-container-networking/cns/restserver" "github.com/Azure/azure-container-networking/common" "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/network" @@ -51,7 +52,7 @@ func getContainerNetworkConfiguration( nwCfg *cni.NetworkConfig, podName string, podNamespace string, - ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, bool, error) { + ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, *cnsclient.CNSClientError) { var podNameWithoutSuffix string if !nwCfg.EnableExactMatchForPodName { @@ -68,24 +69,24 @@ func getContainerNetworkConfigurationInternal( address string, namespace string, podName string, - ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, bool, error) { + ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, *cnsclient.CNSClientError) { cnsClient, err := cnsclient.GetCnsClient() if err != nil { log.Printf("Failed to get CNS client. Error: %v", err) - return nil, nil, net.IPNet{}, false, err + return nil, nil, net.IPNet{}, &cnsclient.CNSClientError{restserver.UnexpectedError, err} } podInfo := cns.KubernetesPodInfo{PodName: podName, PodNamespace: namespace} orchestratorContext, err := json.Marshal(podInfo) if err != nil { log.Printf("Marshalling KubernetesPodInfo failed with %v", err) - return nil, nil, net.IPNet{}, false, err + return nil, nil, net.IPNet{}, &cnsclient.CNSClientError{restserver.UnexpectedError, err} } - networkConfig, isNotFoundError, err := cnsClient.GetNetworkConfiguration(orchestratorContext) + networkConfig, cnsClientErr := cnsClient.GetNetworkConfiguration(orchestratorContext) if err != nil { log.Printf("GetNetworkConfiguration failed with %v", err) - return nil, nil, net.IPNet{}, isNotFoundError, err + return nil, nil, net.IPNet{}, cnsClientErr } log.Printf("Network config received from cns %+v", networkConfig) @@ -94,10 +95,10 @@ func getContainerNetworkConfigurationInternal( if subnetPrefix == nil { errBuf := fmt.Sprintf("Interface not found for this ip %v", networkConfig.PrimaryInterfaceIdentifier) log.Printf(errBuf) - return nil, nil, net.IPNet{}, true, fmt.Errorf(errBuf) + return nil, nil, net.IPNet{}, &cnsclient.CNSClientError{restserver.UnexpectedError, fmt.Errorf(errBuf)} } - return convertToCniResult(networkConfig, ifName), networkConfig, *subnetPrefix, false, nil + return convertToCniResult(networkConfig, ifName), networkConfig, *subnetPrefix, nil } func convertToCniResult(networkConfig *cns.GetNetworkContainerResponse, ifName string) *cniTypesCurr.Result { @@ -211,10 +212,10 @@ func GetMultiTenancyCNIResult( ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, *cniTypesCurr.Result, error) { if nwCfg.MultiTenancy { - result, cnsNetworkConfig, subnetPrefix, _, err := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) - if err != nil { - log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v", k8sPodName, k8sNamespace, err) - return nil, nil, net.IPNet{}, nil, err + result, cnsNetworkConfig, subnetPrefix, cnsClienterr := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) + if cnsClienterr != nil { + log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %+v", k8sPodName, k8sNamespace, cnsClienterr) + return nil, nil, net.IPNet{}, nil, cnsClienterr.Err } log.Printf("PrimaryInterfaceIdentifier :%v", subnetPrefix.IP.String()) @@ -222,7 +223,7 @@ func GetMultiTenancyCNIResult( if checkIfSubnetOverlaps(enableInfraVnet, nwCfg, cnsNetworkConfig) { buf := fmt.Sprintf("InfraVnet %v overlaps with customerVnet %+v", nwCfg.InfraVnetAddressSpace, cnsNetworkConfig.CnetAddressSpace) log.Printf(buf) - err = errors.New(buf) + err := errors.New(buf) return nil, nil, net.IPNet{}, nil, err } diff --git a/cni/network/network.go b/cni/network/network.go index be84dd9499..be0ed1b4bd 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -910,6 +910,7 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error { orchestratorContext []byte targetNetworkConfig *cns.GetNetworkContainerResponse cniMetric telemetry.AIMetric + cnsErr *cnsclient.CNSClientError ) startTime := time.Now() @@ -1012,9 +1013,9 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error { return plugin.Errorf(err.Error()) } - if targetNetworkConfig, _, err = cnsClient.GetNetworkConfiguration(orchestratorContext); err != nil { + if targetNetworkConfig, cnsErr = cnsClient.GetNetworkConfiguration(orchestratorContext); err != nil { log.Printf("GetNetworkConfiguration failed with %v", err) - return plugin.Errorf(err.Error()) + return plugin.Errorf(cnsErr.Err.Error()) } log.Printf("Network config received from cns for [name=%v, namespace=%v] is as follows -> %+v", k8sPodName, k8sNamespace, targetNetworkConfig) diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index 81abdf0447..9eb619c7cc 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -11,6 +11,8 @@ import ( "github.com/Azure/azure-container-networking/cni" "github.com/Azure/azure-container-networking/cns" + "github.com/Azure/azure-container-networking/cns/cnsclient" + "github.com/Azure/azure-container-networking/cns/restserver" "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/network" "github.com/Azure/azure-container-networking/network/policy" @@ -159,6 +161,7 @@ func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (st err error isNotFoundErr bool cnsNetworkConfig *cns.GetNetworkContainerResponse + cnsClientError *cnsclient.CNSClientError ) networkName = nwCfg.Name @@ -172,8 +175,9 @@ func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (st return networkName, isNotFoundErr, err } - _, cnsNetworkConfig, _, isNotFoundErr, err = getContainerNetworkConfiguration(nwCfg, podName, podNs, ifName) - if err != nil { + _, cnsNetworkConfig, _, cnsClientError = getContainerNetworkConfiguration(nwCfg, podName, podNs, ifName) + if cnsClientError != nil { + isNotFoundErr = (cnsClientError.Code == restserver.UnknownContainerID) log.Printf( "GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v, isNotFoundErr: %v", podName, diff --git a/cns/cnsclient/cnsclient.go b/cns/cnsclient/cnsclient.go index bb92558b9d..23f8ac33fb 100644 --- a/cns/cnsclient/cnsclient.go +++ b/cns/cnsclient/cnsclient.go @@ -25,6 +25,11 @@ var ( cnsClient *CNSClient ) +type CNSClientError struct { + Code int + Err error +} + // InitCnsClient initializes new cns client and returns the object func InitCnsClient(url string) (*CNSClient, error) { if cnsClient == nil { @@ -53,14 +58,12 @@ func GetCnsClient() (*CNSClient, error) { // GetNetworkConfiguration Request to get network config. func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) ( - *cns.GetNetworkContainerResponse, bool, error) { + *cns.GetNetworkContainerResponse, *CNSClientError) { var ( body bytes.Buffer isNotFoundError bool ) - isNotFoundError = false - httpc := &http.Client{} url := cnsClient.connectionURL + cns.GetNetworkContainerByOrchestratorContext log.Printf("GetNetworkConfiguration url %v", url) @@ -72,21 +75,20 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) err := json.NewEncoder(&body).Encode(payload) if err != nil { log.Errorf("encoding json failed with %v", err) - return nil, isNotFoundError, err + return nil, &CNSClientError{restserver.UnexpectedError, err} } res, err := httpc.Post(url, contentTypeJSON, &body) if err != nil { log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error()) - return nil, isNotFoundError, err + return nil, &CNSClientError{restserver.UnexpectedError, err} } defer res.Body.Close() if res.StatusCode != http.StatusOK { - errMsg := fmt.Sprintf("[Azure CNSClient] GetNetworkConfiguration invalid http status code: %v", res.StatusCode) - log.Errorf(errMsg) - return nil, isNotFoundError, fmt.Errorf(errMsg) + log.Errorf("[Azure CNSClient] GetNetworkConfiguration invalid http status code: %v", res.StatusCode) + return nil, &CNSClientError{restserver.UnexpectedError, err} } var resp cns.GetNetworkContainerResponse @@ -94,19 +96,18 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) err = json.NewDecoder(res.Body).Decode(&resp) if err != nil { log.Errorf("[Azure CNSClient] Error received while parsing GetNetworkConfiguration response resp:%v err:%v", res.Body, err.Error()) - return nil, isNotFoundError, err + return nil, &CNSClientError{restserver.UnexpectedError, err} } if resp.Response.ReturnCode != 0 { - isNotFoundError = (resp.Response.ReturnCode == restserver.UnknownContainerID) log.Errorf( "[Azure CNSClient] GetNetworkConfiguration received error response :%v , isNotFoundError : %v", resp.Response.Message, isNotFoundError) - return nil, isNotFoundError, fmt.Errorf(resp.Response.Message) + return nil, &CNSClientError{resp.Response.ReturnCode, err} } - return &resp, isNotFoundError, nil + return &resp, nil } // CreateHostNCApipaEndpoint creates an endpoint in APIPA network for host container connectivity. From e61fe1d421887d5ab13bbed039c8aed267bba7d9 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Fri, 9 Oct 2020 11:56:46 -0700 Subject: [PATCH 04/11] Refactring --- cni/network/multitenancy.go | 15 +++++++------- cni/network/network.go | 36 +++++++++++++++++----------------- cni/network/network_windows.go | 21 +++++++------------- cns/cnsclient/cnsclient.go | 34 ++++++++++++++++++++------------ cns/cnsclient/error.go | 22 +++++++++++++++++++++ 5 files changed, 75 insertions(+), 53 deletions(-) create mode 100644 cns/cnsclient/error.go diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index fd7794b8da..d7fb08d006 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -11,7 +11,6 @@ import ( "github.com/Azure/azure-container-networking/cni" "github.com/Azure/azure-container-networking/cns" "github.com/Azure/azure-container-networking/cns/cnsclient" - "github.com/Azure/azure-container-networking/cns/restserver" "github.com/Azure/azure-container-networking/common" "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/network" @@ -52,7 +51,7 @@ func getContainerNetworkConfiguration( nwCfg *cni.NetworkConfig, podName string, podNamespace string, - ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, *cnsclient.CNSClientError) { + ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) { var podNameWithoutSuffix string if !nwCfg.EnableExactMatchForPodName { @@ -69,18 +68,18 @@ func getContainerNetworkConfigurationInternal( address string, namespace string, podName string, - ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, *cnsclient.CNSClientError) { - cnsClient, err := cnsclient.GetCnsClient() + ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) { + cnsClient, err := cnsclient.GetCnsClientEx() if err != nil { log.Printf("Failed to get CNS client. Error: %v", err) - return nil, nil, net.IPNet{}, &cnsclient.CNSClientError{restserver.UnexpectedError, err} + return nil, nil, net.IPNet{}, err } podInfo := cns.KubernetesPodInfo{PodName: podName, PodNamespace: namespace} orchestratorContext, err := json.Marshal(podInfo) if err != nil { log.Printf("Marshalling KubernetesPodInfo failed with %v", err) - return nil, nil, net.IPNet{}, &cnsclient.CNSClientError{restserver.UnexpectedError, err} + return nil, nil, net.IPNet{}, err } networkConfig, cnsClientErr := cnsClient.GetNetworkConfiguration(orchestratorContext) @@ -95,7 +94,7 @@ func getContainerNetworkConfigurationInternal( if subnetPrefix == nil { errBuf := fmt.Sprintf("Interface not found for this ip %v", networkConfig.PrimaryInterfaceIdentifier) log.Printf(errBuf) - return nil, nil, net.IPNet{}, &cnsclient.CNSClientError{restserver.UnexpectedError, fmt.Errorf(errBuf)} + return nil, nil, net.IPNet{}, fmt.Errorf(errBuf) } return convertToCniResult(networkConfig, ifName), networkConfig, *subnetPrefix, nil @@ -215,7 +214,7 @@ func GetMultiTenancyCNIResult( result, cnsNetworkConfig, subnetPrefix, cnsClienterr := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) if cnsClienterr != nil { log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %+v", k8sPodName, k8sNamespace, cnsClienterr) - return nil, nil, net.IPNet{}, nil, cnsClienterr.Err + return nil, nil, net.IPNet{}, nil, cnsClienterr } log.Printf("PrimaryInterfaceIdentifier :%v", subnetPrefix.IP.String()) diff --git a/cni/network/network.go b/cni/network/network.go index be0ed1b4bd..eeb50f399c 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -5,6 +5,7 @@ package network import ( "encoding/json" + "errors" "fmt" "io/ioutil" "net" @@ -385,7 +386,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { log.Printf("Result from multitenancy %+v", result) // Initialize values from network config. - networkId, _, err := getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg) + networkId, err := getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg) if err != nil { log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) return err @@ -709,7 +710,7 @@ func (plugin *netPlugin) Get(args *cniSkel.CmdArgs) error { } // Initialize values from network config. - if networkId, _, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg); err != nil { + if networkId, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg); err != nil { // TODO: Ideally we should return from here only. log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) } @@ -755,16 +756,15 @@ func (plugin *netPlugin) Get(args *cniSkel.CmdArgs) error { // Delete handles CNI delete commands. func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error { var ( - err error - nwCfg *cni.NetworkConfig - k8sPodName string - k8sNamespace string - networkId string - nwInfo network.NetworkInfo - epInfo *network.EndpointInfo - cniMetric telemetry.AIMetric - msg string - isNotFoundErr bool + err error + nwCfg *cni.NetworkConfig + k8sPodName string + k8sNamespace string + networkId string + nwInfo network.NetworkInfo + epInfo *network.EndpointInfo + cniMetric telemetry.AIMetric + msg string ) startTime := time.Now() @@ -798,14 +798,15 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error { } // Initialize values from network config. - networkId, isNotFoundErr, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg) + networkId, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg) // If error is not found error, then we ignore it, to comply with CNI SPEC. if err != nil { log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) - if !isNotFoundErr { - err = plugin.Errorf("Failed to extract network name from network config. error: %v", err) + var cnsError *cnsclient.CNSClientError + if errors.As(err, &cnsError) && cnsError.IsNotFoundError() { + err = plugin.Errorf("Failed to extract network name from network config. error: %v", cnsError) return err } } @@ -910,7 +911,6 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error { orchestratorContext []byte targetNetworkConfig *cns.GetNetworkContainerResponse cniMetric telemetry.AIMetric - cnsErr *cnsclient.CNSClientError ) startTime := time.Now() @@ -1013,9 +1013,9 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error { return plugin.Errorf(err.Error()) } - if targetNetworkConfig, cnsErr = cnsClient.GetNetworkConfiguration(orchestratorContext); err != nil { + if targetNetworkConfig, err = cnsClient.GetNetworkConfiguration(orchestratorContext); err != nil { log.Printf("GetNetworkConfiguration failed with %v", err) - return plugin.Errorf(cnsErr.Err.Error()) + return plugin.Errorf(err.Error()) } log.Printf("Network config received from cns for [name=%v, namespace=%v] is as follows -> %+v", k8sPodName, k8sNamespace, targetNetworkConfig) diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index 9eb619c7cc..5aad6b526d 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -11,8 +11,6 @@ import ( "github.com/Azure/azure-container-networking/cni" "github.com/Azure/azure-container-networking/cns" - "github.com/Azure/azure-container-networking/cns/cnsclient" - "github.com/Azure/azure-container-networking/cns/restserver" "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/network" "github.com/Azure/azure-container-networking/network/policy" @@ -155,35 +153,30 @@ func updateSubnetPrefix(cnsNwConfig *cns.GetNetworkContainerResponse, subnetPref return nil } -func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (string, bool, error) { +func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (string, error) { var ( networkName string err error - isNotFoundErr bool cnsNetworkConfig *cns.GetNetworkContainerResponse - cnsClientError *cnsclient.CNSClientError ) networkName = nwCfg.Name err = nil - isNotFoundErr = false if nwCfg.MultiTenancy { determineWinVer() if len(strings.TrimSpace(podName)) == 0 || len(strings.TrimSpace(podNs)) == 0 { err = fmt.Errorf("POD info cannot be empty. PodName: %s, PodNamespace: %s", podName, podNs) - return networkName, isNotFoundErr, err + return networkName, err } - _, cnsNetworkConfig, _, cnsClientError = getContainerNetworkConfiguration(nwCfg, podName, podNs, ifName) - if cnsClientError != nil { - isNotFoundErr = (cnsClientError.Code == restserver.UnknownContainerID) + _, cnsNetworkConfig, _, err = getContainerNetworkConfiguration(nwCfg, podName, podNs, ifName) + if err != nil { log.Printf( - "GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v, isNotFoundErr: %v", + "GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v", podName, podNs, - err, - isNotFoundErr) + err) } else { var subnet net.IPNet if err = updateSubnetPrefix(cnsNetworkConfig, &subnet); err == nil { @@ -195,7 +188,7 @@ func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (st } } - return networkName, isNotFoundErr, err + return networkName, err } func setupInfraVnetRoutingForMultitenancy( diff --git a/cns/cnsclient/cnsclient.go b/cns/cnsclient/cnsclient.go index 23f8ac33fb..de60fa72dc 100644 --- a/cns/cnsclient/cnsclient.go +++ b/cns/cnsclient/cnsclient.go @@ -25,11 +25,6 @@ var ( cnsClient *CNSClient ) -type CNSClientError struct { - Code int - Err error -} - // InitCnsClient initializes new cns client and returns the object func InitCnsClient(url string) (*CNSClient, error) { if cnsClient == nil { @@ -56,12 +51,24 @@ func GetCnsClient() (*CNSClient, error) { return cnsClient, err } +// GetCnsClientEx returns the cns client object and encapsulates the error as CNSClientError +func GetCnsClientEx() (*CNSClient, error) { + var err error + + if cnsClient == nil { + err = &CNSClientError{ + restserver.UnexpectedError, + fmt.Errorf("[Azure CNSClient] CNS Client not initialized")} + } + + return cnsClient, err +} + // GetNetworkConfiguration Request to get network config. func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) ( - *cns.GetNetworkContainerResponse, *CNSClientError) { + *cns.GetNetworkContainerResponse, error) { var ( - body bytes.Buffer - isNotFoundError bool + body bytes.Buffer ) httpc := &http.Client{} @@ -87,8 +94,9 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) defer res.Body.Close() if res.StatusCode != http.StatusOK { - log.Errorf("[Azure CNSClient] GetNetworkConfiguration invalid http status code: %v", res.StatusCode) - return nil, &CNSClientError{restserver.UnexpectedError, err} + errMsg := fmt.Sprintf("[Azure CNSClient] GetNetworkConfiguration invalid http status code: %v", res.StatusCode) + log.Errorf(errMsg) + return nil, &CNSClientError{restserver.UnexpectedError, fmt.Errorf(errMsg)} } var resp cns.GetNetworkContainerResponse @@ -101,10 +109,10 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte) if resp.Response.ReturnCode != 0 { log.Errorf( - "[Azure CNSClient] GetNetworkConfiguration received error response :%v , isNotFoundError : %v", + "[Azure CNSClient] GetNetworkConfiguration received error response :%v , Code : %d", resp.Response.Message, - isNotFoundError) - return nil, &CNSClientError{resp.Response.ReturnCode, err} + resp.Response.ReturnCode) + return nil, &CNSClientError{resp.Response.ReturnCode, fmt.Errorf(resp.Response.Message)} } return &resp, nil diff --git a/cns/cnsclient/error.go b/cns/cnsclient/error.go new file mode 100644 index 0000000000..565d53ebe5 --- /dev/null +++ b/cns/cnsclient/error.go @@ -0,0 +1,22 @@ +package cnsclient + +import ( + "fmt" + + "github.com/Azure/azure-container-networking/cns/restserver" +) + +// CNSClientError records an error and relevant code +type CNSClientError struct { + Code int + Err error +} + +func (e *CNSClientError) Error() string { + return fmt.Sprintf("[Azure CNSClient] Code: %d , Error: %v", e.Code, e.Err) +} + +// IsNotFoundError - Returns a boolean if the error code is not found or not? +func (e *CNSClientError) IsNotFoundError() bool { + return e.Code == restserver.UnknownContainerID +} From 39b0812dcf866902190eb046e372562a48106902 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Fri, 9 Oct 2020 12:29:31 -0700 Subject: [PATCH 05/11] fixing linux build --- cni/network/network_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cni/network/network_linux.go b/cni/network/network_linux.go index b37252179b..a8dfda1474 100644 --- a/cni/network/network_linux.go +++ b/cni/network/network_linux.go @@ -134,6 +134,6 @@ func updateSubnetPrefix(cnsNetworkConfig *cns.GetNetworkContainerResponse, subne return nil } -func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (string, bool, error) { - return nwCfg.Name, false, nil +func getNetworkName(podName, podNs, ifName string, nwCfg *cni.NetworkConfig) (string, error) { + return nwCfg.Name, nil } From 1ca2c00a6b88a2e34594b5b79b386c837bf83c1f Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Fri, 9 Oct 2020 13:13:40 -0700 Subject: [PATCH 06/11] fix redeclaring --- cni/network/multitenancy.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index d7fb08d006..8847450a58 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -211,10 +211,10 @@ func GetMultiTenancyCNIResult( ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, *cniTypesCurr.Result, error) { if nwCfg.MultiTenancy { - result, cnsNetworkConfig, subnetPrefix, cnsClienterr := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) - if cnsClienterr != nil { - log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %+v", k8sPodName, k8sNamespace, cnsClienterr) - return nil, nil, net.IPNet{}, nil, cnsClienterr + result, cnsNetworkConfig, subnetPrefix, err := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) + if err != nil { + log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %+v", k8sPodName, k8sNamespace, err) + return nil, nil, net.IPNet{}, nil, err } log.Printf("PrimaryInterfaceIdentifier :%v", subnetPrefix.IP.String()) @@ -222,7 +222,7 @@ func GetMultiTenancyCNIResult( if checkIfSubnetOverlaps(enableInfraVnet, nwCfg, cnsNetworkConfig) { buf := fmt.Sprintf("InfraVnet %v overlaps with customerVnet %+v", nwCfg.InfraVnetAddressSpace, cnsNetworkConfig.CnetAddressSpace) log.Printf(buf) - err := errors.New(buf) + err = errors.New(buf) return nil, nil, net.IPNet{}, nil, err } From 481a0ddda996bb155141a23c071c0cb714649005 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Fri, 9 Oct 2020 13:20:15 -0700 Subject: [PATCH 07/11] fix err --- cni/network/multitenancy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index 8847450a58..49f9d7bc53 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -82,10 +82,10 @@ func getContainerNetworkConfigurationInternal( return nil, nil, net.IPNet{}, err } - networkConfig, cnsClientErr := cnsClient.GetNetworkConfiguration(orchestratorContext) + networkConfig, err := cnsClient.GetNetworkConfiguration(orchestratorContext) if err != nil { log.Printf("GetNetworkConfiguration failed with %v", err) - return nil, nil, net.IPNet{}, cnsClientErr + return nil, nil, net.IPNet{}, err } log.Printf("Network config received from cns %+v", networkConfig) From 0a9d202f444e9fff3878a47c4dc61ada2650739d Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Fri, 9 Oct 2020 14:29:02 -0700 Subject: [PATCH 08/11] fix condition for error --- cni/network/network.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cni/network/network.go b/cni/network/network.go index eeb50f399c..ea8e343cdf 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -805,7 +805,8 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error { log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) var cnsError *cnsclient.CNSClientError - if errors.As(err, &cnsError) && cnsError.IsNotFoundError() { + + if errors.As(err, &cnsError) && !cnsError.IsNotFoundError() { err = plugin.Errorf("Failed to extract network name from network config. error: %v", cnsError) return err } From ba934a047cfc779ba4d8eb92d188044373c7bb75 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Fri, 9 Oct 2020 16:01:00 -0700 Subject: [PATCH 09/11] addressed feedback --- cni/network/multitenancy.go | 2 +- cni/network/network.go | 8 +++----- cni/utils/errutils.go | 20 ++++++++++++++++++++ cns/cnsclient/cnsclient.go | 13 +------------ cns/cnsclient/error.go | 7 ------- 5 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 cni/utils/errutils.go diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index 49f9d7bc53..3e6482ebf0 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -69,7 +69,7 @@ func getContainerNetworkConfigurationInternal( namespace string, podName string, ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) { - cnsClient, err := cnsclient.GetCnsClientEx() + cnsClient, err := cnsclient.GetCnsClient() if err != nil { log.Printf("Failed to get CNS client. Error: %v", err) return nil, nil, net.IPNet{}, err diff --git a/cni/network/network.go b/cni/network/network.go index ea8e343cdf..fc8db6b988 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -5,7 +5,6 @@ package network import ( "encoding/json" - "errors" "fmt" "io/ioutil" "net" @@ -16,6 +15,7 @@ import ( "github.com/Azure/azure-container-networking/aitelemetry" "github.com/Azure/azure-container-networking/cni" + "github.com/Azure/azure-container-networking/cni/utils" "github.com/Azure/azure-container-networking/cns" "github.com/Azure/azure-container-networking/cns/cnsclient" "github.com/Azure/azure-container-networking/common" @@ -804,10 +804,8 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error { if err != nil { log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err) - var cnsError *cnsclient.CNSClientError - - if errors.As(err, &cnsError) && !cnsError.IsNotFoundError() { - err = plugin.Errorf("Failed to extract network name from network config. error: %v", cnsError) + if !utils.IsNotFoundError(err) { + err = plugin.Errorf("Failed to extract network name from network config. error: %v", err) return err } } diff --git a/cni/utils/errutils.go b/cni/utils/errutils.go new file mode 100644 index 0000000000..21663384b6 --- /dev/null +++ b/cni/utils/errutils.go @@ -0,0 +1,20 @@ +package utils + +import ( + "errors" + + "github.com/Azure/azure-container-networking/cns/cnsclient" + "github.com/Azure/azure-container-networking/cns/restserver" +) + +// TODO : Move to common directory like common, after fixing circular dependencies +func IsNotFoundError(err error) bool { + switch err := err.(type) { + case *cnsclient.CNSClientError: + var cnsError *cnsclient.CNSClientError + // not expected to fail + _ = errors.As(err, &cnsError) + return (cnsError.Code == restserver.UnknownContainerID) + } + return false +} diff --git a/cns/cnsclient/cnsclient.go b/cns/cnsclient/cnsclient.go index de60fa72dc..99110aa868 100644 --- a/cns/cnsclient/cnsclient.go +++ b/cns/cnsclient/cnsclient.go @@ -40,21 +40,10 @@ func InitCnsClient(url string) (*CNSClient, error) { return cnsClient, nil } -// GetCnsClient returns the cns client object +// GetCnsClient returns the cns client object and encapsulates the error as CNSClientError func GetCnsClient() (*CNSClient, error) { var err error - if cnsClient == nil { - err = fmt.Errorf("[Azure CNSClient] CNS Client not initialized") - } - - return cnsClient, err -} - -// GetCnsClientEx returns the cns client object and encapsulates the error as CNSClientError -func GetCnsClientEx() (*CNSClient, error) { - var err error - if cnsClient == nil { err = &CNSClientError{ restserver.UnexpectedError, diff --git a/cns/cnsclient/error.go b/cns/cnsclient/error.go index 565d53ebe5..d68955fa1b 100644 --- a/cns/cnsclient/error.go +++ b/cns/cnsclient/error.go @@ -2,8 +2,6 @@ package cnsclient import ( "fmt" - - "github.com/Azure/azure-container-networking/cns/restserver" ) // CNSClientError records an error and relevant code @@ -15,8 +13,3 @@ type CNSClientError struct { func (e *CNSClientError) Error() string { return fmt.Sprintf("[Azure CNSClient] Code: %d , Error: %v", e.Code, e.Err) } - -// IsNotFoundError - Returns a boolean if the error code is not found or not? -func (e *CNSClientError) IsNotFoundError() bool { - return e.Code == restserver.UnknownContainerID -} From fe31f449fc303be0cebd4a1f095e20fdcef9c026 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Fri, 9 Oct 2020 16:03:33 -0700 Subject: [PATCH 10/11] fix unwanted changes --- cni/network/multitenancy.go | 2 +- cns/cnsclient/cnsclient.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index 3e6482ebf0..4472f63e63 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -213,7 +213,7 @@ func GetMultiTenancyCNIResult( if nwCfg.MultiTenancy { result, cnsNetworkConfig, subnetPrefix, err := getContainerNetworkConfiguration(nwCfg, k8sPodName, k8sNamespace, ifName) if err != nil { - log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %+v", k8sPodName, k8sNamespace, err) + log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v", k8sPodName, k8sNamespace, err) return nil, nil, net.IPNet{}, nil, err } diff --git a/cns/cnsclient/cnsclient.go b/cns/cnsclient/cnsclient.go index 99110aa868..65b74feb27 100644 --- a/cns/cnsclient/cnsclient.go +++ b/cns/cnsclient/cnsclient.go @@ -40,7 +40,7 @@ func InitCnsClient(url string) (*CNSClient, error) { return cnsClient, nil } -// GetCnsClient returns the cns client object and encapsulates the error as CNSClientError +// GetCnsClient returns the cns client object func GetCnsClient() (*CNSClient, error) { var err error From c24f204496d0a70f57661bed58b4004c03389f4d Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Wed, 14 Oct 2020 11:11:39 -0700 Subject: [PATCH 11/11] Addressing Raimro's feedback --- cni/utils/errutils.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cni/utils/errutils.go b/cni/utils/errutils.go index 21663384b6..86a51091a1 100644 --- a/cni/utils/errutils.go +++ b/cni/utils/errutils.go @@ -1,20 +1,15 @@ package utils import ( - "errors" - "github.com/Azure/azure-container-networking/cns/cnsclient" "github.com/Azure/azure-container-networking/cns/restserver" ) // TODO : Move to common directory like common, after fixing circular dependencies func IsNotFoundError(err error) bool { - switch err := err.(type) { + switch e := err.(type) { case *cnsclient.CNSClientError: - var cnsError *cnsclient.CNSClientError - // not expected to fail - _ = errors.As(err, &cnsError) - return (cnsError.Code == restserver.UnknownContainerID) + return (e.Code == restserver.UnknownContainerID) } return false }