Skip to content

Commit 63d893c

Browse files
Pothulapatiroboquat
authored andcommitted
installer: always override -c config on default values
Fixes #8267 Currently, Users run `init` command first, update it and pass full config to `render` to generate Kubernetes manifests. The passage of `-c` is a requirement here, and users can't skip it. This PR makes the passage of `config` to `render` optional, and flexible. This means - Users can skip `-c` entirely, in which case we use the default values on the default config version for that installer binary - Users can selectively override fields and *thus no need to pass full config* all the time. This means `-c` flag acts as a flag through which they can override the default fields. For the second case, When a user explicitely sets the `apiVersion` field in the passed config, we use the default values for that version. If no `apiVersion` is passed, we override the passed config onto the default values on the default config version for that installer binary. After this change, For users This means that they only store and use the config that has their changes only (on the default config), and not the entire config. Signed-off-by: Tarun Pothulapati <[email protected]>
1 parent e720c49 commit 63d893c

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

install/installer/cmd/render.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66

77
import (
88
"fmt"
9+
"io/ioutil"
910
"os"
1011

1112
_ "embed"
@@ -66,7 +67,18 @@ A config file is required which can be generated with the init command.`,
6667
}
6768

6869
func loadConfig(cfgFN string) (rawCfg interface{}, cfgVersion string, cfg *configv1.Config, err error) {
69-
rawCfg, cfgVersion, err = config.Load(cfgFN)
70+
var overrideConfig string
71+
// Update overrideConfig if cfgFN is not empty
72+
if cfgFN != "" {
73+
cfgBytes, err := ioutil.ReadFile(cfgFN)
74+
if err != nil {
75+
panic(fmt.Sprintf("couldn't read file %s, %s", cfgFN, err))
76+
77+
}
78+
overrideConfig = string(cfgBytes)
79+
}
80+
81+
rawCfg, cfgVersion, err = config.Load(overrideConfig)
7082
if err != nil {
7183
err = fmt.Errorf("error loading config: %w", err)
7284
return

install/installer/pkg/config/loader.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package config
66

77
import (
88
"fmt"
9-
"io/ioutil"
109

1110
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
1211
"github.com/go-playground/validator/v10"
@@ -73,32 +72,43 @@ func LoadConfigVersion(version string) (ConfigVersion, error) {
7372
return v, nil
7473
}
7574

76-
func Load(fn string) (cfg interface{}, version string, err error) {
77-
fc, err := ioutil.ReadFile(fn)
75+
// Load takes a config string and overrides that onto the default
76+
// config for that version (passed in the config). If no config version
77+
// is passed, It overrides it onto the default CurrentVersion of the binary
78+
func Load(overrideConfig string) (cfg interface{}, version string, err error) {
79+
var overrideVS struct {
80+
APIVersion string `json:"apiVersion"`
81+
}
82+
err = yaml.Unmarshal([]byte(overrideConfig), &overrideVS)
7883
if err != nil {
7984
return
8085
}
81-
var vs struct {
82-
APIVersion string `json:"apiVersion"`
86+
87+
apiVersion := overrideVS.APIVersion
88+
// fall-back to default CurrentVersion if no apiVersion was passed
89+
if version == "" {
90+
apiVersion = CurrentVersion
8391
}
84-
err = yaml.Unmarshal(fc, &vs)
92+
93+
v, err := LoadConfigVersion(apiVersion)
8594
if err != nil {
8695
return
8796
}
8897

89-
v, err := LoadConfigVersion(vs.APIVersion)
98+
// Load default configuration
99+
cfg = v.Factory()
100+
err = v.Defaults(cfg)
90101
if err != nil {
91102
return
92103
}
93104

94-
cfg = v.Factory()
95-
version = vs.APIVersion
96-
err = yaml.Unmarshal(fc, cfg)
105+
// Override passed configuration onto the default
106+
err = yaml.Unmarshal([]byte(overrideConfig), cfg)
97107
if err != nil {
98108
return
99109
}
100110

101-
return cfg, version, nil
111+
return cfg, apiVersion, nil
102112
}
103113

104114
func Marshal(version string, cfg interface{}) ([]byte, error) {

install/installer/pkg/config/v1/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func (v version) Defaults(in interface{}) error {
3636
}
3737

3838
cfg.Kind = InstallationFull
39-
cfg.Domain = "gitpod.example.com"
4039
cfg.Repository = "eu.gcr.io/gitpod-core-dev/build"
4140
cfg.Observability = Observability{
4241
LogLevel: LogLevelInfo,

0 commit comments

Comments
 (0)