-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_packages.go
73 lines (60 loc) · 1.78 KB
/
update_packages.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
package nodetasks
import (
"fmt"
"github.com/golang/glog"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
"k8s.io/kops/upup/pkg/fi/nodeup/local"
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
"os"
"os/exec"
)
type UpdatePackages struct {
// We can't be completely empty or we don't run
Updated bool
}
var _ fi.HasDependencies = &UpdatePackages{}
func NewUpdatePackages() *UpdatePackages {
return &UpdatePackages{Updated: true}
}
func (p *UpdatePackages) GetDependencies(tasks map[string]fi.Task) []fi.Task {
return []fi.Task{}
}
func (p *UpdatePackages) String() string {
return fmt.Sprintf("UpdatePackages")
}
func (e *UpdatePackages) Find(c *fi.Context) (*UpdatePackages, error) {
return nil, nil
}
func (e *UpdatePackages) Run(c *fi.Context) error {
return fi.DefaultDeltaRunMethod(e, c)
}
func (s *UpdatePackages) CheckChanges(a, e, changes *UpdatePackages) error {
return nil
}
func (_ *UpdatePackages) RenderLocal(t *local.LocalTarget, a, e, changes *UpdatePackages) error {
if os.Getenv("SKIP_PACKAGE_UPDATE") != "" {
glog.Infof("SKIP_PACKAGE_UPDATE was set; skipping package update")
return nil
}
var args []string
if t.HasTag(tags.TagOSFamilyDebian) {
args = []string{"apt-get", "update"}
} else if t.HasTag(tags.TagOSFamilyRHEL) {
// Probably not technically needed
args = []string{"/usr/bin/yum", "check-update"}
} else {
return fmt.Errorf("unsupported package system")
}
glog.Infof("running command %s", args)
cmd := exec.Command(args[0], args[1:]...)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error update packages: %v: %s", err, string(output))
}
return nil
}
func (_ *UpdatePackages) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *UpdatePackages) error {
t.Config.PackageUpdate = true
return nil
}