From 891ca56f8c024ff7864f64600f6bab4518babc03 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Thu, 15 Aug 2024 12:18:35 +0300 Subject: [PATCH] Relax version checking when using a custom K0sBinaryPath (#745) * Relax version checking when using a custom K0sBinaryPath Signed-off-by: Kimmo Lehto Add a warning Signed-off-by: Kimmo Lehto * Flip condition Signed-off-by: Kimmo Lehto --------- Signed-off-by: Kimmo Lehto --- phase/validate_hosts.go | 10 ++++++++++ pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/phase/validate_hosts.go b/phase/validate_hosts.go index cf764391..9e24158e 100644 --- a/phase/validate_hosts.go +++ b/phase/validate_hosts.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster" + log "github.com/sirupsen/logrus" ) // ValidateHosts performs remote OS detection @@ -48,6 +49,7 @@ func (p *ValidateHosts) Run() error { return p.parallelDo( p.Config.Spec.Hosts, + p.warnK0sBinaryPath, p.validateUniqueHostname, p.validateUniqueMachineID, p.validateUniquePrivateAddress, @@ -55,6 +57,14 @@ func (p *ValidateHosts) Run() error { ) } +func (p *ValidateHosts) warnK0sBinaryPath(h *cluster.Host) error { + if h.Configurer.K0sBinaryPath() != "" { + log.Warnf("%s: k0s binary path is set to %q, version checking for the host is disabled. The k0s version for other hosts is %q.", h, h.Configurer.K0sBinaryPath(), p.Config.Spec.K0s.Version) + } + + return nil +} + func (p *ValidateHosts) validateUniqueHostname(h *cluster.Host) error { if p.hncount[h.Metadata.Hostname] > 1 { return fmt.Errorf("hostname is not unique: %s", h.Metadata.Hostname) diff --git a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go index 321321f4..7190a295 100644 --- a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go +++ b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go @@ -399,7 +399,8 @@ func (h *Host) UpdateK0sBinary(path string, version *version.Version) error { if err != nil { return fmt.Errorf("failed to get updated k0s binary version: %w", err) } - if !version.Equal(updatedVersion) { + // verify the installed version matches the expected version, unless a custom k0sbinarypath is used + if h.K0sBinaryPath == "" && !version.Equal(updatedVersion) { return fmt.Errorf("updated k0s binary version is %s not %s", updatedVersion, version) }