From ef0cbf20f492221eaaedc764bf9f441dab97df3d Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 27 Jul 2022 12:06:47 +0100 Subject: [PATCH] buildx: warn on editing nodes Previously, editing nodes to contain a new set of driver options or config files was unsupported, and silently dropping them. In this patch, we update with these, as well as add a new warning message that any new options may not taken into account until the builder restarts (which may apply to the flags, platforms and endpoints as well). Signed-off-by: Justin Chadwell --- commands/create.go | 3 +++ store/nodegroup.go | 35 +++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/commands/create.go b/commands/create.go index a4e81d2e..074b309e 100644 --- a/commands/create.go +++ b/commands/create.go @@ -320,6 +320,9 @@ func createCmd(dockerCli command.Cli) *cobra.Command { } func csvToMap(in []string) (map[string]string, error) { + if len(in) == 0 { + return nil, nil + } m := make(map[string]string, len(in)) for _, s := range in { csvReader := csv.NewReader(strings.NewReader(s)) diff --git a/store/nodegroup.go b/store/nodegroup.go index b6288e09..0a31331c 100644 --- a/store/nodegroup.go +++ b/store/nodegroup.go @@ -8,6 +8,7 @@ import ( "github.com/docker/buildx/util/platformutil" specs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) type NodeGroup struct { @@ -59,17 +60,42 @@ func (ng *NodeGroup) Update(name, endpoint string, platforms []string, endpoints return err } + var files map[string][]byte + if configFile != "" { + files, err = confutil.LoadConfigFiles(configFile) + if err != nil { + return err + } + } + if i != -1 { n := ng.Nodes[i] + needsRestart := false if endpointsSet { n.Endpoint = endpoint + needsRestart = true } if len(platforms) > 0 { n.Platforms = pp } if flags != nil { n.Flags = flags + needsRestart = true + } + if do != nil { + n.DriverOpts = do + needsRestart = true + } + if configFile != "" { + for k, v := range files { + n.Files[k] = v + } + needsRestart = true + } + if needsRestart { + logrus.Warn("new settings may not be used until builder is restarted") } + ng.Nodes[i] = n if err := ng.validateDuplicates(endpoint, i); err != nil { return err @@ -92,14 +118,7 @@ func (ng *NodeGroup) Update(name, endpoint string, platforms []string, endpoints Platforms: pp, Flags: flags, DriverOpts: do, - } - - if configFile != "" { - files, err := confutil.LoadConfigFiles(configFile) - if err != nil { - return err - } - n.Files = files + Files: files, } ng.Nodes = append(ng.Nodes, n)