Skip to content

Commit 5f93f09

Browse files
Do not return error if it is remount request
1 parent 23e8f92 commit 5f93f09

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/secrets-store/nodeserver.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
7373
var podName, podNamespace, podUID string
7474
var targetPath string
7575
var mounted bool
76+
var isRemountRequest bool
7677
errorReason := internalerrors.FailedToMount
7778
rotationEnabled := ns.rotationConfig.enabled
7879

@@ -81,7 +82,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8182
// if there is an error at any stage during node publish volume and if the path
8283
// has already been mounted, unmount the target path so the next time kubelet calls
8384
// again for mount, entire node publish volume is retried
84-
if targetPath != "" && mounted {
85+
if targetPath != "" && mounted && !isRemountRequest {
8586
klog.InfoS("unmounting target path as node publish volume failed", "targetPath", targetPath, "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName})
8687
if unmountErr := ns.mounter.Unmount(targetPath); unmountErr != nil {
8788
klog.ErrorS(unmountErr, "failed to unmounting target path")
@@ -142,6 +143,9 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
142143
return nil, status.Errorf(codes.Internal, "failed to check if target path %s is mount point, err: %v", targetPath, err)
143144
}
144145
}
146+
// If it is mounted, it means this is not the first time mount request for this path.
147+
isRemountRequest = mounted
148+
145149
// If rotation is not enabled, don't remount the already mounted secrets.
146150
if !rotationEnabled && mounted {
147151
klog.InfoS("target path is already mounted", "targetPath", targetPath, "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName})
@@ -237,7 +241,11 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
237241
mounted = true
238242
var objectVersions map[string]string
239243
if objectVersions, errorReason, err = ns.mountSecretsStoreObjectContent(ctx, providerName, string(parametersStr), string(secretStr), targetPath, string(permissionStr), podName); err != nil {
240-
klog.ErrorS(err, "failed to mount secrets store object content", "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName})
244+
klog.ErrorS(err, "failed to mount secrets store object content", "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName}, "isRemountRequest", isRemountRequest)
245+
if isRemountRequest {
246+
// Mask error until fix available for https://github.com/kubernetes/kubernetes/issues/121271
247+
return &csi.NodePublishVolumeResponse{}, nil
248+
}
241249
return nil, fmt.Errorf("failed to mount secrets store objects for pod %s/%s, err: %w", podNamespace, podName, err)
242250
}
243251

@@ -246,6 +254,11 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
246254
// the pod with same name (pods created by statefulsets) is moved to a different node and the old SPCPS
247255
// has not yet been garbage collected.
248256
if err = createOrUpdateSecretProviderClassPodStatus(ctx, ns.client, ns.reader, podName, podNamespace, podUID, secretProviderClass, targetPath, ns.nodeID, true, objectVersions); err != nil {
257+
klog.ErrorS(err, "failed to create/update spcps", "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName}, "isRemountRequest", isRemountRequest)
258+
if isRemountRequest {
259+
// Mask error until fix available for https://github.com/kubernetes/kubernetes/issues/121271
260+
return &csi.NodePublishVolumeResponse{}, nil
261+
}
249262
return nil, fmt.Errorf("failed to create secret provider class pod status for pod %s/%s, err: %w", podNamespace, podName, err)
250263
}
251264

0 commit comments

Comments
 (0)