Skip to content

Commit a71b63a

Browse files
authored
Removing duplicate implementation of translating cns to crd spec (see ipampoolmonitor.go) (#674)
1 parent 67124b8 commit a71b63a

File tree

3 files changed

+12
-102
lines changed

3 files changed

+12
-102
lines changed

cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,13 @@ func TestUpdateSpecOnNonExistingNodeNetConfig(t *testing.T) {
366366
}
367367
logger.InitLogger("Azure CNS RequestController", 0, 0, "")
368368

369-
ipConfig1 := cns.SecondaryIPConfig{
370-
IPAddress: "10.0.0.1",
371-
}
372-
373-
ipConfig2 := cns.SecondaryIPConfig{
374-
IPAddress: "10.0.0.2",
375-
}
376-
377-
secondaryIPConfigs := map[string]cns.SecondaryIPConfig{
378-
allocatedUUID: ipConfig1,
379-
allocatedUUID2: ipConfig2,
369+
spec := nnc.NodeNetworkConfigSpec{
370+
RequestedIPCount: int64(10),
371+
IPsNotInUse: []string{
372+
allocatedUUID,
373+
allocatedUUID2,
374+
},
380375
}
381-
ipCount := 10
382-
383-
spec, _ := CNSToCRDSpec(secondaryIPConfigs, ipCount)
384376

385377
//Test updating spec for existing NodeNetworkConfig
386378
err := rc.UpdateCRDSpec(context.Background(), spec)
@@ -415,23 +407,14 @@ func TestUpdateSpecOnExistingNodeNetConfig(t *testing.T) {
415407
}
416408
logger.InitLogger("Azure CNS RequestController", 0, 0, "")
417409

418-
ipConfig1 := cns.SecondaryIPConfig{
419-
IPAddress: "10.0.0.1",
420-
}
421-
422-
ipConfig2 := cns.SecondaryIPConfig{
423-
IPAddress: "10.0.0.2",
424-
}
425-
426-
secondaryIPConfigs := map[string]cns.SecondaryIPConfig{
427-
allocatedUUID: ipConfig1,
428-
allocatedUUID2: ipConfig2,
410+
spec := nnc.NodeNetworkConfigSpec{
411+
RequestedIPCount: int64(10),
412+
IPsNotInUse: []string{
413+
allocatedUUID,
414+
allocatedUUID2,
415+
},
429416
}
430417

431-
ipCount := 10
432-
433-
spec, _ := CNSToCRDSpec(secondaryIPConfigs, ipCount)
434-
435418
//Test update spec for existing NodeNetworkConfig
436419
err := rc.UpdateCRDSpec(context.Background(), spec)
437420

cns/requestcontroller/kubecontroller/crdtranslator.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,3 @@ func CRDStatusToNCRequest(crdStatus nnc.NodeNetworkConfigStatus) (cns.CreateNetw
6666
//Only returning the first network container for now, later we will return a list
6767
return ncRequest, nil
6868
}
69-
70-
// CNSToCRDSpec translates CNS's map of Ips to be released and requested ip count into a CRD Spec
71-
func CNSToCRDSpec(toBeDeletedSecondaryIPConfigs map[string]cns.SecondaryIPConfig, ipCount int) (nnc.NodeNetworkConfigSpec, error) {
72-
var (
73-
spec nnc.NodeNetworkConfigSpec
74-
uuid string
75-
)
76-
77-
if toBeDeletedSecondaryIPConfigs == nil {
78-
return spec, fmt.Errorf("Error when translating toBeDeletedSecondaryIPConfigs to CRD spec, map is nil")
79-
}
80-
81-
spec.RequestedIPCount = int64(ipCount)
82-
83-
for uuid = range toBeDeletedSecondaryIPConfigs {
84-
spec.IPsNotInUse = append(spec.IPsNotInUse, uuid)
85-
}
86-
87-
return spec, nil
88-
}

cns/requestcontroller/kubecontroller/crdtranslator_test.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -234,56 +234,3 @@ func TestStatusToNCRequestSuccess(t *testing.T) {
234234
t.Fatalf("Expected %v as the secondary IP config but got %v", testSecIp1, secondaryIP.IPAddress)
235235
}
236236
}
237-
238-
func TestSecondaryIPsToCRDSpecNilMap(t *testing.T) {
239-
var (
240-
secondaryIPs map[string]cns.SecondaryIPConfig
241-
ipCount int
242-
err error
243-
)
244-
245-
ipCount = 10
246-
247-
// Test with nil secondaryIPs map
248-
_, err = CNSToCRDSpec(secondaryIPs, ipCount)
249-
250-
if err == nil {
251-
t.Fatalf("Expected error when converting nil map of secondary IPs into crd spec")
252-
}
253-
}
254-
255-
func TestSecondaryIPsToCRDSpecSuccess(t *testing.T) {
256-
var (
257-
secondaryIPs map[string]cns.SecondaryIPConfig
258-
spec nnc.NodeNetworkConfigSpec
259-
ipCount int
260-
err error
261-
)
262-
263-
ipCount = 10
264-
265-
secondaryIPs = map[string]cns.SecondaryIPConfig{
266-
allocatedUUID: {
267-
IPAddress: testSecIp1,
268-
},
269-
}
270-
271-
// Test with secondary ip with ip and mask length correct
272-
spec, err = CNSToCRDSpec(secondaryIPs, ipCount)
273-
274-
if err != nil {
275-
t.Fatalf("Expected no error when converting secondary ips into crd spec but got %v", err)
276-
}
277-
278-
if len(spec.IPsNotInUse) != 1 {
279-
t.Fatalf("Expected crd spec's IPsNotInUse to have length 1, but has length %v", len(spec.IPsNotInUse))
280-
}
281-
282-
if spec.IPsNotInUse[0] != allocatedUUID {
283-
t.Fatalf("Expected crd's spec to contain UUID %v but got %v", allocatedUUID, spec.IPsNotInUse[0])
284-
}
285-
286-
if spec.RequestedIPCount != int64(ipCount) {
287-
t.Fatalf("Expected crd's spec RequestedIPCount to be equal to ipCount %v but got %v", ipCount, spec.RequestedIPCount)
288-
}
289-
}

0 commit comments

Comments
 (0)