Skip to content

Commit

Permalink
Combine package installs into one exec (#94)
Browse files Browse the repository at this point in the history
* Combine package installs to avoid multiple package manager updates

* Check error!
  • Loading branch information
kke committed Feb 25, 2021
1 parent 7f6f264 commit d2f0058
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions phase/prepare_hosts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package phase

import (
"strings"

"github.com/k0sproject/k0sctl/config/cluster"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit d2f0058

Please sign in to comment.