Skip to content

Commit

Permalink
Merge branch 'main' into global-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kke authored Feb 12, 2025
2 parents caa961a + 274b628 commit 3b0f3ef
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect
github.com/a8m/envsubst v1.4.2
github.com/adrg/xdg v0.5.3
github.com/bmatcuk/doublestar/v4 v4.8.0
github.com/bmatcuk/doublestar/v4 v4.8.1
github.com/creasty/defaults v1.8.0
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
Expand All @@ -28,7 +28,7 @@ require (
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0
golang.org/x/text v0.22.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPp
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/bmatcuk/doublestar/v4 v4.8.0 h1:DSXtrypQddoug1459viM9X9D3dp1Z7993fw36I2kNcQ=
github.com/bmatcuk/doublestar/v4 v4.8.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38=
github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bodgit/ntlmssp v0.0.0-20240506230425-31973bb52d9b h1:baFN6AnR0SeC194X2D292IUZcHDs4JjStpqtE70fjXE=
github.com/bodgit/ntlmssp v0.0.0-20240506230425-31973bb52d9b/go.mod h1:Ram6ngyPDmP+0t6+4T2rymv0w0BS9N8Ch5vvUJccw5o=
github.com/bodgit/windows v1.0.1 h1:tF7K6KOluPYygXa3Z2594zxlkbKPAOvqr97etrGNIz4=
Expand Down Expand Up @@ -248,8 +248,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
4 changes: 2 additions & 2 deletions phase/arm_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
)

var etcdSupportedArchArm64Since = version.MustConstraint(">= v1.22.1+k0s.0")
var etcdSupportedArchArm64Since = version.MustParse("v1.22.1+k0s.0")

