diff --git a/tests/gha-run-k8s-common.sh b/tests/gha-run-k8s-common.sh index 44b02f32ea..4f7de35e14 100644 --- a/tests/gha-run-k8s-common.sh +++ b/tests/gha-run-k8s-common.sh @@ -107,6 +107,11 @@ function delete_cluster() { --yes } +function delete_cluster_kcli() { + CLUSTER_NAME="${CLUSTER_NAME:-kata-k8s}" + kcli delete -y kube "$CLUSTER_NAME" +} + function get_nodes_and_pods_info() { kubectl debug $(kubectl get nodes -o name) -it --image=quay.io/kata-containers/kata-debug:latest || true kubectl get pods -o name | grep node-debugger | xargs kubectl delete || true @@ -165,6 +170,44 @@ function deploy_k3s() { cp /etc/rancher/k3s/k3s.yaml ~/.kube/config } +function create_cluster_kcli() { + CLUSTER_NAME="${CLUSTER_NAME:-kata-k8s}" + + delete_cluster_kcli || true + + kcli create kube "${KUBE_TYPE:-generic}" \ + -P domain="kata.com" \ + -P pool="${LIBVIRT_POOL:-default}" \ + -P ctlplanes="${CLUSTER_CONTROL_NODES:-1}" \ + -P workers="${CLUSTER_WORKERS:-1}" \ + -P network="${LIBVIRT_NETWORK:-default}" \ + -P image="${CLUSTER_IMAGE:-ubuntu2004}" \ + -P sdn=flannel \ + -P nfs=false \ + -P disk_size="${CLUSTER_DISK_SIZE:-20}" \ + "${CLUSTER_NAME}" + + export KUBECONFIG="$HOME/.kcli/clusters/$CLUSTER_NAME/auth/kubeconfig" + + local cmd="kubectl get nodes | grep '.*worker.*\'" + echo "Wait at least one worker be Ready" + if ! waitForProcess "330" "30" "$cmd"; then + echo "ERROR: worker nodes not ready." + kubectl get nodes + return 1 + fi + + # Ensure that system pods are running or completed. + cmd="[ \$(kubectl get pods -A --no-headers | grep -v 'Running\|Completed' | wc -l) -eq 0 ]" + echo "Wait system pods be running or completed" + if ! waitForProcess "90" "30" "$cmd"; then + echo "ERROR: not all pods are Running or Completed." + kubectl get pods -A + kubectl get pods -A + return 1 + fi +} + function deploy_rke2() { curl -sfL https://get.rke2.io | sudo sh - diff --git a/tests/integration/kubernetes/gha-run.sh b/tests/integration/kubernetes/gha-run.sh index bfde44342c..a53b0fcf62 100755 --- a/tests/integration/kubernetes/gha-run.sh +++ b/tests/integration/kubernetes/gha-run.sh @@ -214,6 +214,7 @@ function main() { install-azure-cli) install_azure_cli ;; login-azure) login_azure ;; create-cluster) create_cluster ;; + create-cluster-kcli) create_cluster_kcli ;; configure-snapshotter) configure_snapshotter ;; setup-crio) setup_crio ;; deploy-k8s) deploy_k8s ;; @@ -231,6 +232,7 @@ function main() { cleanup-tdx) cleanup "tdx" ;; cleanup-garm) cleanup "garm" ;; delete-cluster) cleanup "aks" ;; + delete-cluster-kcli) delete_cluster_kcli ;; *) >&2 echo "Invalid argument"; exit 2 ;; esac }