From 18e22e500e864eded6d635b6e70e25d93300d767 Mon Sep 17 00:00:00 2001 From: Daniel-Pivonka Date: Thu, 5 Sep 2019 14:25:50 -0400 Subject: [PATCH] Fix liveness connection opening endless sockets Signed-off-by: Daniel-Pivonka --- pkg/liveness/liveness.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/liveness/liveness.go b/pkg/liveness/liveness.go index 8c0275dd5..9bc2fad58 100644 --- a/pkg/liveness/liveness.go +++ b/pkg/liveness/liveness.go @@ -25,6 +25,7 @@ import ( connlib "github.com/kubernetes-csi/csi-lib-utils/connection" "github.com/kubernetes-csi/csi-lib-utils/rpc" "github.com/prometheus/client_golang/prometheus" + "google.golang.org/grpc" "k8s.io/klog" ) @@ -36,14 +37,7 @@ var ( }) ) -func getLiveness(endpoint string, timeout time.Duration) { - - csiConn, err := connlib.Connect(endpoint) - if err != nil { - // connlib should retry forever so a returned error should mean - // the grpc client is misconfigured rather than an error on the network - klog.Fatalf("failed to establish connection to CSI driver: %v", err) - } +func getLiveness(timeout time.Duration, csiConn *grpc.ClientConn) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -72,11 +66,18 @@ func recordLiveness(endpoint string, pollTime, timeout time.Duration) { klog.Fatalln(err) } + csiConn, err := connlib.Connect(endpoint) + if err != nil { + // connlib should retry forever so a returned error should mean + // the grpc client is misconfigured rather than an error on the network + klog.Fatalf("failed to establish connection to CSI driver: %v", err) + } + // get liveness periodically ticker := time.NewTicker(pollTime) defer ticker.Stop() for range ticker.C { - getLiveness(endpoint, timeout) + getLiveness(timeout, csiConn) } }