Skip to content
Snippets Groups Projects
Commit e6d2d49e5342 authored by Steeven Herlant's avatar Steeven Herlant
Browse files

feat: disabled keyword in charts can now be a variable

parent 2512605560fe
No related branches found
Tags 3.2.2
No related merge requests found
Pipeline #68336 failed
......@@ -267,11 +267,12 @@
type CmdCharts map[string]CmdChart
type CmdChart struct {
Type string
Path string
Name string
Namespace string
Disabled bool
Type string
Path string
Name string
Namespace string
// Must be castable into bool (0,1,true,false)
Disabled string
ValuesFileNames []string
}
......
......@@ -31,7 +31,8 @@
Namespace string
// Disabled: disable this chart
// This can be useful when inheriting the chart
Disabled bool
// must be castable to bool (0,1,true,false)
Disabled string
}
// Arg define command line arguments
......
......@@ -52,6 +52,15 @@
outputDir = r.config.Output
}
for name := range r.config.Spec.Charts {
w := bytes.NewBuffer([]byte{})
if err := hydrateString(r.config.Spec.Charts[name].Disabled, w, variables); err != nil {
return err
}
chart := r.config.Spec.Charts[name]
chart.Disabled = w.String()
r.config.Spec.Charts[name] = chart
}
preBuildDir := filepath.Join(tmpDir, "pre-build")
if err := r.DoBuild(tmpDir, preBuildDir); err != nil {
return fmt.Errorf("failed to do pre-build: %w", err)
......@@ -216,8 +225,21 @@
return input, nil
}
func toBool(s string) (bool, error) {
sLower := strings.ToLower(s)
finalString := strings.TrimSuffix(sLower, "\n")
switch finalString {
case "0", "false", "":
return false, nil
case "1", "true":
return true, nil
default:
return false, errors.New("cannot parse " + s + " as bool")
}
}
func (r *Runner) prepareCmds() (map[string]*cmd.Cmd, error) {
// create helm commands
// create ytt chart commands
cmds := make(map[string]*cmd.Cmd)
for name, chart := range r.config.Spec.Charts {
......@@ -219,9 +241,13 @@
func (r *Runner) prepareCmds() (map[string]*cmd.Cmd, error) {
// create helm commands
// create ytt chart commands
cmds := make(map[string]*cmd.Cmd)
for name, chart := range r.config.Spec.Charts {
if chart.Disabled {
disabled, err := toBool(chart.Disabled)
if err != nil {
return nil, err
}
if disabled {
continue
}
args, err := chart.BuildArgs(name, r.config.Namespace)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment