Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

kata-check: Add version consistency check #2376

Merged
merged 3 commits into from
Feb 19, 2020

Conversation

Pennyzct
Copy link
Contributor

@Pennyzct Pennyzct commented Dec 25, 2019

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, and kata-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 than v1.9.0.

$ docker run --runtime kata-runtime busybox
docker: Error response from daemon: cannot start a stopped process: unknown.
ERRO[0002] error waiting for container: context canceled

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:

$ kata-runtime kata-check
System is capable of running Kata Containers
System can currently create Kata Containers
Warning: there exists version inconsistency in kata components. kata-proxy: v1.10, kata-shim: v1.7, kata-runtime: v1.10

Otherwise, it should output like this:

$ kata-runtime kata-check
INFO[0000] VSOCK supported, configure to not use proxy
System is capable of running Kata Containers
System can currently create Kata Containers
Version consistency of Kata Containers is verified

Updates:
Following upstream comments to use --strict/-s option to perform version consistency check:

$ kata-runtime kata-check --strict
INFO[0000] VSOCK supported, configure to not use proxy
System is capable of running Kata Containers
System can currently create Kata Containers
Version consistency of Kata Containers is verified
$ kata-runtime kata-check --strict         
INFO[0000] VSOCK supported, configure to not use proxy
System is capable of running Kata Containers
System can currently create Kata Containers
ERRO[0000] there exists version inconsistency in Kata Components. kata-shim: v1.8.1, kata-runtime: v1.10.0
  arch=arm64 name=kata-runtime pid=35284 source=runtime
there exists version inconsistency in Kata Components. kata-shim: v1.8.1, kata-runtime: v1.10.0

@Pennyzct
Copy link
Contributor Author

Hi @lifupan
I finally detected the root cause of that error....
stale kata-shim...🤬🤮

@Pennyzct Pennyzct force-pushed the version_compatibility branch from 331eb90 to 6605630 Compare December 25, 2019 07:34
@Pennyzct
Copy link
Contributor Author

/test

@codecov
Copy link

codecov bot commented Dec 25, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@0c3b2c0). Click here to learn what that means.
The diff coverage is 87.05%.

@@            Coverage Diff            @@
##             master    #2376   +/-   ##
=========================================
  Coverage          ?   50.79%           
=========================================
  Files             ?      114           
  Lines             ?    16381           
  Branches          ?        0           
=========================================
  Hits              ?     8321           
  Misses            ?     7035           
  Partials          ?     1025

Copy link
Contributor

@jodh-intel jodh-intel left a 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...

@@ -454,3 +459,45 @@ func genericCheckKVMExtensions(extensions map[string]kvmExtension) (map[string]i

return results, nil
}

// func checkVersionConsistencyInComponents checks version consistency in kata components.
Copy link
Contributor

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).

return errors.New("cannot determine runtime config")
}

proxyInfo, _ := getProxyInfo(config)
Copy link
Contributor

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()).

@@ -357,6 +358,10 @@ var kataCheckCLICommand = cli.Command{
fmt.Println(successMessageCreate)
}

if err := checkVersionConsistencyInComponents(context); err != nil {
Copy link
Contributor

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)

}

var runtimeVersion VersionInfo
versions := strings.Split(version, ".")
Copy link
Contributor

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).


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,
Copy link
Contributor

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 run kata-runtime kata-check --strict and one of these checks fails, it returns 1 rather than 0. That could be more useful for scripts, etc which shouldn't have to parse stderr. 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
Copy link
Contributor

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.

Copy link
Member

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?

@@ -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"}
Copy link
Contributor

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().

}

if proxyInfo.Version.Version != "" {
if !versionCompare(proxyInfo.Version, runtimeVersion) || !versionCompare(shimInfo.Version, runtimeVersion) {
Copy link
Member

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
Copy link
Member

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?

@Pennyzct
Copy link
Contributor Author

Pennyzct commented Jan 6, 2020

Hi guys @jodh-intel @amshinde
Thanks for all your detailed comments, really appreciated. ;) 😚
I'm with the @jodh-intel's suggestion to add a --strict option to do the binary-check, instead of just outputting the warning.
And I'll use semver package to replace the original design. ;).
Update ASAP...

@jodh-intel
Copy link
Contributor

Thanks @Pennyzct !

@Pennyzct Pennyzct added the wip Work in Progress (PR incomplete - needs more work or rework) label Jan 8, 2020
@Pennyzct Pennyzct force-pushed the version_compatibility branch from 6605630 to d04ac42 Compare January 8, 2020 09:08
@Pennyzct
Copy link
Contributor Author

Pennyzct commented Jan 8, 2020

Hi guys
@jodh-intel @amshinde
I've updated my code, Plz take a review~~~~;)

@Pennyzct Pennyzct removed the wip Work in Progress (PR incomplete - needs more work or rework) label Jan 8, 2020
@Pennyzct Pennyzct force-pushed the version_compatibility branch 3 times, most recently from b668117 to 16ee745 Compare January 9, 2020 03:21
@Pennyzct
Copy link
Contributor Author

Pennyzct commented Jan 9, 2020

/test

@WeiZhang555
Copy link
Member

/test

Copy link
Contributor

@jodh-intel jodh-intel left a 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

@jodh-intel
Copy link
Contributor

/test

@Pennyzct
Copy link
Contributor Author

Hi~ guys
FC failed as usual, and should be irrelevant with this patch.
ARM CI failed because of PR kata-containers/tests/#2236.
And I need one reviewer here~~~ any one cares to take a look?? @kata-containers/runtime

@devimc
Copy link

devimc commented Jan 27, 2020

restarting ubuntu-ci

@Pennyzct
Copy link
Contributor Author

/test-fc

@Pennyzct
Copy link
Contributor Author

Pennyzct commented Jan 30, 2020

ARM CI failed on:

10:42:56 pkg/rootless/rootless.go:57:2: comment on exported var `IsRootless` should be of the form `IsRootless ...` (golint)
10:42:56 	//The function is declared this way for mocking in unit tests
10:42:56 	^
10:43:01 Build step 'Execute shell' marked build as failure

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? ;).

@amshinde
Copy link
Member

amshinde commented Feb 7, 2020

Rerunning ARM CI now that #2435 is merged.

@amshinde
Copy link
Member

amshinde commented Feb 7, 2020

ARM CI is still failing @Pennyzct

@Pennyzct
Copy link
Contributor Author

Hi~ @amshinde
Sorry for the ARM CI failure, and I'm already raised an PR kata-containers/test#2294 to fix them.
But it should be irrelevant with this PR. ;).

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>
@Pennyzct Pennyzct force-pushed the version_compatibility branch from 16ee745 to 1c1e7cc Compare February 17, 2020 02:14
@Pennyzct
Copy link
Contributor Author

re-based. ;)
/test

@Pennyzct
Copy link
Contributor Author

/test

@Pennyzct
Copy link
Contributor Author

Hi~ guys. Got all green here~~~~~. ;).

@amshinde amshinde merged commit 44b0967 into kata-containers:master Feb 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants