Skip to content

Commit

Permalink
default to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshghorse committed Jan 3, 2025
1 parent 12392c2 commit 7bb9ae5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 65 deletions.
1 change: 1 addition & 0 deletions pkg/cloud_provider/file/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (manager *fakeServiceManager) CreateInstance(ctx context.Context, obj *Serv
State: "READY",
BackupSource: obj.BackupSource,
NfsExportOptions: obj.NfsExportOptions,
Protocol: obj.Protocol,
}

manager.createdInstances[obj.Name] = instance
Expand Down
12 changes: 2 additions & 10 deletions pkg/csi_driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,7 @@ func (s *controllerServer) generateNewFileInstance(name string, capBytes int64,
}
case v3FileProtocol:
default:
if isBasicTier(tier) {
fileProtocol = v3FileProtocol
} else {
fileProtocol = v4_1FileProtocol
}
fileProtocol = v3FileProtocol
}

return &file.ServiceInstance{
Expand Down Expand Up @@ -740,11 +736,7 @@ func (s *controllerServer) fileInstanceToCSIVolume(instance *file.ServiceInstanc
resp.VolumeContext[attrSupportLockRelease] = "true"
}
default:
if isBasicTier(instance.Tier) {
resp.VolumeContext[attrFileProtocol] = v3FileProtocol
} else {
resp.VolumeContext[attrFileProtocol] = v4_1FileProtocol
}
resp.VolumeContext[attrFileProtocol] = v3FileProtocol
}

