aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/utils.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-18 16:38:20 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-19 15:48:48 -0700
commit42f8f006ab01692d7de9cecc06521eaf58743c0d (patch)
tree03bc5fe0dd662cec4c36e2b67da84cfd30602950 /src/k8splugin/internal/utils.go
parent5414c23063815207c68bfc7398561cec7409c963 (diff)
Move configuration into config files
Move k8splugin configuration into config files instead of using environment variables. Issue-ID: MULTICLOUD-579 Change-Id: I7b76d5a14d24f002a8db484097a31fb5e908b6f8 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/utils.go')
-rw-r--r--src/k8splugin/internal/utils.go36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/k8splugin/internal/utils.go b/src/k8splugin/internal/utils.go
index 3b08dd26..7785733d 100644
--- a/src/k8splugin/internal/utils.go
+++ b/src/k8splugin/internal/utils.go
@@ -15,13 +15,15 @@ package utils
import (
"io/ioutil"
- "k8splugin/internal/db"
"log"
"os"
"path/filepath"
"plugin"
"strings"
+ "k8splugin/internal/config"
+ "k8splugin/internal/db"
+
pkgerrors "github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
@@ -65,23 +67,10 @@ var DecodeYAML = func(path string, into runtime.Object) (runtime.Object, error)
return obj, nil
}
-// CheckEnvVariables checks for required Environment variables
-func CheckEnvVariables() error {
- envList := []string{"CSAR_DIR", "KUBE_CONFIG_DIR", "PLUGINS_DIR",
- "DATABASE_TYPE", "DATABASE_IP", "OVN_CENTRAL_ADDRESS"}
- for _, env := range envList {
- if _, ok := os.LookupEnv(env); !ok {
- return pkgerrors.New("environment variable " + env + " not set")
- }
- }
-
- return nil
-}
-
// CheckDatabaseConnection checks if the database is up and running and
// plugin can talk to it
func CheckDatabaseConnection() error {
- err := db.CreateDBClient(os.Getenv("DATABASE_TYPE"))
+ err := db.CreateDBClient(config.GetConfiguration().DatabaseType)
if err != nil {
return pkgerrors.Cause(err)
}
@@ -92,10 +81,10 @@ func CheckDatabaseConnection() error {
}
// TODO Convert these to configuration files instead of environment variables.
c := db.EtcdConfig{
- Endpoint: os.Getenv("ETCD_ENDPOINT_IP"),
- CertFile: os.Getenv("ETCD_CERT_FILE"),
- KeyFile: os.Getenv("ETCD_KEY_FILE"),
- CAFile: os.Getenv("ETCD_TRUSTED_CA_FILE"),
+ Endpoint: config.GetConfiguration().EtcdIP,
+ CertFile: config.GetConfiguration().EtcdCert,
+ KeyFile: config.GetConfiguration().EtcdKey,
+ CAFile: config.GetConfiguration().EtcdCAFile,
}
err = db.NewEtcdClient(nil, c)
if err != nil {
@@ -106,7 +95,7 @@ func CheckDatabaseConnection() error {
// LoadPlugins loads all the compiled .so plugins
func LoadPlugins() error {
- pluginsDir := os.Getenv("PLUGINS_DIR")
+ pluginsDir := config.GetConfiguration().PluginDir
err := filepath.Walk(pluginsDir,
func(path string, info os.FileInfo, err error) error {
if strings.Contains(path, ".so") {
@@ -127,12 +116,7 @@ func LoadPlugins() error {
// CheckInitialSettings is used to check initial settings required to start api
func CheckInitialSettings() error {
- err := CheckEnvVariables()
- if err != nil {
- return pkgerrors.Cause(err)
- }
-
- err = CheckDatabaseConnection()
+ err := CheckDatabaseConnection()
if err != nil {
return pkgerrors.Cause(err)
}