From 1625a5ce484d1c4eb8a20698d40636ee2976ee0e Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 6 Nov 2023 12:37:43 +0000 Subject: [PATCH 1/5] utils: kata-manager: Improve version check Update `github_get_latest_release()` to use `sort -V` rather than sub-sorting on the major, minor and patch level version number elements. The new approach is safer and more accurate. Signed-off-by: James O. D. Hunt --- utils/kata-manager.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index a70df88f18..34e596aa02 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -109,7 +109,7 @@ github_get_latest_release() local latest latest=$(curl -sL "$url" |\ jq -r '.[].tag_name | select(contains("-") | not)' |\ - sort -t "." -k1,1n -k2,2n -k3,3n |\ + sort -t '.' -V |\ tail -1 || true) [ -z "$latest" ] && die "Cannot determine latest release from $url" From 436d7d127558e4210421ccd1cd12cfc2aa037b81 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 6 Nov 2023 11:49:42 +0000 Subject: [PATCH 2/5] utils: kata-manager: Improve usage message Update the usage to show that the latest Kata version can also be queried using `kata-ctl`. Signed-off-by: James O. D. Hunt --- utils/kata-manager.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index 34e596aa02..c92e9bc619 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -270,9 +270,11 @@ $warnings Advice: -- You can check the latest version of Kata Containers by running: +- You can check the latest version of Kata Containers by running + one of the following: $ kata-runtime check --only-list-releases + $ kata-ctl check only-list-releases EOF } From 9969f5a94a1f90e813aa03ffb0fead087436c1f9 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 10 Nov 2023 09:18:00 +0000 Subject: [PATCH 3/5] utils: kata-manager: Make test container name more unique Rather than creating a container called `test-kata`, prefix with the script name to make it a bit "more unique" and less likely for users to have an existing container with the test container name. The new test container name is `kata-manager-sh-test-kata`. Signed-off-by: James O. D. Hunt --- utils/kata-manager.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index c92e9bc619..73f3956611 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -765,7 +765,7 @@ test_installation() local image="docker.io/library/busybox:latest" sudo $tool image pull "$image" - local container_name="test-kata" + local container_name="${script_name/./-}-test-kata" # Used to prove that the kernel in the container # is different to the host kernel. From be3044fd01b871888595a2e5637f94f6cc483620 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 6 Nov 2023 11:52:45 +0000 Subject: [PATCH 4/5] utils: kata-manager: Add option to list versions Add a command-line option to list the installed and available versions of Kata and containerd. Fixes: #8355. Signed-off-by: James O. D. Hunt --- utils/kata-manager.sh | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index 73f3956611..201fb86613 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -251,6 +251,7 @@ Options: -f : Force installation (use with care). -h : Show this help statement. -k : Specify Kata Containers version. + -l : List installed and available versions only, then exit (uses network). -o : Only install Kata Containers. -r : Don't cleanup on failure (retain files). -t : Disable self test (don't try to create a container after install). @@ -273,6 +274,7 @@ Advice: - You can check the latest version of Kata Containers by running one of the following: + $ $script_name -l $ kata-runtime check --only-list-releases $ kata-ctl check only-list-releases @@ -878,6 +880,41 @@ validate_containerd_flavour() grep -qE "$flavours_regex" <<< "$flavour" || die "expected flavour to match '$flavours_regex', found '$flavour'" } +list_versions() +{ + local -r not_installed='' + + # The latest available checks will hit the network so inform the + # user what we are doing in case of network delays. + info "Getting version details" + + local installed_kata + installed_kata=$("$kata_shim_v2" --version 2>/dev/null ||\ + echo "$not_installed") + + local installed_containerd + installed_containerd=$(containerd --version 2>/dev/null ||\ + echo "$not_installed") + + local latest_kata + latest_kata=$(github_get_latest_release "$kata_releases_url" || true) + [ -z "$latest_kata" ] && \ + die "cannot determine latest version of $project" + + local latest_containerd + latest_containerd=$(github_get_latest_release "$containerd_releases_url" || true) + [ -z "$latest_containerd" ] && \ + die "cannot determine latest version of $containerd_project" + + info "$kata_project: installed version: $installed_kata" + info "$kata_project: latest version: $latest_kata" + + echo + + info "$containerd_project: installed version: $installed_containerd" + info "$containerd_project: latest version: $latest_containerd" +} + handle_args() { local cleanup="true" @@ -887,13 +924,14 @@ handle_args() local only_run_test="false" local enable_debug="false" local install_docker="false" + local list_versions='false' local opt local kata_version="" local containerd_flavour="lts" - while getopts "c:dDfhk:ortT" opt "$@" + while getopts "c:dDfhk:lortT" opt "$@" do case "$opt" in c) containerd_flavour="$OPTARG" ;; @@ -902,6 +940,7 @@ handle_args() f) force="true" ;; h) usage; exit 0 ;; k) kata_version="$OPTARG" ;; + l) list_versions='true' ;; o) skip_containerd="true" ;; r) cleanup="false" ;; t) disable_test="true" ;; @@ -913,6 +952,8 @@ handle_args() shift $[$OPTIND-1] + [ "$list_versions" = 'true' ] && list_versions && exit 0 + [ -z "$kata_version" ] && kata_version="${1:-}" || true [ -z "$containerd_flavour" ] && containerd_flavour="${2:-}" || true From 0ead018d0ab5b6371e6e670450ade9545c3a87ad Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 6 Nov 2023 12:41:29 +0000 Subject: [PATCH 5/5] utils: kata-manager: Add Docker details to list output Add Docker version details to the output of the list versions CLI option. Signed-off-by: James O. D. Hunt --- utils/kata-manager.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index 201fb86613..78b0f9d5b7 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -27,6 +27,10 @@ readonly kata_releases_url="https://api.github.com/repos/${kata_slug}/releases" readonly containerd_releases_url="https://api.github.com/repos/${containerd_slug}/releases" readonly containerd_io_releases_url="https://raw.githubusercontent.com/containerd/containerd.io/main/content/releases.md" +readonly docker_slug="moby/moby" +readonly docker_project="Docker (moby)" +readonly docker_releases_url="https://api.github.com/repos/${docker_slug}/releases" + # Directory created when unpacking a binary release archive downloaded from # $kata_releases_url. readonly kata_install_dir="${kata_install_dir:-/opt/kata}" @@ -896,6 +900,10 @@ list_versions() installed_containerd=$(containerd --version 2>/dev/null ||\ echo "$not_installed") + local installed_docker + installed_docker=$(docker --version 2>/dev/null ||\ + echo "$not_installed") + local latest_kata latest_kata=$(github_get_latest_release "$kata_releases_url" || true) [ -z "$latest_kata" ] && \ @@ -906,6 +914,11 @@ list_versions() [ -z "$latest_containerd" ] && \ die "cannot determine latest version of $containerd_project" + local latest_docker + latest_docker=$(github_get_latest_release "$docker_releases_url" || true) + [ -z "$latest_docker" ] && \ + die "cannot determine latest version of $docker_project" + info "$kata_project: installed version: $installed_kata" info "$kata_project: latest version: $latest_kata" @@ -913,6 +926,11 @@ list_versions() info "$containerd_project: installed version: $installed_containerd" info "$containerd_project: latest version: $latest_containerd" + + echo + + info "$docker_project: installed version: $installed_docker" + info "$docker_project: latest version: $latest_docker" } handle_args()