mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-16 06:18:58 +00:00
kata-check: use "--strict" to perform version consistency check
Use `kata-runtime kata-check --strict/-s` to perform version consistency check. Only if major version number, minor version number and Patch number are all the same, we determine those two kata components are version-consistent. Fixes: #2375 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
This commit is contained in:
@@ -63,6 +63,7 @@ const (
|
|||||||
moduleParamDir = "parameters"
|
moduleParamDir = "parameters"
|
||||||
successMessageCapable = "System is capable of running " + project
|
successMessageCapable = "System is capable of running " + project
|
||||||
successMessageCreate = "System can currently create " + project
|
successMessageCreate = "System can currently create " + project
|
||||||
|
successMessageVersion = "Version consistency of " + project + " is verified"
|
||||||
failMessage = "System is not capable of running " + project
|
failMessage = "System is not capable of running " + project
|
||||||
kernelPropertyCorrect = "Kernel property value correct"
|
kernelPropertyCorrect = "Kernel property value correct"
|
||||||
|
|
||||||
@@ -309,6 +310,10 @@ var kataCheckCLICommand = cli.Command{
|
|||||||
Name: "verbose, v",
|
Name: "verbose, v",
|
||||||
Usage: "display the list of checks performed",
|
Usage: "display the list of checks performed",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "strict, s",
|
||||||
|
Usage: "perform strict checking",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
@@ -357,6 +362,16 @@ var kataCheckCLICommand = cli.Command{
|
|||||||
fmt.Println(successMessageCreate)
|
fmt.Println(successMessageCreate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strict := context.Bool("strict")
|
||||||
|
if strict {
|
||||||
|
err = checkVersionConsistencyInComponents(runtimeConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(successMessageVersion)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -454,3 +469,35 @@ func genericCheckKVMExtensions(extensions map[string]kvmExtension) (map[string]i
|
|||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkVersionConsistencyInComponents checks version consistency in Kata Components.
|
||||||
|
func checkVersionConsistencyInComponents(config oci.RuntimeConfig) error {
|
||||||
|
proxyInfo := getProxyInfo(config)
|
||||||
|
|
||||||
|
shimInfo, err := getShimInfo(config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
shimVersionInfo := shimInfo.Version
|
||||||
|
|
||||||
|
runtimeVersionInfo := constructVersionInfo(version)
|
||||||
|
|
||||||
|
// kata-proxy exists
|
||||||
|
if proxyInfo.Type != string(vc.NoProxyType) {
|
||||||
|
proxyVersionInfo := proxyInfo.Version
|
||||||
|
if !versionEqual(proxyVersionInfo, runtimeVersionInfo) || !versionEqual(shimVersionInfo, runtimeVersionInfo) {
|
||||||
|
return fmt.Errorf("there exists version inconsistency in kata components. kata-proxy: v%d.%d.%d, kata-shim: v%d.%d.%d, kata-runtime: v%d.%d.%d",
|
||||||
|
proxyVersionInfo.Major, proxyVersionInfo.Minor, proxyVersionInfo.Patch,
|
||||||
|
shimVersionInfo.Major, shimVersionInfo.Minor, shimVersionInfo.Patch,
|
||||||
|
runtimeVersionInfo.Major, runtimeVersionInfo.Minor, runtimeVersionInfo.Patch)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !versionEqual(shimVersionInfo, runtimeVersionInfo) {
|
||||||
|
return fmt.Errorf("there exists version inconsistency in kata components. kata-shim: v%d.%d.%d, kata-runtime: v%d.%d.%d",
|
||||||
|
shimVersionInfo.Major, shimVersionInfo.Minor, shimVersionInfo.Patch,
|
||||||
|
runtimeVersionInfo.Major, runtimeVersionInfo.Minor, runtimeVersionInfo.Patch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
18
cli/utils.go
18
cli/utils.go
@@ -183,3 +183,21 @@ func constructVersionInfo(version string) VersionInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func versionEqual(a VersionInfo, b VersionInfo) bool {
|
||||||
|
av, err := semver.Make(a.Semver)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
bv, err := semver.Make(b.Semver)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if av.Major == bv.Major && av.Minor == bv.Minor && av.Patch == bv.Patch {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user