mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
Fix liveness connection opening endless sockets
Signed-off-by: Daniel-Pivonka <dpivonka@redhat.com>
This commit is contained in:
parent
22a7be55ea
commit
18e22e500e
@ -25,6 +25,7 @@ import (
|
|||||||
connlib "github.com/kubernetes-csi/csi-lib-utils/connection"
|
connlib "github.com/kubernetes-csi/csi-lib-utils/connection"
|
||||||
"github.com/kubernetes-csi/csi-lib-utils/rpc"
|
"github.com/kubernetes-csi/csi-lib-utils/rpc"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"google.golang.org/grpc"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,14 +37,7 @@ var (
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
func getLiveness(endpoint string, timeout time.Duration) {
|
func getLiveness(timeout time.Duration, csiConn *grpc.ClientConn) {
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -72,11 +66,18 @@ func recordLiveness(endpoint string, pollTime, timeout time.Duration) {
|
|||||||
klog.Fatalln(err)
|
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
|
// get liveness periodically
|
||||||
ticker := time.NewTicker(pollTime)
|
ticker := time.NewTicker(pollTime)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
getLiveness(endpoint, timeout)
|
getLiveness(timeout, csiConn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user