-
Notifications
You must be signed in to change notification settings - Fork 375
kata-check: Add version consistency check #2376
kata-check: Add version consistency check #2376
Conversation
Hi @lifupan |
331eb90
to
6605630
Compare
/test |
Codecov Report
@@ Coverage Diff @@
## master #2376 +/- ##
=========================================
Coverage ? 50.79%
=========================================
Files ? 114
Lines ? 16381
Branches ? 0
=========================================
Hits ? 8321
Misses ? 7035
Partials ? 1025 |
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.
Thanks @Pennyzct - this is a good idea. A few comments...
cli/kata-check.go
Outdated
@@ -454,3 +459,45 @@ func genericCheckKVMExtensions(extensions map[string]kvmExtension) (map[string]i | |||
|
|||
return results, nil | |||
} | |||
|
|||
// func checkVersionConsistencyInComponents checks version consistency in kata components. |
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.
Nit: The comment should start with the name of the function (without func
).
cli/kata-check.go
Outdated
return errors.New("cannot determine runtime config") | ||
} | ||
|
||
proxyInfo, _ := getProxyInfo(config) |
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.
It might be worth removing the error
return value for getProxyInfo()
as it's always nil
(same for getNetmonInfo()
).
cli/kata-check.go
Outdated
@@ -357,6 +358,10 @@ var kataCheckCLICommand = cli.Command{ | |||
fmt.Println(successMessageCreate) | |||
} | |||
|
|||
if err := checkVersionConsistencyInComponents(context); err != nil { |
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.
You could simplify this block to just:
return checkVersionConsistencyInComponents(context)
cli/kata-check.go
Outdated
} | ||
|
||
var runtimeVersion VersionInfo | ||
versions := strings.Split(version, ".") |
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.
This works but it may be better to use the already-vendored semver package (github.com/blang/semver
).
cli/kata-check.go
Outdated
|
||
if proxyInfo.Version.Version != "" { | ||
if !versionCompare(proxyInfo.Version, runtimeVersion) || !versionCompare(shimInfo.Version, runtimeVersion) { | ||
fmt.Printf("Warning: there exists version inconsistency in kata components. kata-proxy: v%s.%s, kata-shim: v%s.%s, kata-runtime: v%s.%s\n", proxyInfo.Version.Major, proxyInfo.Version.Minor, |
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.
- s/kata components/Kata components/
- We use semver consistently so I think we should display all three parts of the version here (major, minor + patch) , or just the entire version string with a single
%s
. - Random thought: this would expand the scope of this PR a little, but I wonder if we want to add a
--strict
option so that if you runkata-runtime kata-check --strict
and one of these checks fails, it returns1
rather than0
. That could be more useful for scripts, etc which shouldn't have to parsestderr
. That would imply this function would then return an actual error which itself would make it easier to unit test.
cli/kata-env.go
Outdated
@@ -34,6 +34,12 @@ type MetaInfo struct { | |||
Version string | |||
} | |||
|
|||
type VersionInfo struct { | |||
Version string |
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.
This is a little confusing - what is Version
? I think it's the raw output of $cmd --version
so I'd make that clearer by adding a comment or renaming the field. But again, I'd look at the semver
package to avoid "re-inventing the wheel" - you could just store a semver.Version
as that contains everything we'd need.
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.
Ya, same question, what is the Version
here? Shouldnt this be Major
, Minor
and Patch
instead?
Are we not comparing the "Patch" version at all?
cli/kata-env_test.go
Outdated
@@ -30,8 +30,9 @@ import ( | |||
"github.com/stretchr/testify/assert" | |||
) | |||
|
|||
const testProxyVersion = "proxy version 0.1" | |||
const testShimVersion = "shim version 0.1" | |||
var testProxyVersion = VersionInfo{Version: "proxy version 0.1", Major: "0", Minor: "1"} |
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.
Great to see some new tests. It would be great though if you could test a larger number of scenarios:
- runtime older than proxy or shim
- runtime older than proxy and shim
- runtime newer than proxy or shim
- runtime newer than proxy and shim
- etc
I think the easiest way to add in a table-based set of semi-exhaustive tests would be to add in that strict option to allow you to test for error
in checkVersionConsistencyInComponents()
.
cli/kata-check.go
Outdated
} | ||
|
||
if proxyInfo.Version.Version != "" { | ||
if !versionCompare(proxyInfo.Version, runtimeVersion) || !versionCompare(shimInfo.Version, runtimeVersion) { |
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.
Add a condition comparing the shim and proxy versions here?
cli/kata-env.go
Outdated
@@ -34,6 +34,12 @@ type MetaInfo struct { | |||
Version string | |||
} | |||
|
|||
type VersionInfo struct { | |||
Version string |
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.
Ya, same question, what is the Version
here? Shouldnt this be Major
, Minor
and Patch
instead?
Are we not comparing the "Patch" version at all?
Hi guys @jodh-intel @amshinde |
Thanks @Pennyzct ! |
6605630
to
d04ac42
Compare
Hi guys |
b668117
to
16ee745
Compare
/test |
/test |
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.
Thanks @Pennyzct - very nice.
lgtm
/test |
Hi~ guys |
restarting ubuntu-ci |
/test-fc |
ARM CI failed on:
It should be related to the recently merged PR #2418. @devimc Would you like to refine this comment by yourself or I just do the refinement here? ;). |
Rerunning ARM CI now that #2435 is merged. |
ARM CI is still failing @Pennyzct |
Hi~ @amshinde |
We import new struct VersionInfo for better organizing version info of kata components, in order to follow Semantic Versioning Specification. Fixes: kata-containers#2375 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
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: kata-containers#2375 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
we need to refine unit tests due to previous two commits and add new test for new func checkVersionConsistencyInComponents. Fixes: kata-containers#2375 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
16ee745
to
1c1e7cc
Compare
re-based. ;) |
/test |
Hi~ guys. Got all green here~~~~~. ;). |
Which feature do you think can be improved?
We may need multiple kata components to launch one kata container. The longest legacy one could have
kata-shim
,kata-proxy
,kata-runtime
, andkata-agent.
For users, especially for developers, we often encounter confused runtime error due to each kata component at different version.
E.g. Laterly, I've encountered following error in launching kata container with firecracker, and it's because of stale version of
kata-shim
, which is lower thanv1.9.0
.How can it be improved?
So, here, I want to introduce version consistency check in
kata-runtime kata-check
.If we have kata components at different version, it should issue a warning, like this:
Otherwise, it should output like this:
Updates:
Following upstream comments to use
--strict/-s
option to perform version consistency check: