-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move k0s version defaulting into a phase
Signed-off-by: Kimmo Lehto <[email protected]>
- Loading branch information
Showing
8 changed files
with
90 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package phase | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/k0sproject/version" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type DefaultK0sVersion struct { | ||
GenericPhase | ||
} | ||
|
||
func (p *DefaultK0sVersion) ShouldRun() bool { | ||
return p.Config.Spec.K0s.Version == nil || p.Config.Spec.K0s.Version.IsZero() | ||
} | ||
|
||
func (p *DefaultK0sVersion) Title() string { | ||
return "Set k0s version" | ||
} | ||
|
||
func (p *DefaultK0sVersion) Run() error { | ||
isStable := p.Config.Spec.K0s.VersionChannel == "stable" | ||
|
||
var msg string | ||
if isStable { | ||
msg = "latest stable k0s version" | ||
} else { | ||
msg = "latest k0s version including pre-releases" | ||
} | ||
|
||
log.Info("Looking up ", msg) | ||
latest, err := version.LatestByPrerelease(!isStable) | ||
if err != nil { | ||
return fmt.Errorf("failed to look up k0s version online - try setting spec.k0s.version manually: %w", err) | ||
} | ||
log.Infof("Using k0s version %s", latest) | ||
p.Config.Spec.K0s.Version = latest | ||
p.Config.Spec.K0s.Metadata.VersionDefaulted = true | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters