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) } /* 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 8485c34..ff4a151 100644 --- a/kubernetes/kubeclient.go +++ b/kubernetes/kubeclient.go @@ -31,9 +31,39 @@ 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 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 { @@ -458,7 +488,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 +496,7 @@ func InstallVamp(clientset *kubernetes.Clientset, ns string, config *VampConfig) }, { Name: "DBNAME", - Value: "vamp", + Value: config.DatabaseName, }, { Name: "API_SSL",