@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
+ "io/ioutil"
23
24
"net"
24
25
"strings"
25
26
"time"
@@ -35,6 +36,8 @@ const (
35
36
connectionLoggingInterval = 10 * time .Second
36
37
)
37
38
39
+ const terminationLogPath = "/dev/termination-log"
40
+
38
41
// Connect opens insecure gRPC connection to a CSI driver. Address must be either absolute path to UNIX domain socket
39
42
// file or have format '<protocol>://', following gRPC name resolution mechanism at
40
43
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
@@ -63,14 +66,27 @@ type Option func(o *options)
63
66
64
67
// OnConnectionLoss registers a callback that will be invoked when the
65
68
// connection got lost. If that callback returns true, the connection
66
- // is restablished . Otherwise the connection is left as it is and
69
+ // is reestablished . Otherwise the connection is left as it is and
67
70
// all future gRPC calls using it will fail with status.Unavailable.
68
71
func OnConnectionLoss (reconnect func () bool ) Option {
69
72
return func (o * options ) {
70
73
o .reconnect = reconnect
71
74
}
72
75
}
73
76
77
+ // ExitOnConnectionLoss returns callback for OnConnectionLoss() that writes
78
+ // an error to /dev/termination-log and exits.
79
+ func ExitOnConnectionLoss () func () bool {
80
+ return func () bool {
81
+ terminationMsg := "Lost connection to CSI driver, exiting"
82
+ if err := ioutil .WriteFile (terminationLogPath , []byte (terminationMsg ), 0644 ); err != nil {
83
+ klog .Errorf ("%s: %s" , terminationLogPath , err )
84
+ }
85
+ klog .Fatalf (terminationMsg )
86
+ return false
87
+ }
88
+ }
89
+
74
90
type options struct {
75
91
reconnect func () bool
76
92
}
0 commit comments