From d2f0058846d26d161857b6c4e5bb64897e43b6ff Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Thu, 25 Feb 2021 15:50:21 +0200 Subject: [PATCH] Combine package installs into one exec (#94) * Combine package installs to avoid multiple package manager updates * Check error! --- phase/prepare_hosts.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/phase/prepare_hosts.go b/phase/prepare_hosts.go index 3e436f0d..fb9076c6 100644 --- a/phase/prepare_hosts.go +++ b/phase/prepare_hosts.go @@ -1,6 +1,8 @@ package phase import ( + "strings" + "github.com/k0sproject/k0sctl/config/cluster" log "github.com/sirupsen/logrus" ) @@ -28,16 +30,19 @@ func (p *PrepareHosts) prepareHost(h *cluster.Host) error { } } + var pkgs []string + if h.NeedCurl() { - log.Infof("%s: installing curl", h) - if err := h.Configurer.InstallPackage(h, "curl"); err != nil { - return err - } + pkgs = append(pkgs, "curl") } - // TODO: combine with above using a slice of packages as each InstallPackage call triggers an apt/zypper/etc update. if h.NeedIPTables() { - if err := h.Configurer.InstallPackage(h, "iptables"); err != nil { + pkgs = append(pkgs, "iptables") + } + + if len(pkgs) > 0 { + log.Infof("%s: installing packages (%s)", h, strings.Join(pkgs, ", ")) + if err := h.Configurer.InstallPackage(h, pkgs...); err != nil { return err } }