-
Notifications
You must be signed in to change notification settings - Fork 74
/
validate_facts.go
71 lines (56 loc) · 1.83 KB
/
validate_facts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package phase
import (
"fmt"
log "github.com/sirupsen/logrus"
)
// ValidateFacts performs remote OS detection
type ValidateFacts struct {
GenericPhase
SkipDowngradeCheck bool
}
// Title for the phase
func (p *ValidateFacts) Title() string {
return "Validate facts"
}
// Run the phase
func (p *ValidateFacts) Run() error {
if err := p.validateDowngrade(); err != nil {
return err
}
if err := p.validateDefaultVersion(); err != nil {
return err
}
return nil
}
func (p *ValidateFacts) validateDowngrade() error {
if p.SkipDowngradeCheck {
return nil
}
if p.Config.Spec.K0sLeader().Metadata.K0sRunningVersion == nil || p.Config.Spec.K0s.Version == nil {
return nil
}
if p.Config.Spec.K0sLeader().Metadata.K0sRunningVersion.GreaterThan(p.Config.Spec.K0s.Version) {
return fmt.Errorf("can't perform a downgrade: %s > %s", p.Config.Spec.K0sLeader().Metadata.K0sRunningVersion, p.Config.Spec.K0s.Version)
}
return nil
}
func (p *ValidateFacts) validateDefaultVersion() error {
// Only check when running with a defaulted version
if !p.Config.Spec.K0s.Metadata.VersionDefaulted {
return nil
}
// Installing a fresh latest is ok
if p.Config.Spec.K0sLeader().Metadata.K0sRunningVersion == nil {
return nil
}
// Upgrading should not be performed if the config version was defaulted
if p.Config.Spec.K0s.Version.GreaterThan(p.Config.Spec.K0sLeader().Metadata.K0sRunningVersion) {
log.Warnf("spec.k0s.version was automatically defaulted to %s but the cluster is running %s", p.Config.Spec.K0s.Version, p.Config.Spec.K0sLeader().Metadata.K0sRunningVersion)
log.Warnf("to perform an upgrade, set the k0s version in the configuration explicitly")
p.Config.Spec.K0s.Version = p.Config.Spec.K0sLeader().Metadata.K0sRunningVersion
for _, h := range p.Config.Spec.Hosts {
h.Metadata.NeedsUpgrade = false
}
}
return nil
}