Skip to content

Commit 51a8884

Browse files
authored
CNS Pool Scaling (#668)
* init with test framework * handle multiple batch size pool request * test verification * handle batch size multiples * address feedback * fix test * remove test struct from fakes * fix nil test * fix tests * feedback * scale down * init scale down scale down testing test work reconcile fake requestcontroller test revision check for cached nonreleased ipconfigs remove test struct from decrease fakes initial integration fix interface signature test get pending release futher integration tseting test fixes * start feedback * update request controller * fixed tests * test fix * ipampoolmonitor in cns not request controller * init fake ipam pool monitor
1 parent 4ecfc9b commit 51a8884

File tree

19 files changed

+925
-162
lines changed

19 files changed

+925
-162
lines changed

cns/api.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
package cns
55

66
import (
7+
"context"
78
"encoding/json"
89

910
"github.com/Azure/azure-container-networking/cns/common"
11+
nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
1012
)
1113

1214
// Container Network Service remote API Contract
@@ -36,8 +38,10 @@ type HTTPService interface {
3638
SetNodeOrchestrator(*SetOrchestratorTypeRequest)
3739
SyncNodeStatus(string, string, string, json.RawMessage) (int, string)
3840
GetAvailableIPConfigs() []IPConfigurationStatus
41+
GetAllocatedIPConfigs() []IPConfigurationStatus
42+
GetPendingReleaseIPConfigs() []IPConfigurationStatus
3943
GetPodIPConfigState() map[string]IPConfigurationStatus
40-
MarkIPsAsPending(numberToMark int) (map[string]SecondaryIPConfig, error)
44+
MarkIPsAsPending(numberToMark int) (map[string]IPConfigurationStatus, error)
4145
}
4246

4347
// This is used for KubernetesCRD orchastrator Type where NC has multiple ips.
@@ -160,16 +164,9 @@ type NodeConfiguration struct {
160164
NodeID string
161165
NodeSubnet Subnet
162166
}
163-
164167
type IPAMPoolMonitor interface {
165-
Start() error
166-
UpdatePoolLimitsTransacted(ScalarUnits)
167-
}
168-
169-
type ScalarUnits struct {
170-
BatchSize int64
171-
RequestThresholdPercent int64
172-
ReleaseThresholdPercent int64
168+
Start(ctx context.Context, poolMonitorRefreshMilliseconds int) error
169+
Update(scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error
173170
}
174171

175172
// Response describes generic response from CNS.

cns/cnsclient/apiclient.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package cnsclient
22

3-
import "github.com/Azure/azure-container-networking/cns"
3+
import (
4+
"github.com/Azure/azure-container-networking/cns"
5+
nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
6+
)
47

58
// APIClient interface to update cns state
69
type APIClient interface {
7-
ReconcileNCState(nc *cns.CreateNetworkContainerRequest, pods map[string]cns.KubernetesPodInfo, scalarUnits cns.ScalarUnits) error
8-
CreateOrUpdateNC(nc cns.CreateNetworkContainerRequest, scalarUnits cns.ScalarUnits) error
10+
ReconcileNCState(nc *cns.CreateNetworkContainerRequest, pods map[string]cns.KubernetesPodInfo, scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error
11+
CreateOrUpdateNC(nc cns.CreateNetworkContainerRequest, scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error
912
}

cns/cnsclient/cnsclient_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/Azure/azure-container-networking/cns"
1616
"github.com/Azure/azure-container-networking/cns/common"
1717
"github.com/Azure/azure-container-networking/cns/fakes"
18-
"github.com/Azure/azure-container-networking/cns/ipampoolmonitor"
1918
"github.com/Azure/azure-container-networking/cns/logger"
2019
"github.com/Azure/azure-container-networking/cns/restserver"
2120
"github.com/Azure/azure-container-networking/log"
@@ -31,6 +30,10 @@ const (
3130
gatewayIp = "10.0.0.1"
3231
subnetPrfixLength = 24
3332
dockerContainerType = cns.Docker
33+
releasePercent = 50
34+
requestPercent = 100
35+
batchSize = 10
36+
initPoolSize = 10
3437
)
3538

3639
var (
@@ -39,7 +42,6 @@ var (
3942

4043
func addTestStateToRestServer(t *testing.T, secondaryIps []string) {
4144
var ipConfig cns.IPConfiguration
42-
var scalarUnits cns.ScalarUnits
4345
ipConfig.DNSServers = dnsservers
4446
ipConfig.GatewayIPAddress = gatewayIp
4547
var ipSubnet cns.IPSubnet
@@ -63,7 +65,7 @@ func addTestStateToRestServer(t *testing.T, secondaryIps []string) {
6365
SecondaryIPConfigs: secondaryIPConfigs,
6466
}
6567

66-
returnCode := svc.CreateOrUpdateNetworkContainerInternal(req, scalarUnits)
68+
returnCode := svc.CreateOrUpdateNetworkContainerInternal(req, fakes.NewFakeScalar(releasePercent, requestPercent, batchSize), fakes.NewFakeNodeNetworkConfigSpec(initPoolSize))
6769
if returnCode != 0 {
6870
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)
6971
}
@@ -123,7 +125,7 @@ func TestMain(m *testing.M) {
123125
httpRestService, err := restserver.NewHTTPRestService(&config, fakes.NewFakeImdsClient())
124126
svc = httpRestService.(*restserver.HTTPRestService)
125127
svc.Name = "cns-test-server"
126-
svc.PoolMonitor = ipampoolmonitor.NewCNSIPAMPoolMonitor(nil, nil)
128+
svc.IPAMPoolMonitor = fakes.NewIPAMPoolMonitorFake()
127129

128130
if err != nil {
129131
logger.Errorf("Failed to create CNS object, err:%v.\n", err)

cns/cnsclient/httpapi/client.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/Azure/azure-container-networking/cns"
77
"github.com/Azure/azure-container-networking/cns/restserver"
8+
nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
89
)
910

1011
// Client implements APIClient interface. Used to update CNS state
@@ -13,8 +14,8 @@ type Client struct {
1314
}
1415

1516
// CreateOrUpdateNC updates cns state
16-
func (client *Client) CreateOrUpdateNC(ncRequest cns.CreateNetworkContainerRequest, scalarUnits cns.ScalarUnits) error {
17-
returnCode := client.RestService.CreateOrUpdateNetworkContainerInternal(ncRequest, scalarUnits)
17+
func (client *Client) CreateOrUpdateNC(ncRequest cns.CreateNetworkContainerRequest, scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error {
18+
returnCode := client.RestService.CreateOrUpdateNetworkContainerInternal(ncRequest, scalar, spec)
1819

1920
if returnCode != 0 {
2021
return fmt.Errorf("Failed to Create NC request: %+v, errorCode: %d", ncRequest, returnCode)
@@ -24,8 +25,8 @@ func (client *Client) CreateOrUpdateNC(ncRequest cns.CreateNetworkContainerReque
2425
}
2526

2627
// ReconcileNCState initializes cns state
27-
func (client *Client) ReconcileNCState(ncRequest *cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.KubernetesPodInfo, scalarUnits cns.ScalarUnits) error {
28-
returnCode := client.RestService.ReconcileNCState(ncRequest, podInfoByIP, scalarUnits)
28+
func (client *Client) ReconcileNCState(ncRequest *cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.KubernetesPodInfo, scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error {
29+
returnCode := client.RestService.ReconcileNCState(ncRequest, podInfoByIP, scalar, spec)
2930

3031
if returnCode != 0 {
3132
return fmt.Errorf("Failed to Reconcile ncState: ncRequest %+v, podInfoMap: %+v, errorCode: %d", *ncRequest, podInfoByIP, returnCode)

0 commit comments

Comments
 (0)