Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installer: always override -c config on default values #8401

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion install/installer/cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"

_ "embed"
Expand Down Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions install/installer/pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package config

import (
"fmt"
"io/ioutil"

"github.com/gitpod-io/gitpod/installer/pkg/cluster"
"github.com/go-playground/validator/v10"
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion install/installer/pkg/config/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down