return resp
Expand Down
45 changes: 7 additions & 38 deletions pkg/csi_driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
},
},
},
Parameters: map[string]string{"tier": enterpriseTier},
Parameters: map[string]string{"tier": enterpriseTier, paramFileProtocol: v4_1FileProtocol},
VolumeCapabilities: volumeCapabilities,
},
resp: &csi.CreateVolumeResponse{
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
VolumeContext: map[string]string{
attrIP: testIP,
attrVolume: newInstanceVolume,
attrFileProtocol: v4_1FileProtocol,
attrFileProtocol: v3FileProtocol,
},
ContentSource: &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Expand Down Expand Up @@ -512,37 +512,6 @@ func TestCreateVolume(t *testing.T) {
},
features: features,
},
{
name: "create volume without providing protocol for non-basic tiers",
req: &csi.CreateVolumeRequest{
Name: testCSIVolume,
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
Parameters: map[string]string{
"tier": zonalTier,
},
},
resp: &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: 1 * util.Tb,
VolumeId: testVolumeID,
VolumeContext: map[string]string{
attrIP: testIP,
attrVolume: newInstanceVolume,
attrFileProtocol: v4_1FileProtocol,
},
},
},
features: features,
},
// Failure Scenarios
{
name: "name empty",
Expand Down Expand Up @@ -1218,7 +1187,7 @@ func TestGenerateNewFileInstance(t *testing.T) {
Name: newInstanceVolume,
SizeBytes: testBytes,
},
Protocol: v4_1FileProtocol,
Protocol: v3FileProtocol,
},
},
{
Expand Down Expand Up @@ -1263,7 +1232,7 @@ func TestGenerateNewFileInstance(t *testing.T) {
Name: newInstanceVolume,
SizeBytes: testBytes,
},
Protocol: v4_1FileProtocol,
Protocol: v3FileProtocol,
},
},
{
Expand Down Expand Up @@ -1296,7 +1265,7 @@ func TestGenerateNewFileInstance(t *testing.T) {
Name: newInstanceVolume,
SizeBytes: testBytes,
},
Protocol: v4_1FileProtocol,
Protocol: v3FileProtocol,
},
},
{
Expand Down Expand Up @@ -1337,7 +1306,7 @@ func TestGenerateNewFileInstance(t *testing.T) {
Name: newInstanceVolume,
SizeBytes: testBytes,
},
Protocol: v4_1FileProtocol,
Protocol: v3FileProtocol,
},
},
{
Expand All @@ -1362,7 +1331,7 @@ func TestGenerateNewFileInstance(t *testing.T) {
SizeBytes: testBytes,
},
KmsKeyName: "foo-key",
Protocol: v4_1FileProtocol,
Protocol: v3FileProtocol,
},
},
{
Expand Down
12 changes: 6 additions & 6 deletions pkg/csi_driver/multishare_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (m *MultishareController) getShareAndGenerateCSICreateVolumeResponse(ctx co
if share.State != "READY" {
return nil, status.Errorf(codes.Aborted, "share %s not ready, state %s", share.Name, share.State)
}
return m.generateCSICreateVolumeResponse(instancePrefix, share, maxShareSizeSizeBytes)
return m.generateCSICreateVolumeResponse(instancePrefix, s, maxShareSizeSizeBytes)
}

func (m *MultishareController) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
Expand Down Expand Up @@ -630,7 +630,7 @@ func (m *MultishareController) generateNewMultishareInstance(instanceName string
}

if fileProtocol == "" {
fileProtocol = v4_1FileProtocol
fileProtocol = v3FileProtocol
}

f := &file.MultishareInstance{
Expand Down Expand Up @@ -853,11 +853,11 @@ func (m *MultishareController) generateCSICreateVolumeResponse(instancePrefix st
if m.featureMaxSharePerInstance {
resp.Volume.VolumeContext[attrMaxShareSize] = strconv.Itoa(int(maxShareSizeBytes))
}
switch s.Parent.Protocol {
case v3FileProtocol:
resp.Volume.VolumeContext[attrFileProtocol] = v3FileProtocol
default:

if s.Parent.Protocol == v4_1FileProtocol {
resp.Volume.VolumeContext[attrFileProtocol] = v4_1FileProtocol
} else {
resp.Volume.VolumeContext[attrFileProtocol] = v3FileProtocol
}
klog.Infof("CreateVolume resp: %+v", resp)
return resp, nil
Expand Down
21 changes: 15 additions & 6 deletions pkg/csi_driver/multishare_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ func TestGenerateNewMultishareInstance(t *testing.T) {
TagKeyClusterName: testClusterName,
util.ParamMultishareInstanceScLabelKey: testInstanceScPrefix,
},
Protocol: v4_1FileProtocol,
Protocol: v3FileProtocol,
},
},
}
Expand Down Expand Up @@ -828,7 +828,7 @@ func TestGenerateCSICreateVolumeResponse(t *testing.T) {
VolumeContext: map[string]string{
attrIP: "1.1.1.1",
attrMaxShareSize: strconv.Itoa(100 * util.Gb),
attrFileProtocol: v4_1FileProtocol,
attrFileProtocol: v3FileProtocol,
},
},
},
Expand Down Expand Up @@ -1216,6 +1216,7 @@ func TestMultishareCreateVolume(t *testing.T) {
Parameters: map[string]string{
ParamMultishareInstanceScLabel: testInstanceScPrefix,
paramTier: "enterprise",
paramFileProtocol: v4_1FileProtocol,
},
VolumeCapabilities: []*csi.VolumeCapability{
{
Expand Down Expand Up @@ -1277,7 +1278,7 @@ func TestMultishareCreateVolume(t *testing.T) {
Name: defaultNetwork,
ConnectMode: directPeering,
},
State: "READY",
State: "CREATING",
Protocol: v4_1FileProtocol,
},
},
Expand All @@ -1296,6 +1297,7 @@ func TestMultishareCreateVolume(t *testing.T) {
Parameters: map[string]string{
ParamMultishareInstanceScLabel: testInstanceScPrefix,
paramTier: "enterprise",
paramFileProtocol: v4_1FileProtocol,
},
VolumeCapabilities: []*csi.VolumeCapability{
{
Expand Down Expand Up @@ -1417,6 +1419,7 @@ func TestMultishareCreateVolume(t *testing.T) {
},
Parameters: map[string]string{
ParamMultishareInstanceScLabel: testInstanceScPrefix,
paramFileProtocol: v4_1FileProtocol,
},
VolumeCapabilities: []*csi.VolumeCapability{
{
Expand Down Expand Up @@ -1625,6 +1628,7 @@ func TestMultishareCreateVolumeFromBackup(t *testing.T) {
"squashMode": "NO_ROOT_SQUASH"
}
]`,
paramFileProtocol: v4_1FileProtocol,
},
VolumeCapabilities: volumeCapabilities,
VolumeContentSource: &csi.VolumeContentSource{
Expand Down Expand Up @@ -1655,7 +1659,8 @@ func TestMultishareCreateVolumeFromBackup(t *testing.T) {
CapacityBytes: 100 * util.Gb,
VolumeId: fmt.Sprintf(multishareVolIdFmt, testInstanceScPrefix, testProject, testRegion, testInstanceName1, testShareName),
VolumeContext: map[string]string{
attrIP: testIP,
attrIP: testIP,
attrFileProtocol: v4_1FileProtocol,
},
ContentSource: &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Expand Down Expand Up @@ -1694,7 +1699,8 @@ func TestMultishareCreateVolumeFromBackup(t *testing.T) {
CapacityBytes: 100 * util.Gb,
VolumeId: fmt.Sprintf(multishareVolIdFmt, testInstanceScPrefix, testProject, testRegion, testInstanceName1, testShareName),
VolumeContext: map[string]string{
attrIP: testIP,
attrIP: testIP,
attrFileProtocol: v3FileProtocol,
},
ContentSource: &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Expand Down Expand Up @@ -1746,7 +1752,7 @@ func TestMultishareCreateVolumeFromBackup(t *testing.T) {
Name: defaultNetwork,
ConnectMode: directPeering,
},
State: "READY",
State: "CREATING",
Protocol: v4_1FileProtocol,
},
},
Expand All @@ -1765,6 +1771,7 @@ func TestMultishareCreateVolumeFromBackup(t *testing.T) {
Parameters: map[string]string{
ParamMultishareInstanceScLabel: testInstanceScPrefix,
paramTier: "enterprise",
paramFileProtocol: v4_1FileProtocol,
},
VolumeCapabilities: volumeCapabilities,
VolumeContentSource: &csi.VolumeContentSource{
Expand Down Expand Up @@ -1826,6 +1833,7 @@ func TestMultishareCreateVolumeFromBackup(t *testing.T) {
Parameters: map[string]string{
ParamMultishareInstanceScLabel: testInstanceScPrefix,
paramTier: "enterprise",
paramFileProtocol: v4_1FileProtocol,
},
VolumeCapabilities: volumeCapabilities,
VolumeContentSource: &csi.VolumeContentSource{
Expand Down Expand Up @@ -1908,6 +1916,7 @@ func TestMultishareCreateVolumeFromBackup(t *testing.T) {
},
Parameters: map[string]string{
ParamMultishareInstanceScLabel: testInstanceScPrefix,
paramFileProtocol: v4_1FileProtocol,
},
VolumeCapabilities: volumeCapabilities,
VolumeContentSource: &csi.VolumeContentSource{
Expand Down
10 changes: 5 additions & 5 deletions pkg/csi_driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ func (s *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolu
}
}

var isNFSv3Instance bool
if attr[attrFileProtocol] == v3FileProtocol {
isNFSv3Instance = true
fileProtocol, ok := attr[attrFileProtocol]
if !ok {
fileProtocol = v3FileProtocol
}

if mounted {
if isNFSv3Instance && s.features.FeatureLockRelease.Enabled {
if fileProtocol == v3FileProtocol && s.features.FeatureLockRelease.Enabled {
klog.V(4).Infof("NodeStageVolume mounted volume %v to staging target path %s, mount already exists on node %s. Proceed to lock info configmap updates", volumeID, stagingTargetPath, s.driver.config.NodeName)
if err := s.nodeStageVolumeUpdateLockInfo(ctx, req); err != nil {
return nil, status.Errorf(codes.Internal, "failed to store lock info after NodeStageVolume succeeded on volume %v to path %s: %v", volumeID, stagingTargetPath, err.Error())
Expand Down Expand Up @@ -340,7 +340,7 @@ func (s *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolu
return nil, status.Errorf(codes.Internal, "mount %q failed on node %s: %v", stagingTargetPath, s.driver.config.NodeName, err.Error())
}

if isNFSv3Instance && s.features.FeatureLockRelease.Enabled {
if fileProtocol == v3FileProtocol && s.features.FeatureLockRelease.Enabled {
klog.V(4).Infof("NodeStageVolume mounted volume %v to staging target path %s on node %s, proceed to lock info configmap updates.", volumeID, stagingTargetPath, s.driver.config.NodeName)
if err := s.nodeStageVolumeUpdateLockInfo(ctx, req); err != nil {
return nil, status.Errorf(codes.Internal, "failed to store lock info after NodeStageVolume succeeded on volume %v to path %s: %v", volumeID, stagingTargetPath, err.Error())
Expand Down

0 comments on commit 7bb9ae5

Please sign in to comment.