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
17 changes: 7 additions & 10 deletions cns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package cns

import (
"context"
"encoding/json"

"github.com/Azure/azure-container-networking/cns/common"
nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
)

// Container Network Service remote API Contract
Expand Down Expand Up @@ -36,8 +38,10 @@ type HTTPService interface {
SetNodeOrchestrator(*SetOrchestratorTypeRequest)
SyncNodeStatus(string, string, string, json.RawMessage) (int, string)
GetAvailableIPConfigs() []IPConfigurationStatus
GetAllocatedIPConfigs() []IPConfigurationStatus
GetPendingReleaseIPConfigs() []IPConfigurationStatus
GetPodIPConfigState() map[string]IPConfigurationStatus
MarkIPsAsPending(numberToMark int) (map[string]SecondaryIPConfig, error)
MarkIPsAsPending(numberToMark int) (map[string]IPConfigurationStatus, error)
}

// This is used for KubernetesCRD orchastrator Type where NC has multiple ips.
Expand Down Expand Up @@ -160,16 +164,9 @@ type NodeConfiguration struct {
NodeID string
NodeSubnet Subnet
}

type IPAMPoolMonitor interface {
Start() error
UpdatePoolLimitsTransacted(ScalarUnits)
}

type ScalarUnits struct {
BatchSize int64
RequestThresholdPercent int64
ReleaseThresholdPercent int64
Start(ctx context.Context, poolMonitorRefreshMilliseconds int) error
Update(scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error
}

// Response describes generic response from CNS.
Expand Down
9 changes: 6 additions & 3 deletions cns/cnsclient/apiclient.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cnsclient

import "github.com/Azure/azure-container-networking/cns"
import (
"github.com/Azure/azure-container-networking/cns"
nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
)

// APIClient interface to update cns state
type APIClient interface {
ReconcileNCState(nc *cns.CreateNetworkContainerRequest, pods map[string]cns.KubernetesPodInfo, scalarUnits cns.ScalarUnits) error
CreateOrUpdateNC(nc cns.CreateNetworkContainerRequest, scalarUnits cns.ScalarUnits) error
ReconcileNCState(nc *cns.CreateNetworkContainerRequest, pods map[string]cns.KubernetesPodInfo, scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error
CreateOrUpdateNC(nc cns.CreateNetworkContainerRequest, scalar nnc.Scaler, spec nnc.NodeNetworkConfigSpec) error
}
10 changes: 6 additions & 4 deletions cns/cnsclient/cnsclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/common"
"github.com/Azure/azure-container-networking/cns/fakes"
"github.com/Azure/azure-container-networking/cns/ipampoolmonitor"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/restserver"
"github.com/Azure/azure-container-networking/log"
Expand All @@ -31,6 +30,10 @@ const (
gatewayIp = "10.0.0.1"
subnetPrfixLength = 24
dockerContainerType = cns.Docker
releasePercent = 50
requestPercent = 100
batchSize = 10
initPoolSize = 10
)

var (
Expand All @@ -39,7 +42,6 @@ var (

func addTestStateToRestServer(t *testing.T, secondaryIps []string) {
var ipConfig cns.IPConfiguration
var scalarUnits cns.ScalarUnits
ipConfig.DNSServers = dnsservers
ipConfig.GatewayIPAddress = gatewayIp
var ipSubnet cns.IPSubnet
Expand All @@ -63,7 +65,7 @@ func addTestStateToRestServer(t *testing.T, secondaryIps []string) {
SecondaryIPConfigs: secondaryIPConfigs,
}

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

if err != nil {
logger.Errorf("Failed to create CNS object, err:%v.\n", err)
Expand Down
9 changes: 5 additions & 4 deletions cns/cnsclient/httpapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/restserver"
nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
)

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

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

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

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

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