diff --git a/kubevirtci b/kubevirtci index b9199bf7c..f00cb8835 100755 --- a/kubevirtci +++ b/kubevirtci @@ -11,6 +11,9 @@ export KUBEVIRT_NUM_NODES=${KUBEVIRT_NUM_NODES:-1} export KUBEVIRT_MEMORY_SIZE=${KUBEVIRT_MEMORY_SIZE:-15360M} export KUBEVIRT_DEPLOY_CDI="true" export KUBEVIRT_STORAGE="rook-ceph-default" +export METALLB_VERSION="v0.12.1" +export CAPK_RELEASE_VERSION="v0.1.0-rc.0" +export CLUSTERCTL_VERSION="v1.0.0" _default_bin_path=./hack/tools/bin _default_tmp_path=./hack/tools/bin/tmp @@ -36,9 +39,10 @@ function kubevirtci::usage() { Commands: up Start a cluster with kubevirt, cert-manager and capi - sync Build and deploy current capk + sync Build and deploy current capk from source (must be executed from within capk source tree) down Destroy the cluster refresh Build current capk and trigger creating new capk pods + clean-cache Removes all files cached by kubevirtci kubeconfig Return the kubeconfig of the cluster kubectl Interact with the cluster @@ -46,6 +50,10 @@ function kubevirtci::usage() { virtctl Run virtctl commands against the cluster clusterctl Run clusterctl commands against the cluster + install-capk Installs capk from published release manifests + install-metallb Installs metallb into the infra cluster + curl-lb [lb namespace] Curls lb service within infra cluster + ssh-infra SSH into one of the infra nodes (like node01) ssh-tenant [vmi namespace] SSH into one of the guest nodes create-cluster Create new kubernetes tenant cluster @@ -62,11 +70,11 @@ function kubevirtci::kubeconfig() { function kubevirtci::fetch_kubevirtci() { [[ -d cluster-up ]] || git clone https://github.com/kubevirt/kubevirtci.git cluster-up - (cd cluster-up && git checkout ${KUBEVIRTCI_TAG} > /dev/null) + (cd cluster-up && git checkout main > /dev/null 2>&1 && git pull > /dev/null && git checkout ${KUBEVIRTCI_TAG} > /dev/null 2>&1) mkdir -p ./hack/tools/bin/ if [ ! -f "${_default_clusterctl_path}" ]; then - echo >&2 "Downloading clusterctl ..." - curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.0/clusterctl-linux-amd64 -o ${_default_clusterctl_path} + echo >&2 "Downloading clusterctl version ${CLUSTERCTL_VERSION}..." + curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTERCTL_VERSION}/clusterctl-linux-amd64 -o ${_default_clusterctl_path} chmod u+x ${_default_clusterctl_path} fi if [ ! -f "${_default_virtctl_path}" ]; then @@ -151,8 +159,15 @@ function kubevirtci::create_cluster() { export NODE_VM_IMAGE_TEMPLATE=quay.io/capk/ubuntu-container-disk:20.04 export IMAGE_REPO=k8s.gcr.io export CRI_PATH="/var/run/containerd/containerd.sock" + template=templates/cluster-template.yaml + + if [ ! -f $template ]; then + template="https://github.com/kubernetes-sigs/cluster-api-provider-kubevirt/blob/main/templates/cluster-template.yaml" + fi - $CLUSTERCTL_PATH generate cluster ${TENANT_CLUSTER_NAME} --target-namespace ${TENANT_CLUSTER_NAMESPACE} --kubernetes-version v1.21.0 --control-plane-machine-count=1 --worker-machine-count=1 --from templates/cluster-template.yaml | ${_kubectl} apply -f - + echo "Using cluster template $template" + + $CLUSTERCTL_PATH generate cluster ${TENANT_CLUSTER_NAME} --target-namespace ${TENANT_CLUSTER_NAMESPACE} --kubernetes-version v1.21.0 --control-plane-machine-count=1 --worker-machine-count=1 --from $template | ${_kubectl} apply -f - } function kubevirtci::create_external_cluster() { @@ -165,6 +180,105 @@ function kubevirtci::create_external_cluster() { $CLUSTERCTL_PATH generate cluster ${TENANT_CLUSTER_NAME} --target-namespace ${TENANT_CLUSTER_NAMESPACE} --kubernetes-version v1.21.0 --control-plane-machine-count=1 --worker-machine-count=1 --from templates/cluster-template-ext-infra.yaml | ${_kubectl} apply -f - } +function kubevirtci::create_tenant_namespace { + ${_kubectl} apply -f - < $metal_config +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: metallb-system + name: config +data: + config: | + address-pools: + - name: default + protocol: layer2 + addresses: + - 192.168.66.201-192.168.66.250 +EOF + + ${_kubectl} apply -f ${metal_config} + + rm $metal_config + echo "metallb installed!" +} + +function kubevirtci::curl_lb { + mkdir -p ${_default_tmp_path} + job_yaml=${_default_tmp_path}/curl-test-pod.yaml + if [ -f ${job_yaml} ]; then + ${_kubectl} delete -f ${job_yaml} --ignore-not-found + fi + + lb_name=$1 + lb_namespace=${2:-$TENANT_CLUSTER_NAMESPACE} + + $_kubectl get service $lb_name -n $lb_namespace + + lb_ip=$($_kubectl get service $lb_name -n $lb_namespace -o yaml | grep "ip:" | awk '{print $3}') + lb_port=$($_kubectl get service $lb_name -n $lb_namespace -o yaml | grep "port:" | awk '{print $2}') + + + cat << EOF > $job_yaml +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: curl-test-job + namespace: ${lb_namespace} +spec: + template: + spec: + containers: + - name: fedora + image: fedora:35 + command: + - curl + - "${lb_ip}:${lb_port}" + restartPolicy: Never + backoffLimit: 4 +EOF + + ${_kubectl} create -f $job_yaml + echo "-----------Waiting for curl job to complete" + ${_kubectl} wait job curl-test-job -n default --for condition=Complete --timeout=5m + + pod_name=$($_kubectl get pods --selector=job-name=curl-test-job --output=jsonpath='{.items[*].metadata.name}') + + echo "-----------CURL LOG FOR POD $pod_name" + $_kubectl logs -n default $pod_name 2>/dev/null + + ${_kubectl} delete -f ${job_yaml} --ignore-not-found > /dev/null 2>&1 +} + + function kubevirtci::kubectl_tenant { vms_list=$(${_kubectl} get vm -n ${TENANT_CLUSTER_NAMESPACE} --no-headers -o custom-columns=":metadata.name") for vm in $vms_list @@ -204,6 +318,15 @@ case ${_action} in kubevirtci::build kubevirtci::install ;; +"install-capk") + kubevirtci::install_capk_release + ;; +"install-metallb") + kubevirtci::install_metallb + ;; +"curl-lb") + kubevirtci::curl_lb "$@" + ;; "kubeconfig") kubevirtci::kubeconfig ;; @@ -226,15 +349,23 @@ case ${_action} in $CLUSTERCTL_PATH "$@" ;; "create-cluster") + kubevirtci::create_tenant_namespace kubevirtci::create_cluster ;; "create-external-cluster") + kubevirtci::create_tenant_namespace kubevirtci::generate_kubeconfig kubevirtci::create_external_cluster ;; "destroy-cluster") kubevirtci::destroy_cluster ;; + +"clean-cache") + rm ${_default_clusterctl_path} + rm ${_default_virtctl_path} + rm -rf ${_default_tmp_path} + ;; "help") kubevirtci::usage ;;