mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-09 03:48:05 +00:00
Merge pull request #1146 from devimc/2020-11-19/fixKataCheck
[forward port] cli: make check subcommand more tolerant to failures
This commit is contained in:
commit
2c6cee0d28
@ -134,17 +134,25 @@ func getCPUFlags(cpuinfo string) string {
|
|||||||
// haveKernelModule returns true if the specified module exists
|
// haveKernelModule returns true if the specified module exists
|
||||||
// (either loaded or available to be loaded)
|
// (either loaded or available to be loaded)
|
||||||
func haveKernelModule(module string) bool {
|
func haveKernelModule(module string) bool {
|
||||||
|
kmodLog := kataLog.WithField("module", module)
|
||||||
|
|
||||||
// First, check to see if the module is already loaded
|
// First, check to see if the module is already loaded
|
||||||
path := filepath.Join(sysModuleDir, module)
|
path := filepath.Join(sysModuleDir, module)
|
||||||
if katautils.FileExists(path) {
|
if katautils.FileExists(path) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only root can load modules
|
||||||
|
if os.Getuid() != 0 {
|
||||||
|
kmodLog.Error("Module is not loaded and it can not be inserted. Please consider running with sudo or as root")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Now, check if the module is unloaded, but available.
|
// Now, check if the module is unloaded, but available.
|
||||||
// And modprobe it if so.
|
// And modprobe it if so.
|
||||||
cmd := exec.Command(modProbeCmd, module)
|
cmd := exec.Command(modProbeCmd, module)
|
||||||
if output, err := cmd.CombinedOutput(); err != nil {
|
if output, err := cmd.CombinedOutput(); err != nil {
|
||||||
kataLog.WithField("module", module).WithError(err).Warnf("modprobe insert module failed: %s", string(output))
|
kmodLog.WithError(err).WithField("output", string(output)).Warnf("modprobe insert module failed")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -513,6 +513,10 @@ func TestCheckCheckCPUAttribs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckHaveKernelModule(t *testing.T) {
|
func TestCheckHaveKernelModule(t *testing.T) {
|
||||||
|
if tc.NotValid(ktu.NeedRoot()) {
|
||||||
|
t.Skip(testDisabledAsNonRoot)
|
||||||
|
}
|
||||||
|
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "")
|
dir, err := ioutil.TempDir("", "")
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -276,12 +277,17 @@ func getReleases(releaseURL string, includeAll bool) ([]semver.Version, map[stri
|
|||||||
|
|
||||||
releasesArray := []map[string]interface{}{}
|
releasesArray := []map[string]interface{}{}
|
||||||
|
|
||||||
bytes, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to read release details: %v", err)
|
return nil, nil, fmt.Errorf("failed to read release details: %v", err)
|
||||||
|
} else if resp.StatusCode == http.StatusForbidden && bytes.Contains(body, []byte("limit exceeded")) {
|
||||||
|
// Do not fail if rate limit is exceeded
|
||||||
|
kataLog.WithField("url", releaseURL).
|
||||||
|
Warn("API rate limit exceeded. Try again later. Read https://docs.github.com/apps/building-github-apps/understanding-rate-limits-for-github-apps for more information")
|
||||||
|
return []semver.Version{}, map[string]releaseDetails{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(bytes, &releasesArray); err != nil {
|
if err := json.Unmarshal(body, &releasesArray); err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to unpack release details: %v", err)
|
return nil, nil, fmt.Errorf("failed to unpack release details: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user