Skip to content

Commit d0ca54c

Browse files
andyzhangxk8s-infra-cherrypick-robot
authored andcommitted
fix: only unmount kata volume if it's kata node
fix fix
1 parent 1a91024 commit d0ca54c

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
@@ -114,14 +114,13 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
114114
}
115115

116116
if d.enableKataCCMount && context[podNameField] != "" && context[podNamespaceField] != "" {
117-
enableKataCCMount := d.isKataNode
118117
confidentialContainerLabel := getValueInMap(context, confidentialContainerLabelField)
119-
if !enableKataCCMount && confidentialContainerLabel != "" {
118+
if !d.isKataNode && confidentialContainerLabel != "" {
120119
klog.V(2).Infof("NodePublishVolume: checking if node %s is a kata node with confidential container label %s", d.NodeID, confidentialContainerLabel)
121-
enableKataCCMount = isKataNode(ctx, d.NodeID, confidentialContainerLabel, d.kubeClient)
120+
d.isKataNode = isKataNode(ctx, d.NodeID, confidentialContainerLabel, d.kubeClient)
122121
}
123122

124-
if enableKataCCMount {
123+
if d.isKataNode {
125124
runtimeClass, err := getRuntimeClassForPodFunc(ctx, d.kubeClient, context[podNameField], context[podNamespaceField])
126125
if err != nil {
127126
return nil, status.Errorf(codes.Internal, "failed to get runtime class for pod %s/%s: %v", context[podNamespaceField], context[podNameField], err)
@@ -214,7 +213,7 @@ func (d *Driver) NodeUnpublishVolume(_ context.Context, req *csi.NodeUnpublishVo
214213
return nil, status.Errorf(codes.Internal, "failed to unmount target %s: %v", targetPath, err)
215214
}
216215

217-
if d.enableKataCCMount {
216+
if d.enableKataCCMount && d.isKataNode {
218217
klog.V(2).Infof("NodeUnpublishVolume: remove direct volume mount info %s from %s", volumeID, targetPath)
219218
// Remove deletes the direct volume path including all the files inside it.
220219
// if there is no kata-cc mountinfo present on this path, it will return nil.
@@ -472,9 +471,9 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
472471
}
473472
klog.V(2).Infof("volume(%s) mount %s on %s succeeded", volumeID, source, cifsMountPath)
474473
}
475-
enableKataCCMount := d.isKataNode && d.enableKataCCMount
474+
476475
// If runtime OS is not windows and protocol is not nfs, save mountInfo.json
477-
if enableKataCCMount {
476+
if d.enableKataCCMount && d.isKataNode {
478477
if runtime.GOOS != "windows" && protocol != nfs {
479478
// Check if mountInfo.json is already present at the targetPath
480479
isMountInfoPresent, err := d.directVolume.VolumeMountInfo(cifsMountPath)
@@ -585,7 +584,7 @@ func (d *Driver) NodeUnstageVolume(_ context.Context, req *csi.NodeUnstageVolume
585584
}
586585
}
587586

588-
if d.enableKataCCMount {
587+
if d.enableKataCCMount && d.isKataNode {
589588
klog.V(2).Infof("NodeUnstageVolume: remove direct volume mount info %s from %s", volumeID, stagingTargetPath)
590589
if err := d.directVolume.Remove(stagingTargetPath); err != nil {
591590
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)