-
Notifications
You must be signed in to change notification settings - Fork 74
/
detect_os.go
54 lines (46 loc) · 1.54 KB
/
detect_os.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
package phase
import (
"strings"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
// anonymous import is needed to load the os configurers
_ "github.com/k0sproject/k0sctl/configurer"
// anonymous import is needed to load the os configurers
_ "github.com/k0sproject/k0sctl/configurer/linux"
// anonymous import is needed to load the os configurers
_ "github.com/k0sproject/k0sctl/configurer/linux/enterpriselinux"
log "github.com/sirupsen/logrus"
)
// DetectOS performs remote OS detection
type DetectOS struct {
GenericPhase
}
// Title for the phase
func (p *DetectOS) Title() string {
return "Detect host operating systems"
}
// Run the phase
func (p *DetectOS) Run() error {
return p.parallelDo(p.Config.Spec.Hosts, func(h *cluster.Host) error {
if h.OSIDOverride != "" {
log.Infof("%s: OS ID has been manually set to %s", h, h.OSIDOverride)
}
if err := h.ResolveConfigurer(); err != nil {
p.SetProp("missing-support", h.OSVersion.String())
if h.OSVersion.IDLike != "" {
log.Debugf("%s: trying to find a fallback OS support module for %s using os-release ID_LIKE '%s'", h, h.OSVersion.String(), h.OSVersion.IDLike)
for _, id := range strings.Split(h.OSVersion.IDLike, " ") {
h.OSVersion.ID = id
if err := h.ResolveConfigurer(); err == nil {
log.Warnf("%s: using '%s' as OS support fallback for %s", h, id, h.OSVersion.String())
return nil
}
}
}
return err
}
os := h.OSVersion.String()
p.IncProp(os)
log.Infof("%s: is running %s", h, os)
return nil
})
}