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

fix: graceful exit #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions cmd/s3driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"flag"
"log"
"os"
"os/signal"
"syscall"

"github.com/yandex-cloud/k8s-csi-s3/pkg/driver"
)
Expand All @@ -36,10 +38,19 @@ var (
func main() {
flag.Parse()

sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGQUIT)

driver, err := driver.New(*nodeID, *endpoint)
if err != nil {
log.Fatal(err)
}

go func() {
<-sig
driver.Stop()
}()

driver.Run()
os.Exit(0)
}
21 changes: 15 additions & 6 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ type driver struct {
driver *csicommon.CSIDriver
endpoint string

ids *identityServer
ns *nodeServer
cs *controllerServer
ids *identityServer
ns *nodeServer
cs *controllerServer
server csicommon.NonBlockingGRPCServer
}

var (
Expand Down Expand Up @@ -82,7 +83,15 @@ func (s3 *driver) Run() {
s3.ns = s3.newNodeServer(s3.driver)
s3.cs = s3.newControllerServer(s3.driver)

s := csicommon.NewNonBlockingGRPCServer()
s.Start(s3.endpoint, s3.ids, s3.cs, s3.ns)
s.Wait()
s3.server = csicommon.NewNonBlockingGRPCServer()
s3.server.Start(s3.endpoint, s3.ids, s3.cs, s3.ns)
s3.server.Wait()
}

func (s3 *driver) Stop() {
if s3.server == nil {
return
}

s3.server.Stop()
}