Skip to content

Commit 4ab3ad0

Browse files
andyzhangxk8s-infra-cherrypick-robot
authored andcommitted
fix: only unmount kata volume if it's kata node
fix fix
1 parent 7a7718f commit 4ab3ad0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/azurefile/nodeserver.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,13 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
101101
}
102102

103103
if d.enableKataCCMount && context[podNameField] != "" && context[podNamespaceField] != "" {
104-
enableKataCCMount := d.isKataNode
105104
confidentialContainerLabel := getValueInMap(context, confidentialContainerLabelField)
106-
if !enableKataCCMount && confidentialContainerLabel != "" {
105+
if !d.isKataNode && confidentialContainerLabel != "" {
107106
klog.V(2).Infof("NodePublishVolume: checking if node %s is a kata node with confidential container label %s", d.NodeID, confidentialContainerLabel)
108-
enableKataCCMount = isKataNode(ctx, d.NodeID, confidentialContainerLabel, d.kubeClient)
107+
d.isKataNode = isKataNode(ctx, d.NodeID, confidentialContainerLabel, d.kubeClient)
109108
}
110109

111-
if enableKataCCMount {
110+
if d.isKataNode {
112111
runtimeClass, err := getRuntimeClassForPodFunc(ctx, d.kubeClient, context[podNameField], context[podNamespaceField])
113112
if err != nil {
114113
return nil, status.Errorf(codes.Internal, "failed to get runtime class for pod %s/%s: %v", context[podNamespaceField], context[podNameField], err)
@@ -201,7 +200,7 @@ func (d *Driver) NodeUnpublishVolume(_ context.Context, req *csi.NodeUnpublishVo
201200
return nil, status.Errorf(codes.Internal, "failed to unmount target %s: %v", targetPath, err)
202201
}
203202

204-
if d.enableKataCCMount {
203+
if d.enableKataCCMount && d.isKataNode {
205204
klog.V(2).Infof("NodeUnpublishVolume: remove direct volume mount info %s from %s", volumeID, targetPath)
206205
// Remove deletes the direct volume path including all the files inside it.
207206
// if there is no kata-cc mountinfo present on this path, it will return nil.
@@ -432,9 +431,9 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
432431
}
433432
klog.V(2).Infof("volume(%s) mount %s on %s succeeded", volumeID, source, cifsMountPath)
434433
}
435-
enableKataCCMount := d.isKataNode && d.enableKataCCMount
434+
436435
// If runtime OS is not windows and protocol is not nfs, save mountInfo.json
437-
if enableKataCCMount {
436+
if d.enableKataCCMount && d.isKataNode {
438437
if runtime.GOOS != "windows" && protocol != nfs {
439438
// Check if mountInfo.json is already present at the targetPath
440439
isMountInfoPresent, err := d.directVolume.VolumeMountInfo(cifsMountPath)
@@ -545,7 +544,7 @@ func (d *Driver) NodeUnstageVolume(_ context.Context, req *csi.NodeUnstageVolume
545544
}
546545
}
547546

548-
if d.enableKataCCMount {
547+
if d.enableKataCCMount && d.isKataNode {
549548
klog.V(2).Infof("NodeUnstageVolume: remove direct volume mount info %s from %s", volumeID, stagingTargetPath)
550549
if err := d.directVolume.Remove(stagingTargetPath); err != nil {
551550
return nil, status.Errorf(codes.Internal, "failed to remove mount info %s: %v", stagingTargetPath, err)

pkg/azurefile/nodeserver_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
355355
desc: "[Success] Valid request",
356356
req: &csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
357357
setup: func() {
358+
d.isKataNode = true
358359
mockDirectVolume.EXPECT().Remove(targetFile).Return(nil)
359360
},
360361
expectedErr: testutil.TestError{},
@@ -906,6 +907,7 @@ func TestNodeUnstageVolume(t *testing.T) {
906907
desc: "[Success] Valid request",
907908
req: &csi.NodeUnstageVolumeRequest{StagingTargetPath: targetFile, VolumeId: "vol_1"},
908909
setup: func() {
910+
d.isKataNode = true
909911
mockDirectVolume.EXPECT().Remove(targetFile).Return(nil)
910912
},
911913
expectedErr: testutil.TestError{},

0 commit comments

Comments
 (0)