Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

var socketFileName = "reg.sock"
var kubeletRegistrationPath = "/var/lib/kubelet/plugins/csi-dummy/registration"

// TestSocketFileDoesNotExist - Test1: file does not exist. So clean up should be successful.
func TestSocketFileDoesNotExist(t *testing.T) {
Expand Down Expand Up @@ -183,9 +184,7 @@ func TestTouchFile(t *testing.T) {
}
defer os.RemoveAll(testDir)

// In real life, testDir would be the kubeletRegistration socket dirname
// e.g. /var/lib/kubelet/plugins/<driver>/
filePath := filepath.Join(testDir, "registration")
filePath := filepath.Join(testDir, kubeletRegistrationPath)
fileExists, err := DoesFileExist(filePath)
if err != nil {
t.Fatalf("Failed to execute file exist: %+v", err)
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/util_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package util
import (
"fmt"
"os"
"path/filepath"

"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -87,6 +88,11 @@ func TouchFile(filePath string) error {
return err
}
if !exists {
err := os.MkdirAll(filepath.Dir(filePath), 0755)
if err != nil {
return err
}

file, err := os.Create(filePath)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
)

func Umask(mask int) (int, error) {
Expand Down Expand Up @@ -85,6 +86,11 @@ func TouchFile(filePath string) error {
return err
}
if !exists {
err := os.MkdirAll(filepath.Dir(filePath), 0755)
if err != nil {
return err
}

file, err := os.Create(filePath)
if err != nil {
return err
Expand Down