Skip to content

Commit f0ff6cf

Browse files
authored
fix: remove pool monitor from debug api response (#2621)
fix: remove IPAM pool monitor plumbing from restserver, debug api, and tests Signed-off-by: Evan Baker <[email protected]>
1 parent e475038 commit f0ff6cf

File tree

7 files changed

+2
-122
lines changed

7 files changed

+2
-122
lines changed

cns/client/client_test.go

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ import (
2222
"github.com/Azure/azure-container-networking/cns/logger"
2323
"github.com/Azure/azure-container-networking/cns/restserver"
2424
"github.com/Azure/azure-container-networking/cns/types"
25-
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
2625
"github.com/Azure/azure-container-networking/log"
2726
"github.com/google/go-cmp/cmp"
2827
"github.com/google/uuid"
2928
"github.com/stretchr/testify/assert"
3029
"github.com/stretchr/testify/require"
31-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3230
)
3331

3432
const (
@@ -99,24 +97,6 @@ func addTestStateToRestServer(t *testing.T, secondaryIps []string) {
9997
if returnCode != 0 {
10098
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
10199
}
102-
103-
_ = svc.IPAMPoolMonitor.Update(&v1alpha.NodeNetworkConfig{
104-
Spec: v1alpha.NodeNetworkConfigSpec{
105-
RequestedIPCount: 16,
106-
IPsNotInUse: []string{"abc"},
107-
},
108-
Status: v1alpha.NodeNetworkConfigStatus{
109-
Scaler: v1alpha.Scaler{
110-
BatchSize: batchSize,
111-
ReleaseThresholdPercent: releasePercent,
112-
RequestThresholdPercent: requestPercent,
113-
MaxIPCount: 250,
114-
},
115-
NetworkContainers: []v1alpha.NetworkContainer{
116-
{},
117-
},
118-
},
119-
})
120100
}
121101

122102
func getIPNetFromResponse(resp *cns.IPConfigResponse) (net.IPNet, error) {
@@ -174,39 +154,6 @@ func TestMain(m *testing.M) {
174154
httpRestService, err := restserver.NewHTTPRestService(&config, &fakes.WireserverClientFake{}, &fakes.WireserverProxyFake{}, &fakes.NMAgentClientFake{}, nil, nil, nil)
175155
svc = httpRestService
176156
httpRestService.Name = "cns-test-server"
177-
fakeNNC := v1alpha.NodeNetworkConfig{
178-
TypeMeta: metav1.TypeMeta{},
179-
ObjectMeta: metav1.ObjectMeta{},
180-
Spec: v1alpha.NodeNetworkConfigSpec{
181-
RequestedIPCount: 16,
182-
IPsNotInUse: []string{"abc"},
183-
},
184-
Status: v1alpha.NodeNetworkConfigStatus{
185-
Scaler: v1alpha.Scaler{
186-
BatchSize: 10,
187-
ReleaseThresholdPercent: 150,
188-
RequestThresholdPercent: 50,
189-
MaxIPCount: 250,
190-
},
191-
NetworkContainers: []v1alpha.NetworkContainer{
192-
{
193-
ID: "nc1",
194-
PrimaryIP: "10.0.0.11",
195-
SubnetName: "sub1",
196-
IPAssignments: []v1alpha.IPAssignment{
197-
{
198-
Name: "ip1",
199-
IP: "10.0.0.10",
200-
},
201-
},
202-
DefaultGateway: "10.0.0.1",
203-
SubnetAddressSpace: "10.0.0.0/24",
204-
Version: 2,
205-
},
206-
},
207-
},
208-
}
209-
httpRestService.IPAMPoolMonitor = &fakes.MonitorFake{IPsNotInUseCount: 13, NodeNetworkConfig: &fakeNNC}
210157

211158
if err != nil {
212159
logger.Errorf("Failed to create CNS object, err:%v.\n", err)
@@ -369,27 +316,11 @@ func TestCNSClientDebugAPI(t *testing.T) {
369316
}
370317
assert.NotEmpty(t, inmemory.HTTPRestServiceData.PodIPConfigState, "PodIpConfigState with at least 1 entry expected")
371318

372-
testIpamPoolMonitor := inmemory.HTTPRestServiceData.IPAMPoolMonitor
373-
assert.EqualValues(t, 5, testIpamPoolMonitor.MinimumFreeIps, "IPAMPoolMonitor state is not reflecting the initial set values")
374-
assert.EqualValues(t, 15, testIpamPoolMonitor.MaximumFreeIps, "IPAMPoolMonitor state is not reflecting the initial set values")
375-
assert.EqualValues(t, 13, testIpamPoolMonitor.UpdatingIpsNotInUseCount, "IPAMPoolMonitor state is not reflecting the initial set values")
376-
377-
// check for cached NNC Spec struct values
378-
assert.EqualValues(t, 16, testIpamPoolMonitor.CachedNNC.Spec.RequestedIPCount, "IPAMPoolMonitor cached NNC Spec is not reflecting the initial set values")
379-
assert.Len(t, testIpamPoolMonitor.CachedNNC.Spec.IPsNotInUse, 1, "IPAMPoolMonitor cached NNC Spec is not reflecting the initial set values")
380-
381-
// check for cached NNC Status struct values
382-
assert.EqualValues(t, 10, testIpamPoolMonitor.CachedNNC.Status.Scaler.BatchSize, "IPAMPoolMonitor cached NNC Status is not reflecting the initial set values")
383-
assert.EqualValues(t, 150, testIpamPoolMonitor.CachedNNC.Status.Scaler.ReleaseThresholdPercent, "IPAMPoolMonitor cached NNC Status is not reflecting the initial set values")
384-
assert.EqualValues(t, 50, testIpamPoolMonitor.CachedNNC.Status.Scaler.RequestThresholdPercent, "IPAMPoolMonitor cached NNC Status is not reflecting the initial set values")
385-
assert.Len(t, testIpamPoolMonitor.CachedNNC.Status.NetworkContainers, 1, "Expected only one Network Container in the list")
386-
387319
t.Logf("In-memory Data: ")
388320
for i := range inmemory.HTTPRestServiceData.PodIPIDByPodInterfaceKey {
389321
t.Logf("PodIPIDByOrchestratorContext: %+v", inmemory.HTTPRestServiceData.PodIPIDByPodInterfaceKey[i])
390322
}
391323
t.Logf("PodIPConfigState: %+v", inmemory.HTTPRestServiceData.PodIPConfigState)
392-
t.Logf("IPAMPoolMonitor: %+v", inmemory.HTTPRestServiceData.IPAMPoolMonitor)
393324
}
394325

395326
func TestNew(t *testing.T) {

cns/cmd/cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func getInMemory(ctx context.Context, client *client.Client) error {
9595
if err != nil {
9696
return err
9797
}
98-
fmt.Printf("PodIPIDByOrchestratorContext: %v\nPodIPConfigState: %v\nIPAMPoolMonitor: %v\n",
99-
data.HTTPRestServiceData.PodIPIDByPodInterfaceKey, data.HTTPRestServiceData.PodIPConfigState, data.HTTPRestServiceData.IPAMPoolMonitor)
98+
fmt.Printf("PodIPIDByOrchestratorContext: %v\nPodIPConfigState: %v\n",
99+
data.HTTPRestServiceData.PodIPIDByPodInterfaceKey, data.HTTPRestServiceData.PodIPConfigState)
100100
return nil
101101
}

cns/restserver/api_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,6 @@ func startService() error {
16861686
svc = service.(*HTTPRestService)
16871687
svc.Name = "cns-test-server"
16881688

1689-
svc.IPAMPoolMonitor = &fakes.MonitorFake{}
16901689
nmagentClient.GetNCVersionListF = func(context.Context) (nmagent.NCVersionList, error) {
16911690
var hostVersionNeedsUpdateContainers []string
16921691
for idx := range svc.state.ContainerStatus {

cns/restserver/internalapi_test.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -835,18 +835,6 @@ func createAndValidateNCRequest(t *testing.T, secondaryIPConfigs map[string]cns.
835835
if returnCode != 0 {
836836
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
837837
}
838-
_ = svc.IPAMPoolMonitor.Update(&v1alpha.NodeNetworkConfig{
839-
Status: v1alpha.NodeNetworkConfigStatus{
840-
Scaler: v1alpha.Scaler{
841-
BatchSize: batchSize,
842-
ReleaseThresholdPercent: releasePercent,
843-
RequestThresholdPercent: requestPercent,
844-
},
845-
},
846-
Spec: v1alpha.NodeNetworkConfigSpec{
847-
RequestedIPCount: initPoolSize,
848-
},
849-
})
850838
validateNetworkRequest(t, *req)
851839
}
852840

@@ -1061,18 +1049,6 @@ func createNCReqInternal(t *testing.T, secondaryIPConfigs map[string]cns.Seconda
10611049
if returnCode != 0 {
10621050
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
10631051
}
1064-
_ = svc.IPAMPoolMonitor.Update(&v1alpha.NodeNetworkConfig{
1065-
Status: v1alpha.NodeNetworkConfigStatus{
1066-
Scaler: v1alpha.Scaler{
1067-
BatchSize: batchSize,
1068-
ReleaseThresholdPercent: releasePercent,
1069-
RequestThresholdPercent: requestPercent,
1070-
},
1071-
},
1072-
Spec: v1alpha.NodeNetworkConfigSpec{
1073-
RequestedIPCount: initPoolSize,
1074-
},
1075-
})
10761052
return *req
10771053
}
10781054

cns/restserver/ipam.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,10 @@ func (service *HTTPRestService) handleDebugPodContext(w http.ResponseWriter, r *
573573
func (service *HTTPRestService) handleDebugRestData(w http.ResponseWriter, r *http.Request) {
574574
service.RLock()
575575
defer service.RUnlock()
576-
if service.IPAMPoolMonitor == nil {
577-
http.Error(w, "not ready", http.StatusServiceUnavailable)
578-
return
579-
}
580576
resp := GetHTTPServiceDataResponse{
581577
HTTPRestServiceData: HTTPRestServiceData{
582578
PodIPIDByPodInterfaceKey: service.PodIPIDByPodInterfaceKey,
583579
PodIPConfigState: service.PodIPConfigState,
584-
IPAMPoolMonitor: service.IPAMPoolMonitor.GetStateSnapshot(),
585580
},
586581
}
587582
err := service.Listener.Encode(w, &resp)

cns/restserver/ipam_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright 2020 Microsoft. All rights reserved.
2-
// MIT License
3-
41
package restserver
52

63
import (
@@ -18,7 +15,6 @@ import (
1815
"github.com/Azure/azure-container-networking/cns/middlewares"
1916
"github.com/Azure/azure-container-networking/cns/middlewares/mock"
2017
"github.com/Azure/azure-container-networking/cns/types"
21-
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
2218
"github.com/Azure/azure-container-networking/store"
2319
"github.com/pkg/errors"
2420
"github.com/stretchr/testify/assert"
@@ -69,7 +65,6 @@ func getTestService() *HTTPRestService {
6965
var config common.ServiceConfig
7066
httpsvc, _ := NewHTTPRestService(&config, &fakes.WireserverClientFake{}, &fakes.WireserverProxyFake{}, &fakes.NMAgentClientFake{}, store.NewMockStore(""), nil, nil)
7167
svc = httpsvc
72-
httpsvc.IPAMPoolMonitor = &fakes.MonitorFake{}
7368
setOrchestratorTypeInternal(cns.KubernetesCRD)
7469

7570
return httpsvc
@@ -1192,20 +1187,6 @@ func TestIPAMMarkIPAsPendingWithPendingProgrammingIPs(t *testing.T) {
11921187
if returnCode != 0 {
11931188
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
11941189
}
1195-
svc.IPAMPoolMonitor.Update(
1196-
&v1alpha.NodeNetworkConfig{
1197-
Status: v1alpha.NodeNetworkConfigStatus{
1198-
Scaler: v1alpha.Scaler{
1199-
BatchSize: batchSize,
1200-
ReleaseThresholdPercent: releasePercent,
1201-
RequestThresholdPercent: requestPercent,
1202-
},
1203-
},
1204-
Spec: v1alpha.NodeNetworkConfigSpec{
1205-
RequestedIPCount: initPoolSize,
1206-
},
1207-
},
1208-
)
12091190
// Release pending programming IPs
12101191
ips, err := svc.MarkIPAsPendingRelease(2)
12111192
if err != nil {

cns/restserver/restserver.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type HTTPRestService struct {
6161
networkContainer *networkcontainers.NetworkContainers
6262
PodIPIDByPodInterfaceKey map[string][]string // PodInterfaceId is key and value is slice of Pod IP (SecondaryIP) uuids.
6363
PodIPConfigState map[string]cns.IPConfigurationStatus // Secondary IP ID(uuid) is key
64-
IPAMPoolMonitor cns.IPAMPoolMonitor
6564
routingTable *routes.RoutingTable
6665
store store.KeyValueStore
6766
state *httpRestServiceState
@@ -113,7 +112,6 @@ type GetHTTPServiceDataResponse struct {
113112
type HTTPRestServiceData struct { //nolint:musttag // not tagging struct for revert-PR
114113
PodIPIDByPodInterfaceKey map[string][]string // PodInterfaceId is key and value is slice of Pod IP uuids.
115114
PodIPConfigState map[string]cns.IPConfigurationStatus // secondaryipid(uuid) is key
116-
IPAMPoolMonitor cns.IpamPoolMonitorStateSnapshot
117115
}
118116

119117
type Response struct {

0 commit comments

Comments
 (0)