diff --git a/cns/cnsclient/apiclient.go b/cns/cnsclient/apiclient.go index d3a103239..091bd61f2 100644 --- a/cns/cnsclient/apiclient.go +++ b/cns/cnsclient/apiclient.go @@ -4,5 +4,6 @@ import "github.com/Azure/azure-container-networking/cns" // APIClient interface to update cns state type APIClient interface { - UpdateCNSState(createNetworkContainerRequest *cns.CreateNetworkContainerRequest) error + InitCNSState(*cns.CreateNetworkContainerRequest, map[string]*cns.KubernetesPodInfo) error + CreateOrUpdateNC(*cns.CreateNetworkContainerRequest) error } diff --git a/cns/cnsclient/httpapi/client.go b/cns/cnsclient/httpapi/client.go index 16740ec25..f664fc5ea 100644 --- a/cns/cnsclient/httpapi/client.go +++ b/cns/cnsclient/httpapi/client.go @@ -10,8 +10,34 @@ type Client struct { RestService *restserver.HTTPRestService } -// UpdateCNSState updates cns state -func (client *Client) UpdateCNSState(createNetworkContainerRequest *cns.CreateNetworkContainerRequest) error { - //Mat will pick up from here +// CreateOrUpdateNC updates cns state +func (client *Client) CreateOrUpdateNC(ncRequest *cns.CreateNetworkContainerRequest) error { + // var ( + // ipConfigsToAdd []*cns.ContainerIPConfigState + // ) + + // //Lock to read ipconfigs + // client.RestService.Lock() + + // //Only add ipconfigs that don't exist in cns state already + // for _, ipConfig := range ipConfigs { + // if _, ok := client.RestService.PodIPConfigState[ipConfig.ID]; !ok { + // ipConfig.State = cns.Available + // ipConfigsToAdd = append(ipConfigsToAdd, ipConfig) + // } + // } + + // client.RestService.Unlock() + // leave empty + return nil //client.RestService.AddIPConfigsToState(ipConfigsToAdd) +} + +// InitCNSState initializes cns state +func (client *Client) InitCNSState(ncRequest *cns.CreateNetworkContainerRequest, podInfoByIP map[string]*cns.KubernetesPodInfo) error { + // client.RestService.Lock() + // client.RestService.ReadyToIPAM = true + // client.RestService.Unlock() + + // return client.RestService.AddIPConfigsToState(ipConfigs) return nil } diff --git a/cns/requestcontroller/kubecontroller/crdreconciler.go b/cns/requestcontroller/kubecontroller/crdreconciler.go index e958a70d5..41a761c24 100644 --- a/cns/requestcontroller/kubecontroller/crdreconciler.go +++ b/cns/requestcontroller/kubecontroller/crdreconciler.go @@ -45,7 +45,7 @@ func (r *CrdReconciler) Reconcile(request reconcile.Request) (reconcile.Result, } //TODO: process the nc request on CNS side - r.CNSClient.UpdateCNSState(ncRequest) + r.CNSClient.CreateOrUpdateNC(ncRequest) return reconcile.Result{}, nil } diff --git a/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go b/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go index 06c7b661c..3e86d3126 100644 --- a/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go +++ b/cns/requestcontroller/kubecontroller/crdrequestcontroller_test.go @@ -81,11 +81,15 @@ func (mc MockKubeClient) Update(ctx context.Context, obj runtime.Object, opts .. type MockCNSClient struct{} // we're just testing that reconciler interacts with CNS on Reconcile(). -func (mi *MockCNSClient) UpdateCNSState(createNetworkContainerRequest *cns.CreateNetworkContainerRequest) error { +func (mi *MockCNSClient) CreateOrUpdateNC(ncRequest *cns.CreateNetworkContainerRequest) error { mockCNSUpdated = true return nil } +func (mi *MockCNSClient) InitCNSState(ncRequest *cns.CreateNetworkContainerRequest, podInfoByIP map[string]*cns.KubernetesPodInfo) error { + return nil +} + func ResetCNSInteractionFlag() { mockCNSUpdated = false }