Skip to content

Commit

Permalink
NodePublishVolume: require parents of target directory to exist
Browse files Browse the repository at this point in the history
According to the spec, "the CO SHALL ensure that the parent directory
of this path exists". The driver didn't rely on that and created those
parent directories itself if necessary, without removing them in
NodeUnpublishVolume.

This hides potential bugs in the CO or incorrect configuration of
csi-sanity (like creating directories in the wrong pod). Therefore it
is better to be strict and only create the actual target directory
itself.
  • Loading branch information
pohly committed May 27, 2021
1 parent e9313f3 commit 147b1d0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/hostpath/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (hp *hostPath) NodePublishVolume(ctx context.Context, req *csi.NodePublishV
notMnt, err := mount.IsNotMountPoint(mount.New(""), targetPath)
if err != nil {
if os.IsNotExist(err) {
if err = os.MkdirAll(targetPath, 0750); err != nil {
if err = os.Mkdir(targetPath, 0750); err != nil {
return nil, fmt.Errorf("create target path: %w", err)
}
notMnt = true
Expand Down

0 comments on commit 147b1d0

Please sign in to comment.