Skip to content

Commit 6a80b63

Browse files
committed
fix: copilot comments
1 parent 953ae54 commit 6a80b63

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

pkg/azurefile/controllerserver.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
120120
}
121121
var sku, subsID, resourceGroup, location, account, fileShareName, diskName, fsType, secretName string
122122
var secretNamespace, pvcNamespace, protocol, customTags, storageEndpointSuffix, networkEndpointType, shareAccessTier, accountAccessTier, rootSquashType, tagValueDelimiter string
123-
var createAccount, useSeretCache, matchTags, selectRandomMatchingAccount, getLatestAccountKey, encryptInTransit bool
123+
var createAccount, useSeretCache, matchTags, selectRandomMatchingAccount, getLatestAccountKey, encryptInTransit, mountWithManagedIdentity, mountWithWIToken bool
124124
var vnetResourceGroup, vnetName, vnetLinkName, publicNetworkAccess, subnetName, shareNamePrefix, fsGroupChangePolicy, useDataPlaneAPI string
125-
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled, allowSharedKeyAccess, requiresSmbOAuth *bool
125+
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled, allowSharedKeyAccess *bool
126126
var provisionedBandwidthMibps, provisionedIops *int32
127127
// set allowBlobPublicAccess as false by default
128128
allowBlobPublicAccess := ptr.To(false)
@@ -131,6 +131,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
131131
// store account key to k8s secret by default
132132
storeAccountKey := true
133133

134+
var err error
134135
var accountQuota int32
135136
// Apply ProvisionerParameters (case-insensitive). We leave validation of
136137
// the values to the cloud provider.
@@ -298,26 +299,24 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
298299
}
299300
provisionedIops = to.Ptr(int32(value))
300301
case mountWithManagedIdentityField:
301-
value, err := strconv.ParseBool(v)
302+
mountWithManagedIdentity, err = strconv.ParseBool(v)
302303
if err != nil {
303304
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", mountWithManagedIdentityField, v)
304305
}
305-
if value {
306-
requiresSmbOAuth = &value
307-
}
308306
case mountWithWITokenField:
309-
value, err := strconv.ParseBool(v)
307+
mountWithWIToken, err = strconv.ParseBool(v)
310308
if err != nil {
311309
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", mountWithWITokenField, v)
312310
}
313-
if value {
314-
requiresSmbOAuth = &value
315-
}
316311
default:
317312
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", k)
318313
}
319314
}
320315

316+
if mountWithManagedIdentity && mountWithWIToken {
317+
return nil, status.Error(codes.InvalidArgument, "mountwithmanagedidentity and mountwithworkloadidentitytoken cannot be both true in storage class")
318+
}
319+
321320
if matchTags && account != "" {
322321
return nil, status.Errorf(codes.InvalidArgument, "matchTags must set as false when storageAccount(%s) is provided", account)
323322
}
@@ -535,6 +534,12 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
535534
}
536535
}
537536

537+
var requiresSmbOAuth *bool
538+
if mountWithManagedIdentity || mountWithWIToken {
539+
klog.V(2).Info("enabling smb oauth for managed identity or work identity token based mount")
540+
requiresSmbOAuth = to.Ptr(true)
541+
}
542+
538543
accountOptions := &storage.AccountOptions{
539544
Name: account,
540545
Type: sku,

pkg/azurefile/controllerserver_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,24 @@ var _ = ginkgo.Describe("TestCreateVolume", func() {
10951095
})
10961096
})
10971097

1098+
ginkgo.When("mountWithManagedIdentity and mountWithWIToken cannot be both true", func() {
1099+
ginkgo.It("should fail", func(ctx context.Context) {
1100+
req := &csi.CreateVolumeRequest{
1101+
Name: "random-vol-name-valid-request",
1102+
VolumeCapabilities: stdVolCap,
1103+
CapacityRange: lessThanPremCapRange,
1104+
Parameters: map[string]string{
1105+
mountWithManagedIdentityField: "true",
1106+
mountWithWITokenField: "true",
1107+
},
1108+
}
1109+
1110+
expectedErr := status.Errorf(codes.InvalidArgument, "%s and %s cannot be both true in storage class", mountWithManagedIdentityField, mountWithWITokenField)
1111+
_, err := d.CreateVolume(ctx, req)
1112+
gomega.Expect(err).To(gomega.Equal(expectedErr))
1113+
})
1114+
})
1115+
10981116
ginkgo.When("invalid parameter", func() {
10991117
ginkgo.It("should fail", func(ctx context.Context) {
11001118
name := "baz"

pkg/azurefile/nodeserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
359359
return nil, status.Errorf(codes.InvalidArgument, "fsGroupChangePolicy(%s) is not supported, supported fsGroupChangePolicy list: %v", fsGroupChangePolicy, supportedFSGroupChangePolicyList)
360360
}
361361

362+
if mountWithManagedIdentity && mountWithWIToken {
363+
return nil, status.Error(codes.InvalidArgument, "mountWithManagedIdentity and mountWithWIToken cannot be both true")
364+
}
365+
362366
lockKey := fmt.Sprintf("%s-%s", volumeID, targetPath)
363367
if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired {
364368
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)

pkg/azurefile/nodeserver_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,22 @@ func TestNodeStageVolume(t *testing.T) {
761761
DefaultError: status.Error(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", "07ab")),
762762
},
763763
},
764+
{
765+
desc: "[Error] mountWithManagedIdentity and mountWithWIToken cannot be both true",
766+
req: &csi.NodeStageVolumeRequest{VolumeId: "vol_1##", StagingTargetPath: sourceTest,
767+
VolumeCapability: &stdVolCap,
768+
VolumeContext: map[string]string{
769+
shareNameField: "test_sharename",
770+
storageAccountField: "test_accountname",
771+
serviceAccountTokenField: "token",
772+
mountWithManagedIdentityField: "true",
773+
mountWithWITokenField: "true",
774+
},
775+
Secrets: secrets},
776+
expectedErr: testutil.TestError{
777+
DefaultError: status.Error(codes.InvalidArgument, "mountWithManagedIdentity and mountWithWIToken cannot be both true"),
778+
},
779+
},
764780
{
765781
desc: "[Success] Valid request with Kata CC Mount enabled",
766782
setup: func() {

0 commit comments

Comments
 (0)