From 78f692244a9b77cb572730a7dfcd959c36a56b26 Mon Sep 17 00:00:00 2001 From: AzureAhai Date: Wed, 7 Feb 2024 15:30:50 -0800 Subject: [PATCH] addressing the latest comments --- cns/cnireconciler/podinfoprovider.go | 18 +++--------------- cns/configuration/configuration.go | 2 +- cns/restserver/ipam.go | 4 +++- cns/service/main.go | 4 ++-- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/cns/cnireconciler/podinfoprovider.go b/cns/cnireconciler/podinfoprovider.go index 47fbeb269f..68a7d1d864 100644 --- a/cns/cnireconciler/podinfoprovider.go +++ b/cns/cnireconciler/podinfoprovider.go @@ -54,7 +54,7 @@ func newCNIPodInfoProvider(exc exec.Interface, stateMigration bool) (cns.PodInfo } var endpointState map[string]*restserver.EndpointInfo if stateMigration { - endpointState, err = cniStateToCnsEndpointState(state) + endpointState = cniStateToCnsEndpointState(state) } else { endpointState = nil } @@ -117,7 +117,7 @@ func endpointStateToPodInfoByIP(state map[string]*restserver.EndpointInfo) (map[ // cniStateToCnsEndpointState converts an AzureCNIState dumped from a CNI exec // into a EndpointInfo map, using the containerID as keys in the map. // The map then will be saved on CNS endpoint state -func cniStateToCnsEndpointState(state *api.AzureCNIState) (map[string]*restserver.EndpointInfo, error) { +func cniStateToCnsEndpointState(state *api.AzureCNIState) map[string]*restserver.EndpointInfo { logger.Printf("Generating CNS Endpoint State") endpointState := map[string]*restserver.EndpointInfo{} for epID, endpoint := range state.ContainerInterfaces { @@ -126,22 +126,10 @@ func cniStateToCnsEndpointState(state *api.AzureCNIState) (map[string]*restserve for _, epIP := range endpoint.IPAddresses { if epIP.IP.To4() == nil { // is an ipv6 address ipconfig := net.IPNet{IP: epIP.IP, Mask: epIP.Mask} - for _, ipconf := range ipInfo.IPv6 { - if ipconf.IP.Equal(ipconfig.IP) { - logger.Errorf("Found existing ipv6 ipconfig for infra container %s", endpoint.ContainerID) - return nil, restserver.ErrExistingIpconfigFound - } - } ipInfo.IPv6 = append(ipInfo.IPv6, ipconfig) } else { ipconfig := net.IPNet{IP: epIP.IP, Mask: epIP.Mask} - for _, ipconf := range ipInfo.IPv4 { - if ipconf.IP.Equal(ipconfig.IP) { - logger.Errorf("Found existing ipv4 ipconfig for infra container %s", endpoint.ContainerID) - return nil, restserver.ErrExistingIpconfigFound - } - } ipInfo.IPv4 = append(ipInfo.IPv4, ipconfig) } } @@ -150,7 +138,7 @@ func cniStateToCnsEndpointState(state *api.AzureCNIState) (map[string]*restserve endpointState[endpointID] = endpointInfo logger.Printf("CNS endpoint state extracted from CNI: [%+v]", *endpointInfo) } - return endpointState, nil + return endpointState } // extractEndpointInfo extract Interface Name and endpointID for each endpoint based the CNI state diff --git a/cns/configuration/configuration.go b/cns/configuration/configuration.go index 69735de7b7..c6e636b276 100644 --- a/cns/configuration/configuration.go +++ b/cns/configuration/configuration.go @@ -56,7 +56,7 @@ type CNSConfig struct { UseHTTPS bool WatchPods bool `json:"-"` WireserverIP string - StatelessCNIMigration bool + StateMigration bool } type TelemetrySettings struct { diff --git a/cns/restserver/ipam.go b/cns/restserver/ipam.go index 66459c5a68..522e1a38d5 100644 --- a/cns/restserver/ipam.go +++ b/cns/restserver/ipam.go @@ -27,7 +27,6 @@ var ( ErrNoNCs = errors.New("no NCs found in the CNS internal state") ErrOptManageEndpointState = errors.New("CNS is not set to manage the endpoint state") ErrEndpointStateNotFound = errors.New("endpoint state could not be found in the statefile") - ErrExistingIpconfigFound = errors.New("Found existing ipconfig for infra container") ) const ( @@ -1074,6 +1073,9 @@ func (service *HTTPRestService) GetEndpointHelper(endpointID string) (*EndpointI logger.Warnf("[GetEndpointState] Found existing endpoint state for container %s", endpointID) return endpointInfo, nil } + // This part is a temprory fix if we have endpoint states belong to CNI version 1.4.X on Windows since the states don't have the containerID + // In case there was no endpoint founded with ContainerID as the key, + // then [First 8 character of containerid]-eth0 will be tried legacyEndpointID := endpointID[:ContainerIDLength] + "-" + InterfaceName if endpointInfo, ok := service.EndpointState[legacyEndpointID]; ok { logger.Warnf("[GetEndpointState] Found existing endpoint state for container %s", legacyEndpointID) diff --git a/cns/service/main.go b/cns/service/main.go index e274c847f5..cf55559595 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -1521,11 +1521,11 @@ func InitializeStateFromCNS(cnsconfig *configuration.CNSConfig, endpointStateSto if err != nil { if errors.Is(err, store.ErrKeyNotFound) { logger.Printf("[Azure CNS] No endpoint state found, skipping initializing CNS state") - if cnsconfig.StatelessCNIMigration { + if cnsconfig.StateMigration { logger.Printf("StatelessCNI Migration is enabled") logger.Printf("initializing from Statefull CNI") var endpointState map[string]*restserver.EndpointInfo - podInfoByIPProvider, endpointState, err = cnireconciler.NewCNIPodInfoProvider(cnsconfig.StatelessCNIMigration) + podInfoByIPProvider, endpointState, err = cnireconciler.NewCNIPodInfoProvider(cnsconfig.StateMigration) if err != nil { return nil, errors.Wrap(err, "failed to create CNI PodInfoProvider") }