diff --git a/cli/kata-check.go b/cli/kata-check.go index 683d2619f1..5d84a374e2 100644 --- a/cli/kata-check.go +++ b/cli/kata-check.go @@ -63,6 +63,7 @@ const ( moduleParamDir = "parameters" successMessageCapable = "System is capable of running " + project successMessageCreate = "System can currently create " + project + successMessageVersion = "Version consistency of " + project + " is verified" failMessage = "System is not capable of running " + project kernelPropertyCorrect = "Kernel property value correct" @@ -309,6 +310,10 @@ var kataCheckCLICommand = cli.Command{ Name: "verbose, v", Usage: "display the list of checks performed", }, + cli.BoolFlag{ + Name: "strict, s", + Usage: "perform strict checking", + }, }, Action: func(context *cli.Context) error { @@ -357,6 +362,16 @@ var kataCheckCLICommand = cli.Command{ fmt.Println(successMessageCreate) } + strict := context.Bool("strict") + if strict { + err = checkVersionConsistencyInComponents(runtimeConfig) + if err != nil { + return err + } + + fmt.Println(successMessageVersion) + } + return nil }, } @@ -454,3 +469,35 @@ func genericCheckKVMExtensions(extensions map[string]kvmExtension) (map[string]i 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 +} diff --git a/cli/utils.go b/cli/utils.go index 3d17df37c1..f6c855c488 100644 --- a/cli/utils.go +++ b/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 +}