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
20 changes: 11 additions & 9 deletions pkg/csi/service/vanilla/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ func (c *controller) Init(config *config.Config) error {
dsToFileServiceEnabledMap, err := common.IsFileServiceEnabled(ctx, c.manager.VcenterConfig.TargetvSANFileShareDatastoreURLs, c.manager)
if err != nil {
msg := fmt.Sprintf("file service enablement check failed for datastore specified in TargetvSANFileShareDatastoreURLs. err=%v", err)
log.Errorf(msg)
log.Error(msg)
return errors.New(msg)
}
for _, targetFSDatastore := range c.manager.VcenterConfig.TargetvSANFileShareDatastoreURLs {
isFSEnabled := dsToFileServiceEnabledMap[targetFSDatastore]
if !isFSEnabled {
msg := fmt.Sprintf("file service is not enabled on datastore %s specified in TargetvSANFileShareDatastoreURLs", targetFSDatastore)
log.Errorf(msg)
log.Error(msg)
return errors.New(msg)
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func (c *controller) createBlockVolume(ctx context.Context, req *csi.CreateVolum
sharedDatastores, datastoreTopologyMap, err = c.nodeMgr.GetSharedDatastoresInTopology(ctx, topologyRequirement, c.manager.CnsConfig.Labels.Zone, c.manager.CnsConfig.Labels.Region)
if err != nil || len(sharedDatastores) == 0 {
msg := fmt.Sprintf("failed to get shared datastores in topology: %+v. Error: %+v", topologyRequirement, err)
log.Errorf(msg)
log.Error(msg)
return nil, status.Error(codes.NotFound, msg)
}
log.Debugf("Shared datastores [%+v] retrieved for topologyRequirement [%+v] with datastoreTopologyMap [+%v]", sharedDatastores, topologyRequirement, datastoreTopologyMap)
Expand Down Expand Up @@ -523,7 +523,6 @@ func (c *controller) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequ
var volumePath string

// in-tree volume support
var volumeID string
if strings.Contains(req.VolumeId, ".vmdk") {
volumePath = req.VolumeId
}
Expand All @@ -540,7 +539,7 @@ func (c *controller) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequ
} else {
// Migration feature switch is disabled
if volumePath != "" {
msg := fmt.Sprintf("volume-migration feature switch is disabled. Cannot use volume with vmdk path :%q", volumeID)
msg := fmt.Sprintf("volume-migration feature switch is disabled. Cannot use volume with vmdk path :%q", volumePath)
log.Error(msg)
return nil, status.Errorf(codes.Internal, msg)
}
Expand Down Expand Up @@ -624,7 +623,6 @@ func (c *controller) ControllerPublishVolume(ctx context.Context, req *csi.Contr
} else {
// Block Volume
// in-tree volume support
var volumeID string
var volumePath string
if strings.Contains(req.VolumeId, ".vmdk") {
volumePath = req.VolumeId
Expand All @@ -643,7 +641,7 @@ func (c *controller) ControllerPublishVolume(ctx context.Context, req *csi.Contr
} else {
// Migration feature switch is disabled
if volumePath != "" {
msg := fmt.Sprintf("volume-migration feature switch is disabled. Cannot use volume with vmdk path :%q", volumeID)
msg := fmt.Sprintf("volume-migration feature switch is disabled. Cannot use volume with vmdk path :%q", volumePath)
log.Error(msg)
return nil, status.Errorf(codes.Internal, msg)
}
Expand Down Expand Up @@ -683,7 +681,6 @@ func (c *controller) ControllerUnpublishVolume(ctx context.Context, req *csi.Con
}

// in-tree volume support
var volumeID string
var volumePath string
if strings.Contains(req.VolumeId, ".vmdk") {
volumePath = req.VolumeId
Expand All @@ -707,7 +704,7 @@ func (c *controller) ControllerUnpublishVolume(ctx context.Context, req *csi.Con
} else {
// Migration feature switch is disabled
if volumePath != "" {
msg := fmt.Sprintf("volume-migration feature switch is disabled. Cannot use volume with vmdk path :%q", volumeID)
msg := fmt.Sprintf("volume-migration feature switch is disabled. Cannot use volume with vmdk path :%q", volumePath)
log.Error(msg)
return nil, status.Errorf(codes.Internal, msg)
}
Expand Down Expand Up @@ -760,6 +757,11 @@ func (c *controller) ControllerExpandVolume(ctx context.Context, req *csi.Contro
log := logger.GetLogger(ctx)
log.Infof("ControllerExpandVolume: called with args %+v", *req)

if strings.Contains(req.VolumeId, ".vmdk") {
msg := fmt.Sprintf("Cannot expand migrated vSphere volume. :%q", req.VolumeId)
log.Error(msg)
return nil, status.Errorf(codes.Unimplemented, msg)
}
err := validateVanillaControllerExpandVolumeRequest(ctx, req)
if err != nil {
msg := fmt.Sprintf("validation for ExpandVolume Request: %+v has failed. Error: %v", *req, err)
Expand Down
18 changes: 18 additions & 0 deletions pkg/csi/service/vanilla/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,24 @@ func TestExtendVolume(t *testing.T) {
}
}

// TestMigratedExtendVolume helps test ControllerExpandVolume with VolumeId having migrated volume
func TestMigratedExtendVolume(t *testing.T) {
ct := getControllerTest(t)
reqExpand := &csi.ControllerExpandVolumeRequest{
VolumeId: "[vsanDatastore] 08281a5f-a21d-1eff-62d6-02009d0f19a1/004dbb1694f14e3598abef852b113e3b.vmdk",
CapacityRange: &csi.CapacityRange{
RequiredBytes: 1024,
},
}
t.Log(fmt.Sprintf("ControllerExpandVolume will be called with req +%v", *reqExpand))
_, err := ct.controller.ControllerExpandVolume(ctx, reqExpand)
if err != nil {
t.Logf("Expected error received. migrated volume with VMDK path can not be expanded")
} else {
t.Fatal("Expected error not received when ControllerExpandVolume is called with volume having vmdk path")
}
}

func TestCompleteControllerFlow(t *testing.T) {
ct := getControllerTest(t)

Expand Down