// PrepareArm implements a phase which fixes arm quirks
type PrepareArm struct {
Expand Down Expand Up @@ -46,7 +46,7 @@ func (p *PrepareArm) Prepare(config *v1beta1.Cluster) error {

if strings.HasSuffix(arch, "64") {
// 64-bit arm is supported on etcd 3.5.0+ which is included in k0s v1.22.1+k0s.0 and newer
if etcdSupportedArchArm64Since.Check(p.Config.Spec.K0s.Version) {
if p.Config.Spec.K0s.Version.GreaterThanOrEqual(etcdSupportedArchArm64Since) {
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions phase/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var _ Phase = &Backup{}

var backupSinceVersion = version.MustConstraint(">= v1.21.0-rc.1+k0s.0")
var backupSinceVersion = version.MustParse("v1.21.0-rc.1+k0s.0")

// Backup connect to one of the controllers and takes a backup
type Backup struct {
Expand All @@ -35,7 +35,7 @@ func (p *Backup) Title() string {
func (p *Backup) Prepare(config *v1beta1.Cluster) error {
p.Config = config

if !backupSinceVersion.Check(p.Config.Spec.K0s.Version) {
if !p.Config.Spec.K0s.Version.GreaterThanOrEqual(backupSinceVersion) {
return fmt.Errorf("the version of k0s on the host does not support taking backups")
}

Expand Down
8 changes: 4 additions & 4 deletions phase/configure_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// "k0s default-config" was replaced with "k0s config create" in v1.23.1+k0s.0
var configCreateSinceVersion = version.MustConstraint(">= v1.23.1+k0s.0")
var configCreateSince = version.MustParse("v1.23.1+k0s.0")

const (
configSourceExisting int = iota
Expand Down Expand Up @@ -202,7 +202,7 @@ func (p *ConfigureK0s) ShouldRun() bool {
func (p *ConfigureK0s) generateDefaultConfig() (string, error) {
log.Debugf("%s: generating default configuration", p.leader)
var cmd string
if configCreateSinceVersion.Check(p.leader.Metadata.K0sBinaryVersion) {
if p.leader.Metadata.K0sBinaryVersion.GreaterThanOrEqual(configCreateSince) {
cmd = p.leader.Configurer.K0sCmdf("config create --data-dir=%s", p.leader.K0sDataDir())
} else {
cmd = p.leader.Configurer.K0sCmdf("default-config")
Expand All @@ -228,7 +228,6 @@ func (p *ConfigureK0s) validateConfig(h *cluster.Host, configPath string) error
log.Infof("%s: validating configuration", h)

var cmd string
log.Debugf("%s: comparing k0s version %s with %s", h, p.Config.Spec.K0s.Version, configCreateSinceVersion)

if h.Metadata.K0sBinaryTempFile != "" {
oldK0sBinaryPath := h.Configurer.K0sBinaryPath()
Expand All @@ -238,7 +237,8 @@ func (p *ConfigureK0s) validateConfig(h *cluster.Host, configPath string) error
}()
}

if configCreateSinceVersion.Check(p.Config.Spec.K0s.Version) {
log.Debugf("%s: comparing k0s version %s with %s", h, p.Config.Spec.K0s.Version, configCreateSince)
if p.Config.Spec.K0s.Version.GreaterThanOrEqual(configCreateSince) {
log.Debugf("%s: comparison result true", h)
cmd = h.Configurer.K0sCmdf(`config validate --config "%s"`, configPath)
} else {
Expand Down
4 changes: 2 additions & 2 deletions phase/gather_facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type GatherFacts struct {
}

// K0s doesn't rely on unique machine IDs anymore since v1.30.
var uniqueMachineIDVersion = version.MustConstraint("< v1.30")
var uniqueMachineIDSince = version.MustParse("v1.30.0")

// Title for the phase
func (p *GatherFacts) Title() string {
Expand All @@ -37,7 +37,7 @@ func (p *GatherFacts) investigateHost(_ context.Context, h *cluster.Host) error
}
h.Metadata.Arch = output

if !p.SkipMachineIDs && uniqueMachineIDVersion.Check(p.Config.Spec.K0s.Version) {
if !p.SkipMachineIDs && p.Config.Spec.K0s.Version.LessThan(uniqueMachineIDSince) {
id, err := h.Configurer.MachineID(h)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions phase/prepare_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
log "github.com/sirupsen/logrus"
)

var iptablesEmbeddedSince = version.MustConstraint(">= v1.22.1+k0s.0")
var iptablesEmbeddedSince = version.MustParse("v1.22.1+k0s.0")

// PrepareHosts installs required packages and so on on the hosts.
type PrepareHosts struct {
Expand Down Expand Up @@ -85,7 +85,7 @@ func (p *PrepareHosts) prepareHost(ctx context.Context, h *cluster.Host) error {
}

// iptables is only required for very old versions of k0s
if p.Config.Spec.K0s.Version != nil && !iptablesEmbeddedSince.Check(p.Config.Spec.K0s.Version) && h.NeedIPTables() { //nolint:staticcheck
if p.Config.Spec.K0s.Version != nil && !p.Config.Spec.K0s.Version.GreaterThanOrEqual(iptablesEmbeddedSince) && h.NeedIPTables() { //nolint:staticcheck
pkgs = append(pkgs, "iptables")
}

Expand Down
6 changes: 3 additions & 3 deletions phase/reinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func (p *Reinstall) Prepare(config *v1beta1.Cluster) error {

// ShouldRun is true when there are hosts that needs to be reinstalled
func (p *Reinstall) ShouldRun() bool {
return cluster.K0sForceFlagSince.Check(p.Config.Spec.K0s.Version) && len(p.hosts) > 0
return p.Config.Spec.K0s.Version.GreaterThanOrEqual(cluster.K0sForceFlagSince) && len(p.hosts) > 0
}

// Run the phase
func (p *Reinstall) Run(ctx context.Context) error {
if !cluster.K0sForceFlagSince.Check(p.Config.Spec.K0s.Version) {
func (p *Reinstall) Run() error {
if p.Config.Spec.K0s.Version.LessThan(cluster.K0sForceFlagSince) {
log.Warnf("k0s version %s does not support install --force flag, installFlags won't be reconfigured", p.Config.Spec.K0s.Version)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion phase/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *Restore) Prepare(config *v1beta1.Cluster) error {
}

// defined in backup.go
if !backupSinceVersion.Check(p.Config.Spec.K0s.Version) {
if p.Config.Spec.K0s.Version.LessThan(backupSinceVersion) {
return fmt.Errorf("the version of k0s on the host does not support restoring backups")
}

Expand Down
2 changes: 1 addition & 1 deletion phase/validate_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (p *ValidateHosts) Title() string {
// Run the phase
func (p *ValidateHosts) Run(ctx context.Context) error {
p.hncount = make(map[string]int, len(p.Config.Spec.Hosts))
if uniqueMachineIDVersion.Check(p.Config.Spec.K0s.Version) {
if p.Config.Spec.K0s.Version.LessThan(uniqueMachineIDSince) {
p.machineidcount = make(map[string]int, len(p.Config.Spec.Hosts))
}
p.privateaddrcount = make(map[string]int, len(p.Config.Spec.Hosts))
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
log "github.com/sirupsen/logrus"
)

var K0sForceFlagSince = version.MustConstraint(">= v1.27.4+k0s.0")
var K0sForceFlagSince = version.MustParse("v1.27.4+k0s.0")

// Host contains all the needed details to work with hosts
type Host struct {
Expand Down Expand Up @@ -179,7 +179,7 @@ type HostMetadata struct {
K0sInstalled bool
K0sExistingConfig string
K0sNewConfig string
K0sTokenData TokenData
K0sTokenData TokenData
K0sStatusArgs Flags
Arch string
IsK0sLeader bool
Expand Down Expand Up @@ -329,7 +329,7 @@ func (h *Host) K0sInstallFlags() (Flags, error) {
}
}

if flags.Include("--force") && h.Metadata.K0sBinaryVersion != nil && !K0sForceFlagSince.Check(h.Metadata.K0sBinaryVersion) {
if flags.Include("--force") && h.Metadata.K0sBinaryVersion != nil && h.Metadata.K0sBinaryVersion.LessThan(K0sForceFlagSince) {
log.Warnf("%s: k0s version %s does not support the --force flag, ignoring it", h, h.Metadata.K0sBinaryVersion)
flags.Delete("--force")
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
const K0sMinVersion = "0.11.0-rc1"

var (
k0sSupportedVersion = version.MustConstraint(">= " + K0sMinVersion)
k0sDynamicConfigSince = version.MustConstraint(">= 1.22.2+k0s.2")
k0sTokenCreateConfigFlagUntil = version.MustConstraint("< v1.23.4-rc.1+k0s.0")
k0sSupportedVersion = version.MustParse(K0sMinVersion)
k0sDynamicConfigSince = version.MustParse("1.22.2+k0s.2")
k0sTokenCreateConfigFlagUntil = version.MustParse("v1.23.4-rc.1+k0s.0")
)

// K0s holds configuration for bootstraping a k0s cluster
Expand Down Expand Up @@ -97,7 +97,7 @@ func validateVersion(value interface{}) error {
return nil
}

if !k0sSupportedVersion.Check(v) {
if v.LessThan(k0sSupportedVersion) {
return fmt.Errorf("minimum supported k0s version is %s", k0sSupportedVersion)
}

Expand All @@ -122,7 +122,7 @@ func (k *K0s) validateMinDynamic() func(interface{}) error {
return nil
}

if k.Version != nil && !k.Version.IsZero() && !k0sDynamicConfigSince.Check(k.Version) {
if k.Version != nil && !k.Version.IsZero() && k.Version.LessThan(k0sDynamicConfigSince) {
return fmt.Errorf("dynamic config only available since k0s version %s", k0sDynamicConfigSince)
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func (k *K0s) GenerateToken(ctx context.Context, h *Host, role string, expiry ti

k0sFlags.AddOrReplace(fmt.Sprintf("--data-dir=%s", h.K0sDataDir()))

if k0sTokenCreateConfigFlagUntil.Check(k.Version) {
if k.Version.LessThanOrEqual(k0sTokenCreateConfigFlagUntil) {
k0sFlags.Add(fmt.Sprintf("--config %s", shellescape.Quote(h.K0sConfigPath())))
}

Expand Down

0 comments on commit 3b0f3ef

Please sign in to comment.