Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions upup/pkg/fi/nodeup/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"fmt"
"reflect"

"k8s.io/klog/v2"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
)

type Loader struct {
Expand All @@ -43,17 +41,5 @@ func (l *Loader) Build() (map[string]fi.NodeupTask, error) {
tasks = context.Tasks
}

// If there is a package task, we need an update packages task
for _, t := range tasks {
if _, ok := t.(*nodetasks.Package); ok {
klog.Infof("Package task found; adding UpdatePackages task")
tasks["UpdatePackages"] = nodetasks.NewUpdatePackages()
break
}
}
if tasks["UpdatePackages"] == nil {
klog.Infof("No package task found; won't update packages")
}

return tasks, nil
}
39 changes: 33 additions & 6 deletions upup/pkg/fi/nodeup/nodetasks/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"reflect"
"strings"
"sync"
"time"

"k8s.io/klog/v2"
"k8s.io/kops/pkg/apis/kops"
Expand Down Expand Up @@ -65,9 +66,9 @@ var _ fi.NodeupHasDependencies = &Package{}
func (e *Package) GetDependencies(tasks map[string]fi.NodeupTask) []fi.NodeupTask {
var deps []fi.NodeupTask

// UpdatePackages before we install any packages
// AptSource before we install any packages
for _, v := range tasks {
if _, ok := v.(*UpdatePackages); ok {
if _, ok := v.(*AptSource); ok {
deps = append(deps, v)
}
}
Expand Down Expand Up @@ -320,11 +321,37 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
pkgs = append(pkgs, e.Name)
}

var args []string
env := os.Environ()
if d.IsDebianFamily() {
args = []string{"apt-get", "install", "--yes", "--no-install-recommends"}
env = append(env, "DEBIAN_FRONTEND=noninteractive")
}

if d.IsDebianFamily() {
// Each time apt-get install is run, the timestamp of /var/lib/dpkg/status is updated.
// To avoid unnecessary apt-get update calls, we check the timestamp of this file.
// If it is newer than 10 minutes, we skip apt-get update.
stat, err := os.Stat("/var/lib/dpkg/status")
if err != nil {
klog.Infof("Error getting dpkg status info: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we probably should apt-get update in this case (?)

} else {
if stat.ModTime().After(time.Now().Add(-10 * time.Minute)) {
klog.Infof("Skipping package install as /var/lib/dpkg/status is newer than 10 minutes")
} else {
args := []string{"apt-get", "update"}
klog.Infof("Running command %s", args)
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = env
output, err := cmd.CombinedOutput()
if err != nil {
klog.Infof("Error fetching the latest list of available packages: %v:\n%s", err, string(output))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: klog.Warningf or klog.Errorf ...

And maybe a comment that we don't want to fail the nodeup for this, because it could be a transient mirror failure (for example)

}
}
}
}

var args []string
if d.IsDebianFamily() {
args = []string{"apt-get", "install", "--yes", "--no-install-recommends"}
} else if d.IsRHELFamily() {

if d.HasDNF() {
Expand All @@ -337,7 +364,7 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
}
args = append(args, pkgs...)

klog.Infof("running command %s", args)
klog.Infof("Running command %s", args)
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = env
output, err := cmd.CombinedOutput()
Expand All @@ -350,7 +377,7 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
if strings.Contains(string(output), "dpkg --configure -a") {
klog.Warningf("found error requiring dpkg repair: %q", string(output))
args := []string{"dpkg", "--configure", "-a"}
klog.Infof("running command %s", args)
klog.Infof("Running command %s", args)
cmd := exec.Command(args[0], args[1:]...)
dpkgOutput, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/nodeup/nodetasks/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *Service) GetDependencies(tasks map[string]fi.NodeupTask) []fi.NodeupTas
// launching a custom Kubernetes build), they all depend on
// the "docker.service" Service task.
switch v := v.(type) {
case *Package, *UpdatePackages, *UserTask, *GroupTask, *Chattr, *BindMount, *Archive, *Prefix, *UpdateEtcHostsTask:
case *Package, *AptSource, *UserTask, *GroupTask, *Chattr, *BindMount, *Archive, *Prefix, *UpdateEtcHostsTask:
deps = append(deps, v)
case *Service, *PullImageTask, *IssueCert, *BootstrapClientTask, *KubeConfig:
// ignore
Expand Down
95 changes: 0 additions & 95 deletions upup/pkg/fi/nodeup/nodetasks/update_packages.go

This file was deleted.

Loading