From b41fa6d9467c996dc605c7fde3b9828bcc2fdafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Tue, 19 Sep 2023 19:46:10 +0200 Subject: [PATCH] ci: k8s: Add a method to install CRI-O MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is based on official CRI-O documentations[0] and right now we're making this specific to Ubuntu as that's what we have as runners. We may want to expand this in the future, but we're good for now. [0]: https://github.com/cri-o/cri-o/blob/main/install.md#apt-based-operating-systems Signed-off-by: Fabiano FidĂȘncio (cherry picked from commit d7105cf7a498bdac1b057007e4977f8cf0e14f48) --- tests/gha-run-k8s-common.sh | 47 +++++++++++++++++++++++++ tests/integration/kubernetes/gha-run.sh | 1 + 2 files changed, 48 insertions(+) diff --git a/tests/gha-run-k8s-common.sh b/tests/gha-run-k8s-common.sh index 6c6622b2b6..f706db5ebf 100644 --- a/tests/gha-run-k8s-common.sh +++ b/tests/gha-run-k8s-common.sh @@ -181,6 +181,53 @@ function deploy_rke2() { sudo chown ${USER}:${USER} ~/.kube/config } +function _get_k0s_kubernetes_version_for_crio() { + # k0s version will look like: + # v1.27.5+k0s.0 + # + # The CRI-O repo for such version of Kubernetes expects something like: + # 1.27 + k0s_version=$(curl -sSLf "https://docs.k0sproject.io/stable.txt") + + # Remove everything after the second '.' + crio_version=${k0s_version%\.*+*} + # Remove the 'v' + crio_version=${crio_version#v} + + echo ${crio_version} +} + +function _get_os_for_crio() { + source /etc/os-release + + if [ "${NAME}" != "Ubuntu" ]; then + echo "Only Ubuntu is supported for now" + exit 2 + fi + + echo "x${NAME}_${VERSION_ID}" +} + +function setup_crio() { + # Get the CRI-O version to be installed depending on the version of the + # "k8s distro" that we are using + case ${KUBERNETES} in + k0s) crio_version=$(_get_k0s_kubernetes_version_for_crio) ;; + *) >&2 echo "${KUBERNETES} flavour is not supported with CRI-O"; exit 2 ;; + + esac + + os=$(_get_os_for_crio) + + echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/${os}/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list + echo "deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/${crio_version}/${os}/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:${crio_version}.list + curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:${crio_version}/${os}/Release.key | sudo apt-key add - + curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/${os}/Release.key | sudo apt-key add - + sudo apt update + sudo apt install cri-o cri-o-runc + sudo systemctl enable --now crio +} + function deploy_k8s() { echo "::group::Deploying ${KUBERNETES}" diff --git a/tests/integration/kubernetes/gha-run.sh b/tests/integration/kubernetes/gha-run.sh index fa754ada87..360628a6b9 100755 --- a/tests/integration/kubernetes/gha-run.sh +++ b/tests/integration/kubernetes/gha-run.sh @@ -203,6 +203,7 @@ function main() { login-azure) login_azure ;; create-cluster) create_cluster ;; configure-snapshotter) configure_snapshotter ;; + setup-crio) setup_crio ;; deploy-k8s) deploy_k8s ;; install-bats) install_bats ;; install-kubectl) install_kubectl ;;