Skip to content

Commit 611800c

Browse files
Simon Emmsroboquat
Simon Emms
authored andcommitted
[installer]: refactor config loader to use yq to remove apiVersion
1 parent 5d40fd6 commit 611800c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

install/installer/pkg/config/loader.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ package config
66

77
import (
88
"fmt"
9-
"regexp"
109

1110
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
11+
"github.com/gitpod-io/gitpod/installer/pkg/yq"
1212
"github.com/go-playground/validator/v10"
1313

1414
"sigs.k8s.io/yaml"
@@ -107,17 +107,18 @@ func Load(overrideConfig string, strict bool) (cfg interface{}, version string,
107107
return
108108
}
109109

110-
// `apiVersion: vx` line is removed from config since the version dependant
111-
// Config structure doesn't have that field
112-
// The line-ending is either comma (minified YAML) or newline (unminified)
113-
apiVersionRegexp := regexp.MustCompile(`apiVersion: ` + apiVersion + `(,)?`)
114-
overrideConfig = apiVersionRegexp.ReplaceAllString(overrideConfig, "")
110+
// Remove the apiVersion from the config as this has already been parsed
111+
// Use yq to make processing reliable
112+
output, err := yq.Process(overrideConfig, "del(.apiVersion)")
113+
if err != nil {
114+
return
115+
}
115116

116117
// Override passed configuration onto the default
117118
if strict {
118-
err = yaml.UnmarshalStrict([]byte(overrideConfig), cfg)
119+
err = yaml.UnmarshalStrict([]byte(*output), cfg)
119120
} else {
120-
err = yaml.Unmarshal([]byte(overrideConfig), cfg)
121+
err = yaml.Unmarshal([]byte(*output), cfg)
121122
}
122123
if err != nil {
123124
return

0 commit comments

Comments
 (0)