Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
20 changes: 0 additions & 20 deletions cns/requestcontroller/kubecontroller/crdtranslator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
53 changes: 0 additions & 53 deletions cns/requestcontroller/kubecontroller/crdtranslator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}