From bae366c25c44ed3255bf2edfc652f36d2de1ad1d Mon Sep 17 00:00:00 2001 From: Shufang Date: Tue, 20 Oct 2020 23:54:40 -0700 Subject: [PATCH 1/2] Add nc version in SecondaryIPConfig stucture. --- cns/NetworkContainerContract.go | 1 + cns/requestcontroller/kubecontroller/crdtranslator.go | 4 +++- cns/restserver/internalapi_test.go | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cns/NetworkContainerContract.go b/cns/NetworkContainerContract.go index 0f97dbb5ad..9e1331ec59 100644 --- a/cns/NetworkContainerContract.go +++ b/cns/NetworkContainerContract.go @@ -130,6 +130,7 @@ type IPConfiguration struct { // SecondaryIPConfig contains IP info of SecondaryIP type SecondaryIPConfig struct { IPAddress string + NCVersion int } // IPSubnet contains ip subnet. diff --git a/cns/requestcontroller/kubecontroller/crdtranslator.go b/cns/requestcontroller/kubecontroller/crdtranslator.go index aa8c9e89cd..ef09782b6c 100644 --- a/cns/requestcontroller/kubecontroller/crdtranslator.go +++ b/cns/requestcontroller/kubecontroller/crdtranslator.go @@ -3,6 +3,7 @@ package kubecontroller import ( "fmt" "net" + "strconv" "github.com/Azure/azure-container-networking/cns" nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha" @@ -56,9 +57,10 @@ func CRDStatusToNCRequest(crdStatus nnc.NodeNetworkConfigStatus) (cns.CreateNetw if ip = net.ParseIP(ipAssignment.IP); ip == nil { return ncRequest, fmt.Errorf("Invalid SecondaryIP %s:", ipAssignment.IP) } - + ncVersion, _ := strconv.Atoi(ncRequest.Version) secondaryIPConfig = cns.SecondaryIPConfig{ IPAddress: ip.String(), + NCVersion: ncVersion, } ncRequest.SecondaryIPConfigs[ipAssignment.Name] = secondaryIPConfig } diff --git a/cns/restserver/internalapi_test.go b/cns/restserver/internalapi_test.go index b6721bf8d9..64d55dc6a0 100644 --- a/cns/restserver/internalapi_test.go +++ b/cns/restserver/internalapi_test.go @@ -324,7 +324,12 @@ func validateNCStateAfterReconcile(t *testing.T, ncRequest *cns.CreateNetworkCon // validate rest of Secondary IPs in Available state if ncRequest != nil { + ncRequestVersion, _ := strconv.Atoi(ncRequest.Version) for secIpId, secIpConfig := range ncRequest.SecondaryIPConfigs { + if secIpConfig.NCVersion != ncRequestVersion { + t.Fatalf("nc request version is %d, secondary ip %s nc version is %d, they are not equal", + ncRequestVersion, secIpConfig.IPAddress, secIpConfig.NCVersion) + } if _, exists := expectedAllocatedPods[secIpConfig.IPAddress]; exists { continue } From fcdb19a7fe264a985732610a4ce98002ba521331 Mon Sep 17 00:00:00 2001 From: Shufang Date: Wed, 21 Oct 2020 10:32:02 -0700 Subject: [PATCH 2/2] Only update IP version when IP changes. --- .../kubecontroller/crdtranslator.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cns/requestcontroller/kubecontroller/crdtranslator.go b/cns/requestcontroller/kubecontroller/crdtranslator.go index ef09782b6c..4c4df578cd 100644 --- a/cns/requestcontroller/kubecontroller/crdtranslator.go +++ b/cns/requestcontroller/kubecontroller/crdtranslator.go @@ -57,12 +57,16 @@ func CRDStatusToNCRequest(crdStatus nnc.NodeNetworkConfigStatus) (cns.CreateNetw if ip = net.ParseIP(ipAssignment.IP); ip == nil { return ncRequest, fmt.Errorf("Invalid SecondaryIP %s:", ipAssignment.IP) } - ncVersion, _ := strconv.Atoi(ncRequest.Version) - secondaryIPConfig = cns.SecondaryIPConfig{ - IPAddress: ip.String(), - NCVersion: ncVersion, + + ipConfig, ok := ncRequest.SecondaryIPConfigs[ipAssignment.Name] + if !ok || (ok && ipConfig.IPAddress != ip.String()) { + ncVersion, _ := strconv.Atoi(ncRequest.Version) + secondaryIPConfig = cns.SecondaryIPConfig{ + IPAddress: ip.String(), + NCVersion: ncVersion, + } + ncRequest.SecondaryIPConfigs[ipAssignment.Name] = secondaryIPConfig } - ncRequest.SecondaryIPConfigs[ipAssignment.Name] = secondaryIPConfig } }