From aac7a47469b32680472168669e046af34287e462 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Tue, 28 Nov 2023 10:11:51 +0000 Subject: [PATCH] build: fix incorrect solve opt platform from being set This regression was introduced in 616fb3e55cbc85647026f6e409af17e1011a85c4, with the node resolution refactor. The core issue here is just that we would unconditionally set the solve opt's platform to the default current platform, which was incorrect. We can prevent this easily by having a special case for the default case, like we had before, and then not setting the platforms field on this (which keeping the resolution behavior which was introduced). Signed-off-by: Justin Chadwell --- build/driver.go | 26 +++++++++++++++++--------- build/driver_test.go | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/build/driver.go b/build/driver.go index c2e01cbb..0096459e 100644 --- a/build/driver.go +++ b/build/driver.go @@ -164,28 +164,36 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog return nil, true, nil } - if len(ps) == 0 { - ps = []specs.Platform{platforms.DefaultSpec()} - } - perfect := true nodeIdxs := make([]int, 0) - for _, p := range ps { - idx := r.get(p, matcher, additional) + if len(ps) == 0 { + idx := r.get(platforms.DefaultSpec(), matcher, additional) if idx == -1 { idx = 0 perfect = false } nodeIdxs = append(nodeIdxs, idx) + } else { + for _, p := range ps { + idx := r.get(p, matcher, additional) + if idx == -1 { + idx = 0 + perfect = false + } + nodeIdxs = append(nodeIdxs, idx) + } } var nodes []*resolvedNode for i, idx := range nodeIdxs { - nodes = append(nodes, &resolvedNode{ + node := &resolvedNode{ resolver: r, driverIndex: idx, - platforms: []specs.Platform{ps[i]}, - }) + } + if len(ps) > 0 { + node.platforms = []specs.Platform{ps[i]} + } + nodes = append(nodes, node) } nodes = recombineNodes(nodes) if _, err := r.boot(ctx, nodeIdxs, pw); err != nil { diff --git a/build/driver_test.go b/build/driver_test.go index 068ec7ee..63c79728 100644 --- a/build/driver_test.go +++ b/build/driver_test.go @@ -22,6 +22,7 @@ func TestFindDriverSanity(t *testing.T) { require.Len(t, res, 1) require.Equal(t, 0, res[0].driverIndex) require.Equal(t, "aaa", res[0].Node().Builder) + require.Equal(t, []specs.Platform{platforms.DefaultSpec()}, res[0].platforms) } func TestFindDriverEmpty(t *testing.T) { @@ -227,6 +228,7 @@ func TestSelectNodeCurrentPlatform(t *testing.T) { require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, "bbb", res[0].Node().Builder) + require.Empty(t, res[0].platforms) } func TestSelectNodeAdditionalPlatforms(t *testing.T) {