Skip to content

Commit 0284bde

Browse files
authored
Merge pull request #2691 from k8s-infra-cherrypick-robot/cherry-pick-2688-to-release-1.33
[release-1.33] fix: only unmount kata volume if it's kata node
2 parents 1a91024 + faf6787 commit 0284bde

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
347347
},
348348
setup: func() {
349349
if runtime.GOOS == "windows" {
350+
d.isKataNode = true
350351
mockDirectVolume.EXPECT().Remove(errorTarget).Return(nil)
351352
}
352353
},
@@ -355,6 +356,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
355356
desc: "[Success] Valid request",
356357
req: &csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
357358
setup: func() {
359+
d.isKataNode = true
358360
mockDirectVolume.EXPECT().Remove(targetFile).Return(nil)
359361
},
360362
expectedErr: testutil.TestError{},
@@ -898,6 +900,7 @@ func TestNodeUnstageVolume(t *testing.T) {
898900
},
899901
setup: func() {
900902
if runtime.GOOS == "windows" {
903+
d.isKataNode = true
901904
mockDirectVolume.EXPECT().Remove(errorTarget).Return(nil)
902905
}
903906
},
@@ -906,6 +909,7 @@ func TestNodeUnstageVolume(t *testing.T) {
906909
desc: "[Success] Valid request",
907910
req: &csi.NodeUnstageVolumeRequest{StagingTargetPath: targetFile, VolumeId: "vol_1"},
908911
setup: func() {
912+
d.isKataNode = true
909913
mockDirectVolume.EXPECT().Remove(targetFile).Return(nil)
910914
},
911915
expectedErr: testutil.TestError{},

0 commit comments

Comments
 (0)