Skip to content

Commit

Permalink
Skip GatherK0sFacts for hosts without pre-existing k0s (#606)
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke authored Jan 4, 2024
1 parent 9a85e68 commit 9e799de
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions phase/gather_k0s_facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/k0sproject/dig"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
"github.com/k0sproject/k0sctl/pkg/node"
"github.com/k0sproject/rig/exec"
Expand Down Expand Up @@ -41,16 +42,32 @@ func (k *k0sstatus) isSingle() bool {
type GatherK0sFacts struct {
GenericPhase
leader *cluster.Host
hosts cluster.Hosts
}

// Title for the phase
func (p *GatherK0sFacts) Title() string {
return "Gather k0s facts"
}

// Prepare finds hosts with k0s installed
func (p *GatherK0sFacts) Prepare(config *v1beta1.Cluster) error {
p.Config = config
p.hosts = config.Spec.Hosts.Filter(func(h *cluster.Host) bool {
return h.Configurer.CommandExist(h, "k0s")
})

return nil
}

// ShouldRun is true when there are hosts that need to be connected
func (p *GatherK0sFacts) ShouldRun() bool {
return len(p.hosts) > 0
}

// Run the phase
func (p *GatherK0sFacts) Run() error {
var controllers cluster.Hosts = p.Config.Spec.Hosts.Controllers()
var controllers cluster.Hosts = p.hosts.Controllers()
if err := p.parallelDo(controllers, p.investigateK0s); err != nil {
return err
}
Expand All @@ -61,7 +78,7 @@ func (p *GatherK0sFacts) Run() error {
p.SetProp("clusterID", id)
}

var workers cluster.Hosts = p.Config.Spec.Hosts.Workers()
var workers cluster.Hosts = p.hosts.Workers()
if err := p.parallelDo(workers, p.investigateK0s); err != nil {
return err
}
Expand Down

0 comments on commit 9e799de

Please sign in to comment.