Skip to content

Commit

Permalink
Merge pull request #61 from Madhu-1/fix-21
Browse files Browse the repository at this point in the history
Remove registratation socket file on shutdown
  • Loading branch information
k8s-ci-robot authored Jul 31, 2020
2 parents bf988b8 + 3a02a6b commit a0c2e6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ the actual driver's name.
args:
- "--csi-address=/csi/csi.sock"
- "--kubelet-registration-path=/var/lib/kubelet/plugins/<drivername.example.com>/csi.sock"
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "rm -rf /registration/<plugin> /registration/<drivername.example.com>-reg.sock"]
volumeMounts:
- name: plugin-dir
mountPath: /csi
Expand Down
22 changes: 21 additions & 1 deletion cmd/csi-node-driver-registrar/node_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"fmt"
"net"
"os"
"os/signal"
"runtime"
"syscall"

"google.golang.org/grpc"

Expand All @@ -36,7 +38,7 @@ func nodeRegister(
// as gRPC server which replies to registration requests initiated by kubelet's
// pluginswatcher infrastructure. Node labeling is done by kubelet's csi code.
registrar := newRegistrationServer(csiDriverName, *kubeletRegistrationPath, supportedVersions)
socketPath := fmt.Sprintf("/registration/%s-reg.sock", csiDriverName)
socketPath := buildSocketPath(csiDriverName)
if err := util.CleanupSocketFile(socketPath); err != nil {
klog.Errorf("%+v", err)
os.Exit(1)
Expand All @@ -62,6 +64,7 @@ func nodeRegister(
// Registers kubelet plugin watcher api.
registerapi.RegisterRegistrationServer(grpcServer, registrar)

go removeRegSocket(csiDriverName)
// Starts service
if err := grpcServer.Serve(lis); err != nil {
klog.Errorf("Registration Server stopped serving: %v", err)
Expand All @@ -70,3 +73,20 @@ func nodeRegister(
// If gRPC server is gracefully shutdown, exit
os.Exit(0)
}

func buildSocketPath(csiDriverName string) string {
return fmt.Sprintf("/registration/%s-reg.sock", csiDriverName)
}

func removeRegSocket(csiDriverName string) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGTERM)
<-sigc
socketPath := buildSocketPath(csiDriverName)
err := os.Remove(socketPath)
if err != nil && !os.IsNotExist(err) {
klog.Errorf("failed to remove socket: %s with error: %+v", socketPath, err)
os.Exit(1)
}
os.Exit(0)
}

0 comments on commit a0c2e6b

Please sign in to comment.