Skip to content

Commit

Permalink
add check for volume context
Browse files Browse the repository at this point in the history
  • Loading branch information
arc9693 committed Sep 13, 2024
1 parent 4f59837 commit dc2d0ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/azurefile/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", perm)
}
}
if d.enableKataCCMount {
if d.enableKataCCMount && context[podNameField] != "" && context[podNamespaceField] != "" {
runtimeClass, err := getRuntimeClassForPodFunc(ctx, d.cloud.KubeClient, context[podNameField], context[podNamespaceField])
if err != nil {
klog.Errorf("failed to get runtime class for pod %s/%s: %v", context[podNamespaceField], context[podNameField], err)
Expand Down
12 changes: 7 additions & 5 deletions pkg/azurefile/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestNodePublishVolume(t *testing.T) {
TargetPath: targetTest,
StagingTargetPath: sourceTest,
Readonly: true,
VolumeContext: map[string]string{mountPermissionsField: "0755"},
VolumeContext: map[string]string{mountPermissionsField: "0755", podNameField: "testPod", podNamespaceField: "testNamespace"},
},
setup: func() {
d.enableKataCCMount = true
Expand Down Expand Up @@ -765,10 +765,12 @@ func TestNodeStageVolume(t *testing.T) {
d.resolver = mockResolver
d.directVolume = mockDirectVolume
d.enableKataCCMount = true
mockIPAddr := &net.IPAddr{IP: net.ParseIP("192.168.1.1")}
mockDirectVolume.EXPECT().VolumeMountInfo(sourceTest).Return(nil, nil)
mockResolver.EXPECT().ResolveIPAddr("ip", "test_servername").Return(mockIPAddr, nil)
mockDirectVolume.EXPECT().Add(sourceTest, gomock.Any()).Return(nil)
if runtime.GOOS != "windows" {
mockIPAddr := &net.IPAddr{IP: net.ParseIP("192.168.1.1")}
mockDirectVolume.EXPECT().VolumeMountInfo(sourceTest).Return(nil, nil)
mockResolver.EXPECT().ResolveIPAddr("ip", "test_servername").Return(mockIPAddr, nil)
mockDirectVolume.EXPECT().Add(sourceTest, gomock.Any()).Return(nil)
}
},
req: csi.NodeStageVolumeRequest{VolumeId: "vol_1##", StagingTargetPath: sourceTest,
VolumeCapability: &stdVolCap,
Expand Down

0 comments on commit dc2d0ae

Please sign in to comment.