Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mkdir call while creating the registration probe file #214

Merged
merged 1 commit into from
Aug 13, 2022
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: 3 additions & 2 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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 @@ -184,7 +183,9 @@ func TestTouchFile(t *testing.T) {
}
defer os.RemoveAll(testDir)

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this assumption true for all csi drivers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path for the temp registration file is hidden from the users, the steps to create it are:

  • take the kubelet registration path: /var/lib/kubelet/plugins/<drivername.example.com>/csi.sock
  • on a successful registration, write the temp file to the same dirname: /var/lib/kubelet/plugins/<drivername.example.com>/registration

I think the directory /var/lib/kubelet/plugins/<drivername.example.com>/ is created in advance in the driver spec e.g. from the README

      volumes:
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins/<drivername.example.com>/
            type: DirectoryOrCreate

I checked a few drivers:

I think the assumption that this directory is created is true therefore node-driver-registrar should only create the file assuming that the dir already exists

if err != nil {
return err
}

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

func Umask(mask int) (int, error) {
Expand Down Expand Up @@ -86,11 +85,6 @@ 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