Skip to content

Commit 4e52f8c

Browse files
committed
add more unit test cases
1 parent 73e5818 commit 4e52f8c

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

pkg/csi_driver/node.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ func (s *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublish
138138
return nil, status.Errorf(codes.NotFound, "failed to get pod: %v", err)
139139
}
140140
gcsFuseSidecarImage := gcsFuseSidecarContainerImage(pod)
141-
enableSidecarBucketAccessCheckForSidecarVersion := s.driver.config.EnableSidecarBucketAccessCheck && gcsFuseSidecarImage != "" && isSidecarVersionSupportedForGivenFeature(gcsFuseSidecarImage, SidecarBucketAccessCheckMinVersion)
141+
if gcsFuseSidecarImage == "" {
142+
return nil, status.Errorf(codes.Internal, "failed to fetch gcs fuse sidecar container image from pod")
143+
}
144+
enableSidecarBucketAccessCheckForSidecarVersion := s.driver.config.EnableSidecarBucketAccessCheck && isSidecarVersionSupportedForGivenFeature(gcsFuseSidecarImage, SidecarBucketAccessCheckMinVersion)
142145
identityProvider := ""
143146
shouldPopulateIdentityProviderForHnwKSA := s.shouldPopulateIdentityProvider(pod, optInHostnetworkKSA, userSpecifiedIdentityProvider != "")
144147
if shouldPopulateIdentityProviderForHnwKSA {
@@ -152,7 +155,7 @@ func (s *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublish
152155
identityProvider = s.driver.config.TokenManager.GetIdentityProvider()
153156
}
154157

155-
enableCloudProfilerForVersion := enableCloudProfilerForSidecar && gcsFuseSidecarImage != "" && isSidecarVersionSupportedForGivenFeature(gcsFuseSidecarImage, SidecarCloudProfilerMinVersion)
158+
enableCloudProfilerForVersion := enableCloudProfilerForSidecar && isSidecarVersionSupportedForGivenFeature(gcsFuseSidecarImage, SidecarCloudProfilerMinVersion)
156159
identityPool := s.driver.config.TokenManager.GetIdentityPool()
157160
fuseMountOptions, err = addFuseMountOptions(identityProvider, identityPool, fuseMountOptions, vc, shouldPopulateIdentityProviderForHnwKSA, enableSidecarBucketAccessCheckForSidecarVersion, enableCloudProfilerForVersion)
158161
if err != nil {
@@ -202,7 +205,7 @@ func (s *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublish
202205
}
203206

204207
// Only pass mountOptions flags for defaulting if sidecar container is managed and satisfies min version requirement
205-
if gcsFuseSidecarImage != "" && isSidecarVersionSupportedForGivenFeature(gcsFuseSidecarImage, MachineTypeAutoConfigSidecarMinVersion) {
208+
if isSidecarVersionSupportedForGivenFeature(gcsFuseSidecarImage, MachineTypeAutoConfigSidecarMinVersion) {
206209
shouldDisableAutoConfig := s.driver.config.DisableAutoconfig
207210
machineType, ok := node.Labels[clientset.MachineTypeKey]
208211
if ok {
@@ -385,6 +388,7 @@ func gcsFuseSidecarContainerImage(pod *corev1.Pod) string {
385388
return ""
386389
}
387390

391+
// addFuseMountOptions modifies the input array of existing FUSE mount options by appending additional options for respective enabled features.
388392
func addFuseMountOptions(identityProvider string, identityPool string, fuseMountOptions []string, vc map[string]string, hostNetworkEnabled bool, enableSidecarBucketAccessCheckForSidecarVersion bool, enableCloudProfilerForVersion bool) ([]string, error) {
389393
if hostNetworkEnabled {
390394
// Identity Provider is populated separately for host network enabled workloads.

pkg/csi_driver/node_test.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func TestAddFuseMountOptions(t *testing.T) {
481481
expectErr bool
482482
}{
483483
{
484-
name: "validate fuse mount options for host network workloads",
484+
name: "identity provider is added in fuse mount options for host network workloads",
485485
enableSidecarBucketAccessCheckForVersion: false,
486486
hostNetworkEnabled: true,
487487
identityProvider: sampleIdentityProvider,
@@ -493,7 +493,7 @@ func TestAddFuseMountOptions(t *testing.T) {
493493
},
494494
},
495495
{
496-
name: "validate sidecar bucket access check is disabled when host network is enabled",
496+
name: "fuse mount options related to sidecar bucket access check are not set for host network",
497497
enableSidecarBucketAccessCheckForVersion: true,
498498
hostNetworkEnabled: true,
499499
identityProvider: sampleIdentityProvider,
@@ -505,7 +505,7 @@ func TestAddFuseMountOptions(t *testing.T) {
505505
},
506506
},
507507
{
508-
name: "enable sidecar bucket access check on non-host network and validate fuse mount options are correctly set",
508+
name: "validate respective fuse mount options for sidecar bucket access check are set when host network is disabled",
509509
volumeContextParams: vc,
510510
enableSidecarBucketAccessCheckForVersion: true,
511511
identityProvider: sampleIdentityProvider,
@@ -520,7 +520,7 @@ func TestAddFuseMountOptions(t *testing.T) {
520520
},
521521
},
522522
{
523-
name: "verify sidecar bucket access disabled does not set fuse mount options",
523+
name: "validate no fuse mount options are added when host network and sidecar bucket check is disabled",
524524
volumeContextParams: vc,
525525
enableSidecarBucketAccessCheckForVersion: false,
526526
identityProvider: sampleIdentityProvider,
@@ -529,15 +529,15 @@ func TestAddFuseMountOptions(t *testing.T) {
529529
expectedFuseMountOptions: []string{},
530530
},
531531
{
532-
name: "validate cloud profiler flag is correctly set",
532+
name: "validate cloud profiler fuse mount option is set when cloud profiler is enabled",
533533
enableCloudProfilerForVersion: true,
534534
inputFuseMountOptions: []string{},
535535
expectedFuseMountOptions: []string{
536536
util.EnableCloudProfilerForSidecarConst + "=true",
537537
},
538538
},
539539
{
540-
name: "validate sidecar bucket access check when identity provider is not set",
540+
name: "missing identity provider should fail when sidecar bucket access check is enabled",
541541
volumeContextParams: vc,
542542
enableSidecarBucketAccessCheckForVersion: true,
543543
identityProvider: "",
@@ -546,7 +546,7 @@ func TestAddFuseMountOptions(t *testing.T) {
546546
expectErr: true,
547547
},
548548
{
549-
name: "validate sidecar bucket access check when identity pool is not set",
549+
name: "missing identity pool should fail when sidecar bucket access check is enabled",
550550
volumeContextParams: vc,
551551
enableSidecarBucketAccessCheckForVersion: true,
552552
identityProvider: sampleIdentityProvider,
@@ -555,7 +555,7 @@ func TestAddFuseMountOptions(t *testing.T) {
555555
expectErr: true,
556556
},
557557
{
558-
name: "validate cloud profiler with host network",
558+
name: "verify fuse mount options are not overwritten when multiple features are enabled",
559559
hostNetworkEnabled: true,
560560
enableCloudProfilerForVersion: true,
561561
identityProvider: sampleIdentityProvider,
@@ -565,6 +565,18 @@ func TestAddFuseMountOptions(t *testing.T) {
565565
util.TokenServerIdentityProviderConst + "=" + sampleIdentityProvider,
566566
},
567567
},
568+
{
569+
name: "verify new mount options are appended to existing fuse mount options",
570+
hostNetworkEnabled: true,
571+
enableCloudProfilerForVersion: true,
572+
identityProvider: sampleIdentityProvider,
573+
inputFuseMountOptions: []string{util.EnableCloudProfilerForSidecarConst + "=true"},
574+
expectedFuseMountOptions: []string{
575+
util.EnableCloudProfilerForSidecarConst + "=true",
576+
util.OptInHnw + "=true",
577+
util.TokenServerIdentityProviderConst + "=" + sampleIdentityProvider,
578+
},
579+
},
568580
}
569581

570582
for _, tc := range cases {

0 commit comments

Comments
 (0)