From 394767ca7f034931f9c48d70adaae917d59f4800 Mon Sep 17 00:00:00 2001 From: berkgokden Date: Mon, 11 Feb 2019 23:57:35 +0100 Subject: [PATCH 1/3] Added mode and database name settings to installation configuration --- kubernetes/kubeclient.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kubernetes/kubeclient.go b/kubernetes/kubeclient.go index 8485c34..6878270 100644 --- a/kubernetes/kubeclient.go +++ b/kubernetes/kubeclient.go @@ -31,9 +31,11 @@ import ( type VampConfig struct { RootPassword string `yaml:"rootPassword,omitempty" json:"rootPassword,omitempty"` DatabaseUrl string `yaml:"databaseUrl,omitempty" json:"databaseUrl,omitempty"` + DatabaseName string `yaml:"databaseName,omitempty" json:"databaseName,omitempty"` RepoUsername string `yaml:"repoUsername,omitempty" json:"repoUsername,omitempty"` RepoPassword string `yaml:"repoPassword,omitempty" json:"repoPassword,omitempty"` VampVersion string `yaml:"vampVersion,omitempty" json:"vampVersion,omitempty"` + Mode string `yaml:"mode,omitempty" json:"mode,omitempty"` } func GetKubeConfigPath(configPath string) *string { @@ -458,7 +460,7 @@ func InstallVamp(clientset *kubernetes.Clientset, ns string, config *VampConfig) Env: []apiv1.EnvVar{ { Name: "MODE", - Value: "IN_CLUSTER", + Value: config.Mode, }, { Name: "DBURL", @@ -466,7 +468,7 @@ func InstallVamp(clientset *kubernetes.Clientset, ns string, config *VampConfig) }, { Name: "DBNAME", - Value: "vamp", + Value: config.DatabaseName, }, { Name: "API_SSL", From 40b684811f6f553691b9ff64ec6e6e413797118b Mon Sep 17 00:00:00 2001 From: berkgokden Date: Tue, 12 Feb 2019 11:28:07 +0100 Subject: [PATCH 2/3] Added Vamp Installation Config Validation --- cmd/install.go | 7 ++++++- kubernetes/kubeclient.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cmd/install.go b/cmd/install.go index 4ba75b6..d46646c 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -62,7 +62,12 @@ Leave databaseUrl empty to deploy an internal one if unmarshallError != nil { return unmarshallError } - url, cert, _, err := kubeclient.InstallVampService(&config) + validatedConfig, configError := kubeclient.VampConfigValidateAndSetupDefaults(&config) + if configError != nil { + return configError + } + fmt.Printf("Vamp Configuration validated.\n") + url, cert, _, err := kubeclient.InstallVampService(validatedConfig) if err != nil { return err } diff --git a/kubernetes/kubeclient.go b/kubernetes/kubeclient.go index 6878270..ff4a151 100644 --- a/kubernetes/kubeclient.go +++ b/kubernetes/kubeclient.go @@ -38,6 +38,34 @@ type VampConfig struct { Mode string `yaml:"mode,omitempty" json:"mode,omitempty"` } +func VampConfigValidateAndSetupDefaults(config *VampConfig) (*VampConfig, error) { + if config.RootPassword == "" { + // This is enforced + return config, errors.New("Root Password can not be empty.") + } + if config.RepoUsername == "" { + return config, errors.New("Repo Username can not be empty.") + } + if config.RepoPassword == "" { + return config, errors.New("Repo Password can not be empty.") + } + if config.DatabaseName == "" { + config.DatabaseName = "vamp" + fmt.Printf("Database Name set to default value: %v\n", config.DatabaseName) + } + if config.VampVersion == "" { + config.VampVersion = "0.7.0" + fmt.Printf("Vamp Version set to default value: %v\n", config.VampVersion) + } + if config.Mode != "IN_CLUSTER" && + config.Mode != "OUT_CLUSTER" && + config.Mode != "OUT_OF_CLUSTER" { + config.Mode = "IN_CLUSTER" + fmt.Printf("Vamp Mode set to default value: %v\n", config.Mode) + } + return config, nil +} + func GetKubeConfigPath(configPath string) *string { if configPath == "" { home := homeDir() From 5c146118d1877a953c197ba66e97614ab30255b2 Mon Sep 17 00:00:00 2001 From: berkgokden Date: Tue, 12 Feb 2019 13:35:23 +0100 Subject: [PATCH 3/3] Fix in error messages when not returned as json --- client/client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index d3304cf..ecd3b46 100644 --- a/client/client.go +++ b/client/client.go @@ -165,7 +165,11 @@ Return the error object with message to be returned It can be used after checking with IsError */ func getError(resp *resty.Response) error { - return errors.New(resp.Error().(*ErrorResponse).Message) + message := resp.Error().(*ErrorResponse).Message + if message == "" { + message = string(resp.Body()) + } + return errors.New(message) } /*