Skip to content
Closed
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
17 changes: 17 additions & 0 deletions cmd/csi-node-driver-registrar/node_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net"
"os"
"runtime"
"time"

"google.golang.org/grpc"

Expand All @@ -36,6 +37,15 @@ func nodeRegister(
// pluginswatcher infrastructure. Node labeling is done by kubelet's csi code.
registrar := newRegistrationServer(csiDriverName, *kubeletRegistrationPath, supportedVersions)
socketPath := fmt.Sprintf("/registration/%s-reg.sock", csiDriverName)

ticker := time.NewTicker(5 * time.Second)
for {
<-ticker.C
go periodicallyCheck(socketPath, registrar)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to spawn a new goroutine? Is there ever a case where reconciling the socket could take a long time?

}
}

func periodicallyCheck(socketPath string, registrar registerapi.RegistrationServer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function can be called something like "reconcileSocket", to be more descriptive of what it does.

fi, err := os.Stat(socketPath)
if err == nil && (fi.Mode()&os.ModeSocket) != 0 {
// Remove any socket, stale or not, but fall through for other files
Expand All @@ -44,6 +54,12 @@ func nodeRegister(
os.Exit(1)
}
}

if err == nil && (fi.Mode()&os.ModeSocket) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

if err == nil then we always exit? That doesn't seem right.

// If listening
os.Exit(0)
}

if err != nil && !os.IsNotExist(err) {
klog.Errorf("failed to stat the socket %s with error: %+v", socketPath, err)
os.Exit(1)
Expand All @@ -64,6 +80,7 @@ func nodeRegister(
if runtime.GOOS == "linux" {
umask(oldmask)
}

klog.Infof("Registration Server started at: %s\n", socketPath)
grpcServer := grpc.NewServer()
// Registers kubelet plugin watcher api.
Expand Down