diff options
author | 2022-04-11 20:36:00 +0200 | |
---|---|---|
committer | 2022-04-11 20:36:23 +0200 | |
commit | e503b0942f87b5e3a9f43e8395dcd6d185b8d9ca (patch) | |
tree | 7a6f28a6718e153043ff6a428af83c886203e14f /src/k8splugin/internal | |
parent | 76b4c1981e361b52e94c1545e15a9d90ed311b1e (diff) |
Fixed detection of the etcd connection status
Issue-ID: MULTICLOUD-1468
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: If243e9a484afe5db7d9538a1875241fa425a2516
Diffstat (limited to 'src/k8splugin/internal')
-rw-r--r-- | src/k8splugin/internal/db/etcd.go | 15 | ||||
-rw-r--r-- | src/k8splugin/internal/db/etcd_testing.go | 4 | ||||
-rw-r--r-- | src/k8splugin/internal/utils/utils.go | 2 |
3 files changed, 21 insertions, 0 deletions
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 { diff --git a/src/k8splugin/internal/db/etcd_testing.go b/src/k8splugin/internal/db/etcd_testing.go index 2f62d365..4022d30e 100644 --- a/src/k8splugin/internal/db/etcd_testing.go +++ b/src/k8splugin/internal/db/etcd_testing.go @@ -24,6 +24,10 @@ type MockEtcdClient struct { Err error } +func (c *MockEtcdClient) HealthCheck() error { + return c.Err +} + func (c *MockEtcdClient) Put(key, value string) error { if c.Items == nil { c.Items = make(map[string]string) diff --git a/src/k8splugin/internal/utils/utils.go b/src/k8splugin/internal/utils/utils.go index 174f8e79..e8ce2f8e 100644 --- a/src/k8splugin/internal/utils/utils.go +++ b/src/k8splugin/internal/utils/utils.go @@ -76,6 +76,7 @@ func CheckDatabaseConnection() error { err = db.DBconn.HealthCheck() if err != nil { + log.Printf("MongoDB health problem: %s", err.Error()) return pkgerrors.Cause(err) } // TODO Convert these to configuration files instead of environment variables. @@ -88,6 +89,7 @@ func CheckDatabaseConnection() error { err = db.NewEtcdClient(nil, c) if err != nil { log.Printf("Etcd Client Initialization failed with error: %s", err.Error()) + return pkgerrors.Cause(err) } return nil } |