Skip to content

Commit

Permalink
Move k8s code inside COCommon Orchestrator and split topology interface
Browse files Browse the repository at this point in the history
  • Loading branch information
shalini-b committed Jul 22, 2021
1 parent d662544 commit 13cc25d
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 524 deletions.
8 changes: 8 additions & 0 deletions pkg/common/unittestcommon/types.go
Expand Up @@ -60,3 +60,11 @@ type MockVolumeMigrationService interface {
type fakeVolumeOperationRequestInterface struct {
volumeOperationRequestMap map[string]*cnsvolumeoperationrequest.VolumeOperationRequestDetails
}

// mockControllerVolumeTopology is a mock of the k8sorchestrator controllerVolumeTopology type.
type mockControllerVolumeTopology struct {
}

// mockNodeVolumeTopology is a mock of the k8sorchestrator nodeVolumeTopology type.
type mockNodeVolumeTopology struct {
}
34 changes: 34 additions & 0 deletions pkg/common/unittestcommon/utils.go
Expand Up @@ -22,14 +22,17 @@ import (
"strconv"
"sync"

"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/vsphere-csi-driver/pkg/apis/migration"

cnsvolume "sigs.k8s.io/vsphere-csi-driver/pkg/common/cns-lib/volume"
cnsvsphere "sigs.k8s.io/vsphere-csi-driver/pkg/common/cns-lib/vsphere"
cnsconfig "sigs.k8s.io/vsphere-csi-driver/pkg/common/config"
"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/common"
"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/common/commonco"
commoncotypes "sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/common/commonco/types"
"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/logger"
"sigs.k8s.io/vsphere-csi-driver/pkg/internalapis/cnsvolumeoperationrequest"
cnsvolumeoperationrequestv1alpha1 "sigs.k8s.io/vsphere-csi-driver/pkg/internalapis/cnsvolumeoperationrequest/v1alpha1"
Expand Down Expand Up @@ -97,6 +100,37 @@ func (c *FakeK8SOrchestrator) ClearFakeAttached(ctx context.Context, volumeID st
"ClearFakeAttached for FakeK8SOrchestrator is not yet implemented.")
}

// GetNodeTopologyLabels fetches the topology information of a node from the CSINodeTopology CR.
func (nodeTopology *mockNodeVolumeTopology) GetNodeTopologyLabels(ctx context.Context, info *commoncotypes.NodeInfo) (
map[string]string, error) {
log := logger.GetLogger(ctx)
return nil, logger.LogNewError(log, "GetNodeTopologyLabels is not yet implemented.")
}

// GetSharedDatastoresInTopology retrieves shared datastores of nodes which satisfy a given topology requirement.
func (cntrlTopology *mockControllerVolumeTopology) GetSharedDatastoresInTopology(ctx context.Context,
topologyRequirement *csi.TopologyRequirement) ([]*cnsvsphere.DatastoreInfo, map[string][]map[string]string,
error) {
log := logger.GetLogger(ctx)
return nil, nil, logger.LogNewError(log, "GetSharedDatastoresInTopology is not yet implemented.")
}

// InitTopologyServiceInController returns a singleton implementation of the
// commoncotypes.ControllerTopologyService interface for the FakeK8SOrchestrator.
func (c *FakeK8SOrchestrator) InitTopologyServiceInController(ctx context.Context) (
commoncotypes.ControllerTopologyService, error) {
// TODO: Mock the k8sClients, node manager and informer.
return &mockControllerVolumeTopology{}, nil
}

// InitTopologyServiceInNode returns a singleton implementation of the
//commoncotypes.NodeTopologyService interface for the FakeK8SOrchestrator.
func (c *FakeK8SOrchestrator) InitTopologyServiceInNode(ctx context.Context) (commoncotypes.NodeTopologyService,
error) {
// TODO: Mock the custom k8sClients and watchers.
return &mockNodeVolumeTopology{}, nil
}

// GetFakeVolumeMigrationService returns the mocked VolumeMigrationService
func GetFakeVolumeMigrationService(
ctx context.Context,
Expand Down
7 changes: 7 additions & 0 deletions pkg/csi/service/common/commonco/coagnostic.go
Expand Up @@ -25,6 +25,7 @@ import (

"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/common"
"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/common/commonco/k8sorchestrator"
"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/common/commonco/types"
"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/logger"
)

Expand All @@ -44,6 +45,12 @@ type COCommonInterface interface {
MarkFakeAttached(ctx context.Context, volumeID string) error
// Check if the volume was fake attached, and unmark it as not fake attached.
ClearFakeAttached(ctx context.Context, volumeID string) error
// InitTopologyServiceInController initializes the necessary resources
// required for topology related functionality in the controller.
InitTopologyServiceInController(ctx context.Context) (types.ControllerTopologyService, error)
// InitTopologyServiceInNode initializes the necessary resources
// required for topology related functionality in the nodes.
InitTopologyServiceInNode(ctx context.Context) (types.NodeTopologyService, error)
}

// GetContainerOrchestratorInterface returns orchestrator object for a given
Expand Down

0 comments on commit 13cc25d

Please sign in to comment.