From 702ccb84609a206aa85286725f10e24f8498eaca Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Thu, 12 Nov 2026 13:47:36 +0200 Subject: [PATCH] fix(executor): keep the file order across a config with no steps yip runs the configs in a directory in name order: every step of a config waits for the steps of the config before it. A config that has no steps for the stage being run reset that chain, so the next config waited for nothing and ran concurrently with every config before it. Kairos ships /system/oem/30_ulimit.yaml with no initramfs steps, so 31_hosts.yaml ran concurrently with 05_network.yaml during the initramfs stage. 05_network.yaml relinks /etc/resolv.conf only when this check passes: if: '[ -f /etc/hosts ]' while 31_hosts.yaml runs `rm -f /etc/hosts` and then recreates it as a symlink. On a Kairos VM the immucore log showed the two files' steps interleaved and the relink check passing on some boots and failing on others, so the same node could come up with a different /etc/resolv.conf from one boot to the next. A config with no steps for the stage now leaves the chain alone, so the next config that has steps waits for the last one that had any. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Dimitris Karakasilis --- pkg/executor/default.go | 15 ++++--- pkg/executor/default_test.go | 77 ++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/pkg/executor/default.go b/pkg/executor/default.go index b6d27a4b..abd2cd64 100644 --- a/pkg/executor/default.go +++ b/pkg/executor/default.go @@ -234,13 +234,16 @@ func (e *DefaultExecutor) dirOps(stage, dir string, fs vfs.FS, console plugins.C return nil } ops := e.genOpFromSchema(path, stage, *config, fs, console) + // A config with no steps for this stage leaves prev alone, so + // the chain carries over it to the next config that has some. + if len(ops) == 0 { + return nil + } // mark lexicographic order dependency from previous blocks - if len(prev) > 0 && len(ops) > 0 { - for _, p := range prev { - if len(p.after) == 0 { - for _, o := range ops { - o.deps = append(o.deps, p.name) - } + for _, p := range prev { + if len(p.after) == 0 { + for _, o := range ops { + o.deps = append(o.deps, p.name) } } } diff --git a/pkg/executor/default_test.go b/pkg/executor/default_test.go index 71f3cee9..b8418f64 100644 --- a/pkg/executor/default_test.go +++ b/pkg/executor/default_test.go @@ -929,3 +929,80 @@ stages: Expect(strings.Join(order, " ")).To(MatchRegexp(`01_first\.yaml.*03_last\.yaml`)) }) }) + +// A config with no steps for the stage being run must not break the +// lexicographic chain: the configs after it still wait for the ones before +// it. Kairos ships 30_ulimit.yaml with no initramfs steps, and without the +// chain 31_hosts.yaml ran concurrently with 05_network.yaml, whose step +// checks /etc/hosts while 31_hosts.yaml replaces it. +var _ = Describe("Executor over a directory with a config that has no steps for the stage", func() { + l := logrus.New() + l.SetOutput(io.Discard) + def := NewExecutor(WithLogger(l)) + testConsole := console.NewStandardConsole() + + var fs *vfst.TestFS + var cleanup func() + var temp string + + BeforeEach(func() { + var err error + fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{ + "/some/yip": &vfst.Dir{Perm: 0o755}, + }) + Expect(err).ShouldNot(HaveOccurred()) + + temp = fs.TempDir() + Expect(fs.WriteFile("/some/yip/01_first.yaml", []byte(` +stages: + test: + - name: first + commands: + - sleep 0.5 + - echo first >> `+temp+`/order +`), 0o644)).To(Succeed()) + Expect(fs.WriteFile("/some/yip/02_other_stage.yaml", []byte(` +stages: + other: + - name: unrelated + commands: + - "true" +`), 0o644)).To(Succeed()) + Expect(fs.WriteFile("/some/yip/03_last.yaml", []byte(` +stages: + test: + - name: last + commands: + - echo last >> `+temp+`/order +`), 0o644)).To(Succeed()) + }) + + AfterEach(func() { + cleanup() + }) + + It("puts the config after it in a later layer than the config before it", func() { + g, err := def.Graph("test", fs, testConsole, "/some/yip") + Expect(err).ShouldNot(HaveOccurred()) + + layerOf := map[string]int{} + for i, layer := range g { + for _, op := range layer { + layerOf[op.Name] = i + } + } + first, ok := layerOf["/some/yip/01_first.yaml.first"] + Expect(ok).To(BeTrue(), "layers: %v", layerOf) + last, ok := layerOf["/some/yip/03_last.yaml.last"] + Expect(ok).To(BeTrue(), "layers: %v", layerOf) + Expect(last).To(BeNumerically(">", first), "layers: %v", layerOf) + }) + + It("runs the config after it only once the config before it is done", func() { + Expect(def.Run("test", fs, testConsole, "/some/yip")).To(Succeed()) + + out, err := os.ReadFile(temp + "/order") + Expect(err).ShouldNot(HaveOccurred()) + Expect(string(out)).To(Equal("first\nlast\n")) + }) +})