From 202a877d36b1dc4042f5d164ab2394ea9815940b Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Tue, 26 May 2020 00:39:55 -0700 Subject: [PATCH] utils: Fix case version check for stable releases For stable versions the format used `x.y.z`. kata-env was failing trying to make a new release from 1.11.0-rc to 1.11.0 This fix kata-env for releases 1.11+ where this regression was introduced. Fixes: kata-containers/runtime#2674 Signed-off-by: Jose Carlos Venegas Munoz Signed-off-by: Peng Tao --- src/runtime/cli/kata-check_test.go | 7 +++++++ src/runtime/cli/utils.go | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/runtime/cli/kata-check_test.go b/src/runtime/cli/kata-check_test.go index c45460f01d..c1e986ccc3 100644 --- a/src/runtime/cli/kata-check_test.go +++ b/src/runtime/cli/kata-check_test.go @@ -959,6 +959,13 @@ func TestCheckVersionConsistencyInComponents(t *testing.T) { "", "0.2.0-rc0", }, + { + false, + false, + "kata-shim version 0.2.0-xxxxxxxxxxxxx", + "", + "0.2.0", + }, } origVersion := version diff --git a/src/runtime/cli/utils.go b/src/runtime/cli/utils.go index 4a532204ee..4d982e8cb6 100644 --- a/src/runtime/cli/utils.go +++ b/src/runtime/cli/utils.go @@ -161,7 +161,13 @@ func constructVersionInfo(version string) VersionInfo { return unknownVersionInfo } - pres := strings.Split(sv.Pre[0].VersionStr, "-") + var pres string + if len(sv.Pre) > 0 { + presSplit := strings.Split(sv.Pre[0].VersionStr, "-") + if len(presSplit) > 2 { + pres = presSplit[1] + } + } // version contains Commit info. if len(pres) > 1 { @@ -170,7 +176,7 @@ func constructVersionInfo(version string) VersionInfo { Major: sv.Major, Minor: sv.Minor, Patch: sv.Patch, - Commit: pres[1], + Commit: pres, } }