diff --git a/src/runtime/cli/kata-check.go b/src/runtime/cli/kata-check.go index 2e3cb24103..a1add256d2 100644 --- a/src/runtime/cli/kata-check.go +++ b/src/runtime/cli/kata-check.go @@ -34,12 +34,12 @@ import ( ) type kernelModule struct { - // description - desc string - // maps parameter names to values parameters map[string]string + // description + desc string + // if it is definitely required required bool } @@ -54,10 +54,10 @@ type kvmExtension struct { } type vmContainerCapableDetails struct { - cpuInfoFile string requiredCPUFlags map[string]string requiredCPUAttribs map[string]string requiredKernelModules map[string]kernelModule + cpuInfoFile string } const ( diff --git a/src/runtime/cli/kata-check_amd64_test.go b/src/runtime/cli/kata-check_amd64_test.go index d7a45cbcb9..69b09c88dc 100644 --- a/src/runtime/cli/kata-check_amd64_test.go +++ b/src/runtime/cli/kata-check_amd64_test.go @@ -109,12 +109,12 @@ func TestCheckCheckKernelModulesNoNesting(t *testing.T) { } actualModuleData := []testModuleData{ - {filepath.Join(sysModuleDir, "kvm"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_intel"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_intel/parameters/unrestricted_guest"), false, "Y"}, + {filepath.Join(sysModuleDir, "kvm"), "", true}, + {filepath.Join(sysModuleDir, "kvm_intel"), "", true}, + {filepath.Join(sysModuleDir, "kvm_intel/parameters/unrestricted_guest"), "Y", false}, // XXX: force a warning - {filepath.Join(sysModuleDir, "kvm_intel/parameters/nested"), false, "N"}, + {filepath.Join(sysModuleDir, "kvm_intel/parameters/nested"), "N", false}, } vendor := archGenuineIntel @@ -194,12 +194,12 @@ func TestCheckCheckKernelModulesNoUnrestrictedGuest(t *testing.T) { } actualModuleData := []testModuleData{ - {filepath.Join(sysModuleDir, "kvm"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_intel"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_intel/parameters/nested"), false, "Y"}, + {filepath.Join(sysModuleDir, "kvm"), "", true}, + {filepath.Join(sysModuleDir, "kvm_intel"), "", true}, + {filepath.Join(sysModuleDir, "kvm_intel/parameters/nested"), "Y", false}, // XXX: force a failure on non-VMM systems - {filepath.Join(sysModuleDir, "kvm_intel/parameters/unrestricted_guest"), false, "N"}, + {filepath.Join(sysModuleDir, "kvm_intel/parameters/unrestricted_guest"), "N", false}, } vendor := archGenuineIntel @@ -295,10 +295,10 @@ func TestCheckHostIsVMContainerCapable(t *testing.T) { } moduleData = []testModuleData{ - {filepath.Join(sysModuleDir, "kvm"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_intel"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_intel/parameters/nested"), false, "Y"}, - {filepath.Join(sysModuleDir, "kvm_intel/parameters/unrestricted_guest"), false, "Y"}, + {filepath.Join(sysModuleDir, "kvm"), "", true}, + {filepath.Join(sysModuleDir, "kvm_intel"), "", true}, + {filepath.Join(sysModuleDir, "kvm_intel/parameters/nested"), "Y", false}, + {filepath.Join(sysModuleDir, "kvm_intel/parameters/unrestricted_guest"), "Y", false}, } } else if cpuType == cpuTypeAMD { cpuData = []testCPUData{ @@ -311,9 +311,9 @@ func TestCheckHostIsVMContainerCapable(t *testing.T) { } moduleData = []testModuleData{ - {filepath.Join(sysModuleDir, "kvm"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_amd"), true, ""}, - {filepath.Join(sysModuleDir, "kvm_amd/parameters/nested"), false, "1"}, + {filepath.Join(sysModuleDir, "kvm"), "", true}, + {filepath.Join(sysModuleDir, "kvm_amd"), "", true}, + {filepath.Join(sysModuleDir, "kvm_amd/parameters/nested"), "1", false}, } } @@ -338,51 +338,51 @@ func TestArchKernelParamHandler(t *testing.T) { assert := assert.New(t) type testData struct { - onVMM bool - expectIgnore bool fields logrus.Fields msg string + onVMM bool + expectIgnore bool } data := []testData{ - {true, false, logrus.Fields{}, ""}, - {false, false, logrus.Fields{}, ""}, + {logrus.Fields{}, "", true, false}, + {logrus.Fields{}, "", false, false}, { - false, - false, logrus.Fields{ // wrong type "parameter": 123, }, "foo", + false, + false, }, { - false, - false, logrus.Fields{ "parameter": "unrestricted_guest", }, "", + false, + false, }, { - true, - true, logrus.Fields{ "parameter": "unrestricted_guest", }, "", + true, + true, }, { - false, - true, logrus.Fields{ "parameter": "nested", }, "", + false, + true, }, } diff --git a/src/runtime/cli/kata-check_test.go b/src/runtime/cli/kata-check_test.go index 38e6ec62ea..b64fb8e013 100644 --- a/src/runtime/cli/kata-check_test.go +++ b/src/runtime/cli/kata-check_test.go @@ -26,8 +26,8 @@ import ( type testModuleData struct { path string - isDir bool contents string + isDir bool } // nolint: structcheck, unused, deadcode @@ -400,46 +400,46 @@ func TestCheckCheckCPUFlags(t *testing.T) { assert := assert.New(t) type testData struct { - cpuflags string required map[string]string + cpuflags string expectCount uint32 } data := []testData{ { - "", map[string]string{}, + "", 0, }, { - "", map[string]string{ "a": "A flag", }, + "", 0, }, { - "", map[string]string{ "a": "A flag", "b": "B flag", }, + "", 0, }, { - "a b c", map[string]string{ "b": "B flag", }, + "a b c", 0, }, { - "a b c", map[string]string{ "x": "X flag", "y": "Y flag", "z": "Z flag", }, + "a b c", 3, }, } @@ -454,54 +454,54 @@ func TestCheckCheckCPUAttribs(t *testing.T) { assert := assert.New(t) type testData struct { - cpuinfo string required map[string]string + cpuinfo string expectCount uint32 } data := []testData{ { - "", map[string]string{}, + "", 0, }, { - "", map[string]string{ "a": "", }, + "", 0, }, { + map[string]string{ + "b": "B attribute", + }, "a: b", - map[string]string{ - "b": "B attribute", - }, 0, }, { + map[string]string{ + "b": "B attribute", + }, "a: b\nc: d\ne: f", - map[string]string{ - "b": "B attribute", - }, 0, }, { - "a: b\n", map[string]string{ "b": "B attribute", "c": "C attribute", "d": "D attribute", }, + "a: b\n", 2, }, { - "a: b\nc: d\ne: f", map[string]string{ "b": "B attribute", "d": "D attribute", "f": "F attribute", }, + "a: b\nc: d\ne: f", 0, }, } diff --git a/src/runtime/cli/kata-env.go b/src/runtime/cli/kata-env.go index 3816754755..87e803825b 100644 --- a/src/runtime/cli/kata-env.go +++ b/src/runtime/cli/kata-env.go @@ -72,29 +72,29 @@ type RuntimeConfigInfo struct { // RuntimeInfo stores runtime details. type RuntimeInfo struct { - Version RuntimeVersionInfo Config RuntimeConfigInfo + Path string + Experimental []exp.Feature + Version RuntimeVersionInfo Debug bool Trace bool DisableGuestSeccomp bool DisableNewNetNs bool SandboxCgroupOnly bool - Experimental []exp.Feature - Path string } type VersionInfo struct { Semver string + Commit string Major uint64 Minor uint64 Patch uint64 - Commit string } // RuntimeVersionInfo stores details of the runtime version type RuntimeVersionInfo struct { - Version VersionInfo OCI string + Version VersionInfo } // HypervisorInfo stores hypervisor details @@ -115,10 +115,10 @@ type HypervisorInfo struct { // AgentInfo stores agent details type AgentInfo struct { - Debug bool - Trace bool TraceMode string TraceType string + Debug bool + Trace bool } // DistroInfo stores host operating system distribution details. @@ -140,8 +140,8 @@ type HostInfo struct { // NetmonInfo stores netmon details type NetmonInfo struct { - Version VersionInfo Path string + Version VersionInfo Debug bool Enable bool } @@ -151,15 +151,15 @@ type NetmonInfo struct { // // XXX: Any changes must be coupled with a change to formatVersion. type EnvInfo struct { - Meta MetaInfo - Runtime RuntimeInfo - Hypervisor HypervisorInfo - Image ImageInfo Kernel KernelInfo + Meta MetaInfo + Image ImageInfo Initrd InitrdInfo Agent AgentInfo - Host HostInfo + Hypervisor HypervisorInfo Netmon NetmonInfo + Runtime RuntimeInfo + Host HostInfo } func getMetaInfo() MetaInfo { diff --git a/src/runtime/cli/release.go b/src/runtime/cli/release.go index c86060f9ca..560541c48c 100644 --- a/src/runtime/cli/release.go +++ b/src/runtime/cli/release.go @@ -21,10 +21,10 @@ import ( type ReleaseCmd int type releaseDetails struct { - version semver.Version date string url string filename string + version semver.Version } const ( diff --git a/src/runtime/cli/release_test.go b/src/runtime/cli/release_test.go index fc5b46cbad..275a2b5db4 100644 --- a/src/runtime/cli/release_test.go +++ b/src/runtime/cli/release_test.go @@ -55,16 +55,16 @@ func TestGetReleaseURL(t *testing.T) { type testData struct { currentVersion string - expectError bool expectedURL string + expectError bool } data := []testData{ - {"0.0.0", true, ""}, - {"1.0.0", false, kata1xURL}, - {"1.9999.9999", false, kata1xURL}, - {"2.0.0-alpha3", false, kata2xURL}, - {"2.9999.9999", false, kata2xURL}, + {"0.0.0", "", true}, + {"1.0.0", kata1xURL, false}, + {"1.9999.9999", kata1xURL, false}, + {"2.0.0-alpha3", kata2xURL, false}, + {"2.9999.9999", kata2xURL, false}, } for i, d := range data { @@ -99,17 +99,17 @@ func TestGetReleaseURLEnvVar(t *testing.T) { type testData struct { envVarValue string - expectError bool expectedURL string + expectError bool } data := []testData{ - {"", false, expectedReleasesURL}, - {"http://google.com", true, ""}, - {"https://katacontainers.io", true, ""}, - {"https://github.com/kata-containers/runtime/releases/latest", true, ""}, - {"https://github.com/kata-containers/kata-containers/releases/latest", true, ""}, - {expectedReleasesURL, false, expectedReleasesURL}, + {"", expectedReleasesURL, false}, + {"http://google.com", "", true}, + {"https://katacontainers.io", "", true}, + {"https://github.com/kata-containers/runtime/releases/latest", "", true}, + {"https://github.com/kata-containers/kata-containers/releases/latest", "", true}, + {expectedReleasesURL, expectedReleasesURL, false}, } assert.Equal(os.Getenv("KATA_RELEASE_URL"), "") @@ -138,9 +138,9 @@ func TestMakeRelease(t *testing.T) { type testData struct { release map[string]interface{} - expectError bool expectedVersion string expectedDetails releaseDetails + expectError bool } invalidRel1 := map[string]interface{}{"foo": 1} @@ -228,17 +228,17 @@ func TestMakeRelease(t *testing.T) { } data := []testData{ - {invalidRel1, true, "", releaseDetails{}}, - {invalidRel2, true, "", releaseDetails{}}, - {invalidRel3, true, "", releaseDetails{}}, - {invalidRelMissingVersion, true, "", releaseDetails{}}, - {invalidRelInvalidVersion, true, "", releaseDetails{}}, - {invalidRelMissingAssets, true, "", releaseDetails{}}, - {invalidRelAssetsMissingURL, true, "", releaseDetails{}}, - {invalidRelAssetsMissingFile, true, "", releaseDetails{}}, - {invalidRelAssetsMissingDate, true, "", releaseDetails{}}, + {invalidRel1, "", releaseDetails{}, true}, + {invalidRel2, "", releaseDetails{}, true}, + {invalidRel3, "", releaseDetails{}, true}, + {invalidRelMissingVersion, "", releaseDetails{}, true}, + {invalidRelInvalidVersion, "", releaseDetails{}, true}, + {invalidRelMissingAssets, "", releaseDetails{}, true}, + {invalidRelAssetsMissingURL, "", releaseDetails{}, true}, + {invalidRelAssetsMissingFile, "", releaseDetails{}, true}, + {invalidRelAssetsMissingDate, "", releaseDetails{}, true}, - {validRel, false, testRelVersion, validReleaseDetails}, + {validRel, testRelVersion, validReleaseDetails, false}, } for i, d := range data { @@ -453,47 +453,47 @@ func TestGetNewReleaseType(t *testing.T) { type testData struct { currentVer string latestVer string - expectError bool result string + expectError bool } data := []testData{ // Check build metadata (ignored for version comparisons) - {"2.0.0+build", "2.0.0", true, ""}, - {"2.0.0+build-1", "2.0.0+build-2", true, ""}, - {"1.12.0+build", "1.12.0", true, ""}, + {"2.0.0+build", "2.0.0", "", true}, + {"2.0.0+build-1", "2.0.0+build-2", "", true}, + {"1.12.0+build", "1.12.0", "", true}, - {"2.0.0-rc3+foo", "2.0.0", false, "major"}, - {"2.0.0-rc3+foo", "2.0.0-rc4", false, "pre-release"}, - {"1.12.0+foo", "1.13.0", false, "minor"}, + {"2.0.0-rc3+foo", "2.0.0", "major", false}, + {"2.0.0-rc3+foo", "2.0.0-rc4", "pre-release", false}, + {"1.12.0+foo", "1.13.0", "minor", false}, - {"1.12.0+build", "2.0.0", false, "major"}, - {"1.12.0+build", "1.13.0", false, "minor"}, - {"1.12.0-rc2+build", "1.12.1", false, "patch"}, - {"1.12.0-rc2+build", "1.12.1-foo", false, "patch pre-release"}, - {"1.12.0-rc4+wibble", "1.12.0", false, "major"}, + {"1.12.0+build", "2.0.0", "major", false}, + {"1.12.0+build", "1.13.0", "minor", false}, + {"1.12.0-rc2+build", "1.12.1", "patch", false}, + {"1.12.0-rc2+build", "1.12.1-foo", "patch pre-release", false}, + {"1.12.0-rc4+wibble", "1.12.0", "major", false}, - {"2.0.0-alpha3", "1.0.0", true, ""}, - {"1.0.0", "1.0.0", true, ""}, - {"2.0.0", "1.0.0", true, ""}, + {"2.0.0-alpha3", "1.0.0", "", true}, + {"1.0.0", "1.0.0", "", true}, + {"2.0.0", "1.0.0", "", true}, - {"1.0.0", "2.0.0", false, "major"}, - {"2.0.0-alpha3", "2.0.0-alpha4", false, "pre-release"}, - {"1.0.0", "2.0.0-alpha3", false, "major pre-release"}, + {"1.0.0", "2.0.0", "major", false}, + {"2.0.0-alpha3", "2.0.0-alpha4", "pre-release", false}, + {"1.0.0", "2.0.0-alpha3", "major pre-release", false}, - {"1.0.0", "1.1.2", false, "minor"}, - {"1.0.0", "1.1.2-pre2", false, "minor pre-release"}, - {"1.0.0", "1.1.2-foo", false, "minor pre-release"}, + {"1.0.0", "1.1.2", "minor", false}, + {"1.0.0", "1.1.2-pre2", "minor pre-release", false}, + {"1.0.0", "1.1.2-foo", "minor pre-release", false}, - {"1.0.0", "1.0.3", false, "patch"}, - {"1.0.0-beta29", "1.0.0-beta30", false, "pre-release"}, - {"1.0.0", "1.0.3-alpha99.1b", false, "patch pre-release"}, + {"1.0.0", "1.0.3", "patch", false}, + {"1.0.0-beta29", "1.0.0-beta30", "pre-release", false}, + {"1.0.0", "1.0.3-alpha99.1b", "patch pre-release", false}, - {"2.0.0-rc0", "2.0.0", false, "major"}, - {"2.0.0-rc1", "2.0.0", false, "major"}, + {"2.0.0-rc0", "2.0.0", "major", false}, + {"2.0.0-rc1", "2.0.0", "major", false}, - {"1.12.0-rc0", "1.12.0", false, "major"}, - {"1.12.0-rc5", "1.12.0", false, "major"}, + {"1.12.0-rc0", "1.12.0", "major", false}, + {"1.12.0-rc5", "1.12.0", "major", false}, } for i, d := range data {