This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
dep.go
99 lines (76 loc) · 2.27 KB
/
dep.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package kubelet
import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"
"github.com/pkg/errors"
"github.com/caos/orbos/internal/operator/common"
"github.com/caos/orbos/internal/operator/nodeagent"
"github.com/caos/orbos/internal/operator/nodeagent/dep"
"github.com/caos/orbos/internal/operator/nodeagent/dep/k8s"
"github.com/caos/orbos/internal/operator/nodeagent/dep/middleware"
"github.com/caos/orbos/internal/operator/nodeagent/dep/selinux"
"github.com/caos/orbos/mntr"
)
type Installer interface {
isKubelet()
nodeagent.Installer
}
type kubeletDep struct {
os dep.OperatingSystem
monitor mntr.Monitor
common *k8s.Common
systemd *dep.SystemD
}
func New(monitor mntr.Monitor, os dep.OperatingSystem, manager *dep.PackageManager, systemd *dep.SystemD) Installer {
return &kubeletDep{os, monitor, k8s.New(os, manager, "kubelet"), systemd}
}
func (kubeletDep) isKubelet() {}
func (kubeletDep) Is(other nodeagent.Installer) bool {
_, ok := middleware.Unwrap(other).(Installer)
return ok
}
func (k kubeletDep) String() string { return "Kubelet" }
func (*kubeletDep) Equals(other nodeagent.Installer) bool {
_, ok := other.(*kubeletDep)
return ok
}
func (k *kubeletDep) Current() (pkg common.Package, err error) {
pkg, err = k.common.Current()
if err != nil {
return pkg, err
}
return pkg, selinux.Current(k.os, &pkg)
}
func (k *kubeletDep) Ensure(remove common.Package, install common.Package) error {
if err := selinux.EnsurePermissive(k.monitor, k.os, remove); err != nil {
return err
}
if k.os != dep.CentOS {
return k.ensurePackage(remove, install)
}
errBuf := new(bytes.Buffer)
defer errBuf.Reset()
cmd := exec.Command("modprobe", "br_netfilter")
cmd.Stderr = errBuf
if k.monitor.IsVerbose() {
fmt.Println(strings.Join(cmd.Args, " "))
cmd.Stdout = os.Stdout
}
if err := cmd.Run(); err != nil {
return errors.Wrapf(err, "loading module br_netfilter while installing kubelet failed with stderr %s", errBuf.String())
}
errBuf.Reset()
return k.ensurePackage(remove, install)
}
func (k *kubeletDep) ensurePackage(remove common.Package, install common.Package) error {
if err := k.common.Ensure(remove, install); err != nil {
return err
}
if err := k.systemd.Enable("kubelet"); err != nil {
return err
}
return k.systemd.Start("kubelet")
}