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 <rbtr@users.noreply.github.com>
This commit is contained in:
Родитель
e475038704
Коммит
f0ff6cfae0
|
@ -22,13 +22,11 @@ import (
|
|||
"github.com/Azure/azure-container-networking/cns/logger"
|
||||
"github.com/Azure/azure-container-networking/cns/restserver"
|
||||
"github.com/Azure/azure-container-networking/cns/types"
|
||||
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
|
||||
"github.com/Azure/azure-container-networking/log"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -99,24 +97,6 @@ func addTestStateToRestServer(t *testing.T, secondaryIps []string) {
|
|||
if returnCode != 0 {
|
||||
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
|
||||
}
|
||||
|
||||
_ = svc.IPAMPoolMonitor.Update(&v1alpha.NodeNetworkConfig{
|
||||
Spec: v1alpha.NodeNetworkConfigSpec{
|
||||
RequestedIPCount: 16,
|
||||
IPsNotInUse: []string{"abc"},
|
||||
},
|
||||
Status: v1alpha.NodeNetworkConfigStatus{
|
||||
Scaler: v1alpha.Scaler{
|
||||
BatchSize: batchSize,
|
||||
ReleaseThresholdPercent: releasePercent,
|
||||
RequestThresholdPercent: requestPercent,
|
||||
MaxIPCount: 250,
|
||||
},
|
||||
NetworkContainers: []v1alpha.NetworkContainer{
|
||||
{},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func getIPNetFromResponse(resp *cns.IPConfigResponse) (net.IPNet, error) {
|
||||
|
@ -174,39 +154,6 @@ func TestMain(m *testing.M) {
|
|||
httpRestService, err := restserver.NewHTTPRestService(&config, &fakes.WireserverClientFake{}, &fakes.WireserverProxyFake{}, &fakes.NMAgentClientFake{}, nil, nil, nil)
|
||||
svc = httpRestService
|
||||
httpRestService.Name = "cns-test-server"
|
||||
fakeNNC := v1alpha.NodeNetworkConfig{
|
||||
TypeMeta: metav1.TypeMeta{},
|
||||
ObjectMeta: metav1.ObjectMeta{},
|
||||
Spec: v1alpha.NodeNetworkConfigSpec{
|
||||
RequestedIPCount: 16,
|
||||
IPsNotInUse: []string{"abc"},
|
||||
},
|
||||
Status: v1alpha.NodeNetworkConfigStatus{
|
||||
Scaler: v1alpha.Scaler{
|
||||
BatchSize: 10,
|
||||
ReleaseThresholdPercent: 150,
|
||||
RequestThresholdPercent: 50,
|
||||
MaxIPCount: 250,
|
||||
},
|
||||
NetworkContainers: []v1alpha.NetworkContainer{
|
||||
{
|
||||
ID: "nc1",
|
||||
PrimaryIP: "10.0.0.11",
|
||||
SubnetName: "sub1",
|
||||
IPAssignments: []v1alpha.IPAssignment{
|
||||
{
|
||||
Name: "ip1",
|
||||
IP: "10.0.0.10",
|
||||
},
|
||||
},
|
||||
DefaultGateway: "10.0.0.1",
|
||||
SubnetAddressSpace: "10.0.0.0/24",
|
||||
Version: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
httpRestService.IPAMPoolMonitor = &fakes.MonitorFake{IPsNotInUseCount: 13, NodeNetworkConfig: &fakeNNC}
|
||||
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to create CNS object, err:%v.\n", err)
|
||||
|
@ -369,27 +316,11 @@ func TestCNSClientDebugAPI(t *testing.T) {
|
|||
}
|
||||
assert.NotEmpty(t, inmemory.HTTPRestServiceData.PodIPConfigState, "PodIpConfigState with at least 1 entry expected")
|
||||
|
||||
testIpamPoolMonitor := inmemory.HTTPRestServiceData.IPAMPoolMonitor
|
||||
assert.EqualValues(t, 5, testIpamPoolMonitor.MinimumFreeIps, "IPAMPoolMonitor state is not reflecting the initial set values")
|
||||
assert.EqualValues(t, 15, testIpamPoolMonitor.MaximumFreeIps, "IPAMPoolMonitor state is not reflecting the initial set values")
|
||||
assert.EqualValues(t, 13, testIpamPoolMonitor.UpdatingIpsNotInUseCount, "IPAMPoolMonitor state is not reflecting the initial set values")
|
||||
|
||||
// check for cached NNC Spec struct values
|
||||
assert.EqualValues(t, 16, testIpamPoolMonitor.CachedNNC.Spec.RequestedIPCount, "IPAMPoolMonitor cached NNC Spec is not reflecting the initial set values")
|
||||
assert.Len(t, testIpamPoolMonitor.CachedNNC.Spec.IPsNotInUse, 1, "IPAMPoolMonitor cached NNC Spec is not reflecting the initial set values")
|
||||
|
||||
// check for cached NNC Status struct values
|
||||
assert.EqualValues(t, 10, testIpamPoolMonitor.CachedNNC.Status.Scaler.BatchSize, "IPAMPoolMonitor cached NNC Status is not reflecting the initial set values")
|
||||
assert.EqualValues(t, 150, testIpamPoolMonitor.CachedNNC.Status.Scaler.ReleaseThresholdPercent, "IPAMPoolMonitor cached NNC Status is not reflecting the initial set values")
|
||||
assert.EqualValues(t, 50, testIpamPoolMonitor.CachedNNC.Status.Scaler.RequestThresholdPercent, "IPAMPoolMonitor cached NNC Status is not reflecting the initial set values")
|
||||
assert.Len(t, testIpamPoolMonitor.CachedNNC.Status.NetworkContainers, 1, "Expected only one Network Container in the list")
|
||||
|
||||
t.Logf("In-memory Data: ")
|
||||
for i := range inmemory.HTTPRestServiceData.PodIPIDByPodInterfaceKey {
|
||||
t.Logf("PodIPIDByOrchestratorContext: %+v", inmemory.HTTPRestServiceData.PodIPIDByPodInterfaceKey[i])
|
||||
}
|
||||
t.Logf("PodIPConfigState: %+v", inmemory.HTTPRestServiceData.PodIPConfigState)
|
||||
t.Logf("IPAMPoolMonitor: %+v", inmemory.HTTPRestServiceData.IPAMPoolMonitor)
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
|
|
|
@ -95,7 +95,7 @@ func getInMemory(ctx context.Context, client *client.Client) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("PodIPIDByOrchestratorContext: %v\nPodIPConfigState: %v\nIPAMPoolMonitor: %v\n",
|
||||
data.HTTPRestServiceData.PodIPIDByPodInterfaceKey, data.HTTPRestServiceData.PodIPConfigState, data.HTTPRestServiceData.IPAMPoolMonitor)
|
||||
fmt.Printf("PodIPIDByOrchestratorContext: %v\nPodIPConfigState: %v\n",
|
||||
data.HTTPRestServiceData.PodIPIDByPodInterfaceKey, data.HTTPRestServiceData.PodIPConfigState)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1686,7 +1686,6 @@ func startService() error {
|
|||
svc = service.(*HTTPRestService)
|
||||
svc.Name = "cns-test-server"
|
||||
|
||||
svc.IPAMPoolMonitor = &fakes.MonitorFake{}
|
||||
nmagentClient.GetNCVersionListF = func(context.Context) (nmagent.NCVersionList, error) {
|
||||
var hostVersionNeedsUpdateContainers []string
|
||||
for idx := range svc.state.ContainerStatus {
|
||||
|
|
|
@ -835,18 +835,6 @@ func createAndValidateNCRequest(t *testing.T, secondaryIPConfigs map[string]cns.
|
|||
if returnCode != 0 {
|
||||
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
|
||||
}
|
||||
_ = svc.IPAMPoolMonitor.Update(&v1alpha.NodeNetworkConfig{
|
||||
Status: v1alpha.NodeNetworkConfigStatus{
|
||||
Scaler: v1alpha.Scaler{
|
||||
BatchSize: batchSize,
|
||||
ReleaseThresholdPercent: releasePercent,
|
||||
RequestThresholdPercent: requestPercent,
|
||||
},
|
||||
},
|
||||
Spec: v1alpha.NodeNetworkConfigSpec{
|
||||
RequestedIPCount: initPoolSize,
|
||||
},
|
||||
})
|
||||
validateNetworkRequest(t, *req)
|
||||
}
|
||||
|
||||
|
@ -1061,18 +1049,6 @@ func createNCReqInternal(t *testing.T, secondaryIPConfigs map[string]cns.Seconda
|
|||
if returnCode != 0 {
|
||||
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
|
||||
}
|
||||
_ = svc.IPAMPoolMonitor.Update(&v1alpha.NodeNetworkConfig{
|
||||
Status: v1alpha.NodeNetworkConfigStatus{
|
||||
Scaler: v1alpha.Scaler{
|
||||
BatchSize: batchSize,
|
||||
ReleaseThresholdPercent: releasePercent,
|
||||
RequestThresholdPercent: requestPercent,
|
||||
},
|
||||
},
|
||||
Spec: v1alpha.NodeNetworkConfigSpec{
|
||||
RequestedIPCount: initPoolSize,
|
||||
},
|
||||
})
|
||||
return *req
|
||||
}
|
||||
|
||||
|
|
|
@ -573,15 +573,10 @@ func (service *HTTPRestService) handleDebugPodContext(w http.ResponseWriter, r *
|
|||
func (service *HTTPRestService) handleDebugRestData(w http.ResponseWriter, r *http.Request) {
|
||||
service.RLock()
|
||||
defer service.RUnlock()
|
||||
if service.IPAMPoolMonitor == nil {
|
||||
http.Error(w, "not ready", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
resp := GetHTTPServiceDataResponse{
|
||||
HTTPRestServiceData: HTTPRestServiceData{
|
||||
PodIPIDByPodInterfaceKey: service.PodIPIDByPodInterfaceKey,
|
||||
PodIPConfigState: service.PodIPConfigState,
|
||||
IPAMPoolMonitor: service.IPAMPoolMonitor.GetStateSnapshot(),
|
||||
},
|
||||
}
|
||||
err := service.Listener.Encode(w, &resp)
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// Copyright 2020 Microsoft. All rights reserved.
|
||||
// MIT License
|
||||
|
||||
package restserver
|
||||
|
||||
import (
|
||||
|
@ -18,7 +15,6 @@ import (
|
|||
"github.com/Azure/azure-container-networking/cns/middlewares"
|
||||
"github.com/Azure/azure-container-networking/cns/middlewares/mock"
|
||||
"github.com/Azure/azure-container-networking/cns/types"
|
||||
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
|
||||
"github.com/Azure/azure-container-networking/store"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -69,7 +65,6 @@ func getTestService() *HTTPRestService {
|
|||
var config common.ServiceConfig
|
||||
httpsvc, _ := NewHTTPRestService(&config, &fakes.WireserverClientFake{}, &fakes.WireserverProxyFake{}, &fakes.NMAgentClientFake{}, store.NewMockStore(""), nil, nil)
|
||||
svc = httpsvc
|
||||
httpsvc.IPAMPoolMonitor = &fakes.MonitorFake{}
|
||||
setOrchestratorTypeInternal(cns.KubernetesCRD)
|
||||
|
||||
return httpsvc
|
||||
|
@ -1192,20 +1187,6 @@ func TestIPAMMarkIPAsPendingWithPendingProgrammingIPs(t *testing.T) {
|
|||
if returnCode != 0 {
|
||||
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
|
||||
}
|
||||
svc.IPAMPoolMonitor.Update(
|
||||
&v1alpha.NodeNetworkConfig{
|
||||
Status: v1alpha.NodeNetworkConfigStatus{
|
||||
Scaler: v1alpha.Scaler{
|
||||
BatchSize: batchSize,
|
||||
ReleaseThresholdPercent: releasePercent,
|
||||
RequestThresholdPercent: requestPercent,
|
||||
},
|
||||
},
|
||||
Spec: v1alpha.NodeNetworkConfigSpec{
|
||||
RequestedIPCount: initPoolSize,
|
||||
},
|
||||
},
|
||||
)
|
||||
// Release pending programming IPs
|
||||
ips, err := svc.MarkIPAsPendingRelease(2)
|
||||
if err != nil {
|
||||
|
|
|
@ -61,7 +61,6 @@ type HTTPRestService struct {
|
|||
networkContainer *networkcontainers.NetworkContainers
|
||||
PodIPIDByPodInterfaceKey map[string][]string // PodInterfaceId is key and value is slice of Pod IP (SecondaryIP) uuids.
|
||||
PodIPConfigState map[string]cns.IPConfigurationStatus // Secondary IP ID(uuid) is key
|
||||
IPAMPoolMonitor cns.IPAMPoolMonitor
|
||||
routingTable *routes.RoutingTable
|
||||
store store.KeyValueStore
|
||||
state *httpRestServiceState
|
||||
|
@ -113,7 +112,6 @@ type GetHTTPServiceDataResponse struct {
|
|||
type HTTPRestServiceData struct { //nolint:musttag // not tagging struct for revert-PR
|
||||
PodIPIDByPodInterfaceKey map[string][]string // PodInterfaceId is key and value is slice of Pod IP uuids.
|
||||
PodIPConfigState map[string]cns.IPConfigurationStatus // secondaryipid(uuid) is key
|
||||
IPAMPoolMonitor cns.IpamPoolMonitorStateSnapshot
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
|
|
Загрузка…
Ссылка в новой задаче