CNS Client API interface and skeleton implementation (#615)
* Adding api template and skeleton to unblock Neha * Removed new container type and reversed api order * Fixed tests and reconcile call
This commit is contained in:
Родитель
9d6b6c9194
Коммит
853870c5a5
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче