From a3b4717bd4dd1ac4538158a8b8b1cc28ccb94971 Mon Sep 17 00:00:00 2001 From: Paul Johnston Date: Thu, 17 Sep 2020 16:28:15 -0700 Subject: [PATCH] Removing duplicate implementation of translating cns to crd spec (see ipampoolmonitor.go) --- .../crdrequestcontroller_test.go | 41 +++++--------- .../kubecontroller/crdtranslator.go | 20 ------- .../kubecontroller/crdtranslator_test.go | 53 ------------------- 3 files changed, 12 insertions(+), 102 deletions(-) diff --git a/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go b/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go index 7f280a7907..0a0dcb3de2 100644 --- a/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go +++ b/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go @@ -366,21 +366,13 @@ func TestUpdateSpecOnNonExistingNodeNetConfig(t *testing.T) { } logger.InitLogger("Azure CNS RequestController", 0, 0, "") - ipConfig1 := cns.SecondaryIPConfig{ - IPAddress: "10.0.0.1", - } - - ipConfig2 := cns.SecondaryIPConfig{ - IPAddress: "10.0.0.2", - } - - secondaryIPConfigs := map[string]cns.SecondaryIPConfig{ - allocatedUUID: ipConfig1, - allocatedUUID2: ipConfig2, + spec := nnc.NodeNetworkConfigSpec{ + RequestedIPCount: int64(10), + IPsNotInUse: []string{ + allocatedUUID, + allocatedUUID2, + }, } - ipCount := 10 - - spec, _ := CNSToCRDSpec(secondaryIPConfigs, ipCount) //Test updating spec for existing NodeNetworkConfig err := rc.UpdateCRDSpec(context.Background(), spec) @@ -415,23 +407,14 @@ func TestUpdateSpecOnExistingNodeNetConfig(t *testing.T) { } logger.InitLogger("Azure CNS RequestController", 0, 0, "") - ipConfig1 := cns.SecondaryIPConfig{ - IPAddress: "10.0.0.1", - } - - ipConfig2 := cns.SecondaryIPConfig{ - IPAddress: "10.0.0.2", - } - - secondaryIPConfigs := map[string]cns.SecondaryIPConfig{ - allocatedUUID: ipConfig1, - allocatedUUID2: ipConfig2, + spec := nnc.NodeNetworkConfigSpec{ + RequestedIPCount: int64(10), + IPsNotInUse: []string{ + allocatedUUID, + allocatedUUID2, + }, } - ipCount := 10 - - spec, _ := CNSToCRDSpec(secondaryIPConfigs, ipCount) - //Test update spec for existing NodeNetworkConfig err := rc.UpdateCRDSpec(context.Background(), spec) diff --git a/cns/requestcontroller/kubecontroller/crdtranslator.go b/cns/requestcontroller/kubecontroller/crdtranslator.go index 815510712d..d4b3bdd42f 100644 --- a/cns/requestcontroller/kubecontroller/crdtranslator.go +++ b/cns/requestcontroller/kubecontroller/crdtranslator.go @@ -66,23 +66,3 @@ func CRDStatusToNCRequest(crdStatus nnc.NodeNetworkConfigStatus) (cns.CreateNetw //Only returning the first network container for now, later we will return a list return ncRequest, nil } - -// CNSToCRDSpec translates CNS's map of Ips to be released and requested ip count into a CRD Spec -func CNSToCRDSpec(toBeDeletedSecondaryIPConfigs map[string]cns.SecondaryIPConfig, ipCount int) (nnc.NodeNetworkConfigSpec, error) { - var ( - spec nnc.NodeNetworkConfigSpec - uuid string - ) - - if toBeDeletedSecondaryIPConfigs == nil { - return spec, fmt.Errorf("Error when translating toBeDeletedSecondaryIPConfigs to CRD spec, map is nil") - } - - spec.RequestedIPCount = int64(ipCount) - - for uuid = range toBeDeletedSecondaryIPConfigs { - spec.IPsNotInUse = append(spec.IPsNotInUse, uuid) - } - - return spec, nil -} diff --git a/cns/requestcontroller/kubecontroller/crdtranslator_test.go b/cns/requestcontroller/kubecontroller/crdtranslator_test.go index 0f79d01462..433d806da8 100644 --- a/cns/requestcontroller/kubecontroller/crdtranslator_test.go +++ b/cns/requestcontroller/kubecontroller/crdtranslator_test.go @@ -234,56 +234,3 @@ func TestStatusToNCRequestSuccess(t *testing.T) { t.Fatalf("Expected %v as the secondary IP config but got %v", testSecIp1, secondaryIP.IPAddress) } } - -func TestSecondaryIPsToCRDSpecNilMap(t *testing.T) { - var ( - secondaryIPs map[string]cns.SecondaryIPConfig - ipCount int - err error - ) - - ipCount = 10 - - // Test with nil secondaryIPs map - _, err = CNSToCRDSpec(secondaryIPs, ipCount) - - if err == nil { - t.Fatalf("Expected error when converting nil map of secondary IPs into crd spec") - } -} - -func TestSecondaryIPsToCRDSpecSuccess(t *testing.T) { - var ( - secondaryIPs map[string]cns.SecondaryIPConfig - spec nnc.NodeNetworkConfigSpec - ipCount int - err error - ) - - ipCount = 10 - - secondaryIPs = map[string]cns.SecondaryIPConfig{ - allocatedUUID: { - IPAddress: testSecIp1, - }, - } - - // Test with secondary ip with ip and mask length correct - spec, err = CNSToCRDSpec(secondaryIPs, ipCount) - - if err != nil { - t.Fatalf("Expected no error when converting secondary ips into crd spec but got %v", err) - } - - if len(spec.IPsNotInUse) != 1 { - t.Fatalf("Expected crd spec's IPsNotInUse to have length 1, but has length %v", len(spec.IPsNotInUse)) - } - - if spec.IPsNotInUse[0] != allocatedUUID { - t.Fatalf("Expected crd's spec to contain UUID %v but got %v", allocatedUUID, spec.IPsNotInUse[0]) - } - - if spec.RequestedIPCount != int64(ipCount) { - t.Fatalf("Expected crd's spec RequestedIPCount to be equal to ipCount %v but got %v", ipCount, spec.RequestedIPCount) - } -}