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..4c4df578cd 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" @@ -57,10 +58,15 @@ func CRDStatusToNCRequest(crdStatus nnc.NodeNetworkConfigStatus) (cns.CreateNetw return ncRequest, fmt.Errorf("Invalid SecondaryIP %s:", ipAssignment.IP) } - secondaryIPConfig = cns.SecondaryIPConfig{ - IPAddress: ip.String(), + 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 } } 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 }