Skip to content

Commit

Permalink
Merge pull request #247 from kubernetes-csi/revert-214-remove-mkdirall
Browse files Browse the repository at this point in the history
Revert "Remove mkdir call while creating the registration probe file"
  • Loading branch information
k8s-ci-robot authored Nov 21, 2022
2 parents ecbc79d + d8d56f7 commit a95d6c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
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

0 comments on commit a95d6c0

Please sign in to comment.