-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Update the node package list only before installing packages #17690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import ( | |
| "reflect" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "k8s.io/klog/v2" | ||
| "k8s.io/kops/pkg/apis/kops" | ||
|
|
@@ -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) | ||
| } | ||
| } | ||
|
|
@@ -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) | ||
| } 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)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
|
@@ -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() | ||
|
|
@@ -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 { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 (?)