From 7f10867473bf2f3224ef4827175d5cc0e39ac116 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Thu, 25 Feb 2021 10:26:29 +0200 Subject: [PATCH 1/2] Combine package installs to avoid multiple package manager updates --- phase/prepare_hosts.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/phase/prepare_hosts.go b/phase/prepare_hosts.go index 3e436f0d..a3fc0aff 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,18 +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 { - return err - } + pkgs = append(pkgs, "iptables") + } + + if len(pkgs) > 0 { + log.Infof("%s: installing packages (%s)", h, strings.Join(pkgs, ", ")) + h.Configurer.InstallPackage(h, pkgs...) } if h.IsController() && !h.Configurer.CommandExist(h, "kubectl") { From a0ae646938aa99d980a8504b2cfdcfa78bb9907b Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Thu, 25 Feb 2021 10:28:37 +0200 Subject: [PATCH 2/2] Check error! --- phase/prepare_hosts.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phase/prepare_hosts.go b/phase/prepare_hosts.go index a3fc0aff..fb9076c6 100644 --- a/phase/prepare_hosts.go +++ b/phase/prepare_hosts.go @@ -42,7 +42,9 @@ func (p *PrepareHosts) prepareHost(h *cluster.Host) error { if len(pkgs) > 0 { log.Infof("%s: installing packages (%s)", h, strings.Join(pkgs, ", ")) - h.Configurer.InstallPackage(h, pkgs...) + if err := h.Configurer.InstallPackage(h, pkgs...); err != nil { + return err + } } if h.IsController() && !h.Configurer.CommandExist(h, "kubectl") {