From e503b0942f87b5e3a9f43e8395dcd6d185b8d9ca Mon Sep 17 00:00:00 2001 From: Lukasz Rajewski Date: Mon, 11 Apr 2022 20:36:00 +0200 Subject: Fixed detection of the etcd connection status Issue-ID: MULTICLOUD-1468 Signed-off-by: Lukasz Rajewski Change-Id: If243e9a484afe5db7d9538a1875241fa425a2516 --- src/k8splugin/internal/db/etcd.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/k8splugin/internal/db/etcd.go') diff --git a/src/k8splugin/internal/db/etcd.go b/src/k8splugin/internal/db/etcd.go index 5ce8135a..a3a09352 100644 --- a/src/k8splugin/internal/db/etcd.go +++ b/src/k8splugin/internal/db/etcd.go @@ -35,6 +35,7 @@ type EtcdConfig struct { // EtcdStore Interface needed for mocking type EtcdStore interface { + HealthCheck() error Get(key string) ([]byte, error) GetKeys(key string) ([]string, error) GetValues(key string) ([][]byte, error) @@ -96,6 +97,20 @@ func newClient(store *clientv3.Client, c EtcdConfig) (EtcdClient, error) { }, nil } +// HealthCheck verifies if the database is up and running +func (e EtcdClient) HealthCheck() error { + + if e.cli == nil { + return pkgerrors.Errorf("Etcd Client not initialized") + } + _, err := e.cli.Get(context.Background(), "HealthCheckKey") + if err != nil { + return pkgerrors.Errorf("Error getting etcd entry: %s", err.Error()) + } + + return nil +} + // Put values in Etcd DB func (e EtcdClient) Put(key, value string) error { -- cgit 1.2.3-korg