From 721f9e44cf6ddd9e1eb87d1f52cb2f24a3667a11 Mon Sep 17 00:00:00 2001 From: wangyueliang Date: Wed, 8 May 2024 16:58:40 +0800 Subject: [PATCH] kola: Add support for injecting Butane and Ignition [upstream] 7ce59d238367377d58c0f81337a26437cf26fa66 221a0d87a9ed10dcaa9bfec4e0963c23a0f080f2 --- mantle/cmd/kola/options.go | 2 ++ mantle/platform/cluster.go | 55 ++++++++++++++++++++++++++++++++++++- mantle/platform/platform.go | 3 ++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/mantle/cmd/kola/options.go b/mantle/cmd/kola/options.go index e5405062..9ba44f40 100644 --- a/mantle/cmd/kola/options.go +++ b/mantle/cmd/kola/options.go @@ -69,6 +69,8 @@ func init() { sv(&kola.Options.CosaWorkdir, "workdir", "", "coreos-assembler working directory") sv(&kola.Options.CosaBuildId, "build", "", "coreos-assembler build ID") sv(&kola.Options.CosaBuildArch, "arch", coreosarch.CurrentRpmArch(), "The target architecture of the build") + sv(&kola.Options.AppendButane, "append-butane", "", "Path to Butane config which is merged with test code") + sv(&kola.Options.AppendIgnition, "append-ignition", "", "Path to Ignition config which is merged with test code") // we make this a percentage to avoid having to deal with floats root.PersistentFlags().UintVar(&kola.Options.ExtendTimeoutPercent, "extend-timeout-percentage", 0, "Extend all test timeouts by N percent") // rhcos-specific options diff --git a/mantle/platform/cluster.go b/mantle/platform/cluster.go index 7a9b283e..51e804a7 100644 --- a/mantle/platform/cluster.go +++ b/mantle/platform/cluster.go @@ -196,10 +196,63 @@ func (bc *BaseCluster) RenderUserData(userdata *platformConf.UserData, ignitionV userdata = userdata.Subst(k, v) } - conf, err := userdata.Render(bc.rconf.WarningsAction) + confSources := []*platformConf.Conf{} + + // Gather the base config + baseConf, err := userdata.Render(bc.rconf.WarningsAction) if err != nil { return nil, err } + // We may have multiple config sources; create an array now + // with that sole element. + confSources = append(confSources, baseConf) + + // If butane is specified, parse and add that. + if bc.bf.baseopts.AppendButane != "" { + buf, err := os.ReadFile(bc.bf.baseopts.AppendButane) + if err != nil { + return nil, err + } + subData := platformConf.Butane(string(buf)) + subConf, err := subData.Render(platformConf.ReportWarnings) + if err != nil { + return nil, err + } + confSources = append(confSources, subConf) + } + + // If Ignition is specified, parse and add that. + if bc.bf.baseopts.AppendIgnition != "" { + buf, err := os.ReadFile(bc.bf.baseopts.AppendIgnition) + if err != nil { + return nil, err + } + subData := platformConf.Ignition(string(buf)) + subConf, err := subData.Render(platformConf.ReportWarnings) + if err != nil { + return nil, err + } + confSources = append(confSources, subConf) + } + + // Look at the array of configs we have so far; if there is exactly one, + // then we don't need to do any merging. + var conf *platformConf.Conf + if len(confSources) == 1 { + conf = confSources[0] + } else { + // There are multiple configs; we now default to merging + // them all into a new Ignition config. + userdata, err := platformConf.MergeAllConfigs(confSources) + if err != nil { + return nil, err + } + + conf, err = userdata.Render(platformConf.ReportWarnings) + if err != nil { + return nil, err + } + } for _, dropin := range bc.bf.baseopts.SystemdDropins { conf.AddSystemdUnitDropin(dropin.Unit, dropin.Name, dropin.Contents) diff --git a/mantle/platform/platform.go b/mantle/platform/platform.go index 7e038d55..56e45f6d 100644 --- a/mantle/platform/platform.go +++ b/mantle/platform/platform.go @@ -184,6 +184,9 @@ type Options struct { UseWarnExitCode77 bool + AppendButane string + AppendIgnition string + // OSContainer is an image pull spec that can be given to the pivot service // in RHCOS machines to perform machine content upgrades. // When specified additional files & units will be automatically generated -- Gitee