diff --git a/install/installer/cmd/render.go b/install/installer/cmd/render.go index 4749d403743209..902e82ea7215c1 100644 --- a/install/installer/cmd/render.go +++ b/install/installer/cmd/render.go @@ -6,6 +6,7 @@ package cmd import ( "fmt" + "io/ioutil" "os" _ "embed" @@ -66,7 +67,18 @@ A config file is required which can be generated with the init command.`, } func loadConfig(cfgFN string) (rawCfg interface{}, cfgVersion string, cfg *configv1.Config, err error) { - rawCfg, cfgVersion, err = config.Load(cfgFN) + var overrideConfig string + // Update overrideConfig if cfgFN is not empty + if cfgFN != "" { + cfgBytes, err := ioutil.ReadFile(cfgFN) + if err != nil { + panic(fmt.Sprintf("couldn't read file %s, %s", cfgFN, err)) + + } + overrideConfig = string(cfgBytes) + } + + rawCfg, cfgVersion, err = config.Load(overrideConfig) if err != nil { err = fmt.Errorf("error loading config: %w", err) return diff --git a/install/installer/pkg/config/loader.go b/install/installer/pkg/config/loader.go index ebc75405dd251c..684eaf7b7da803 100644 --- a/install/installer/pkg/config/loader.go +++ b/install/installer/pkg/config/loader.go @@ -6,7 +6,6 @@ package config import ( "fmt" - "io/ioutil" "github.com/gitpod-io/gitpod/installer/pkg/cluster" "github.com/go-playground/validator/v10" @@ -73,32 +72,43 @@ func LoadConfigVersion(version string) (ConfigVersion, error) { return v, nil } -func Load(fn string) (cfg interface{}, version string, err error) { - fc, err := ioutil.ReadFile(fn) +// Load takes a config string and overrides that onto the default +// config for that version (passed in the config). If no config version +// is passed, It overrides it onto the default CurrentVersion of the binary +func Load(overrideConfig string) (cfg interface{}, version string, err error) { + var overrideVS struct { + APIVersion string `json:"apiVersion"` + } + err = yaml.Unmarshal([]byte(overrideConfig), &overrideVS) if err != nil { return } - var vs struct { - APIVersion string `json:"apiVersion"` + + apiVersion := overrideVS.APIVersion + // fall-back to default CurrentVersion if no apiVersion was passed + if version == "" { + apiVersion = CurrentVersion } - err = yaml.Unmarshal(fc, &vs) + + v, err := LoadConfigVersion(apiVersion) if err != nil { return } - v, err := LoadConfigVersion(vs.APIVersion) + // Load default configuration + cfg = v.Factory() + err = v.Defaults(cfg) if err != nil { return } - cfg = v.Factory() - version = vs.APIVersion - err = yaml.Unmarshal(fc, cfg) + // Override passed configuration onto the default + err = yaml.Unmarshal([]byte(overrideConfig), cfg) if err != nil { return } - return cfg, version, nil + return cfg, apiVersion, nil } func Marshal(version string, cfg interface{}) ([]byte, error) { diff --git a/install/installer/pkg/config/v1/config.go b/install/installer/pkg/config/v1/config.go index 9b784bc7c14ddc..43f5251a25ae76 100644 --- a/install/installer/pkg/config/v1/config.go +++ b/install/installer/pkg/config/v1/config.go @@ -36,7 +36,6 @@ func (v version) Defaults(in interface{}) error { } cfg.Kind = InstallationFull - cfg.Domain = "gitpod.example.com" cfg.Repository = "eu.gcr.io/gitpod-core-dev/build" cfg.Observability = Observability{ LogLevel: LogLevelInfo,