Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 136 additions & 5 deletions kubevirtci
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,16 +39,21 @@ 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 <kubectl options> Interact with the cluster
kubectl-tenant <kubectl options> Interact with the tenant cluster
virtctl <virtctl options> Run virtctl commands against the cluster
clusterctl <clusterctl options> 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 name> [lb namespace] Curls lb service within infra cluster

ssh-infra <node name> SSH into one of the infra nodes (like node01)
ssh-tenant <vmi> [vmi namespace] SSH into one of the guest nodes
create-cluster Create new kubernetes tenant cluster
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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 - <<EOF
---
apiVersion: v1
kind: Namespace
metadata:
name: ${TENANT_CLUSTER_NAMESPACE}
EOF
}

function kubevirtci::install_capk_release {
${_kubectl} apply -f https://github.com/kubernetes-sigs/cluster-api-provider-kubevirt/releases/download/${CAPK_RELEASE_VERSION}/infrastructure-components.yaml

${_kubectl} wait -n capk-system --for=condition=Available=true deployment/capk-controller-manager --timeout=10m

echo "capk release $CAPK_RELEASE_VERSION installed!"
}

function kubevirtci::install_metallb {
${_kubectl} apply -f https://raw.githubusercontent.com/metallb/metallb/${METALLB_VERSION}/manifests/namespace.yaml
${_kubectl} apply -f https://raw.githubusercontent.com/metallb/metallb/${METALLB_VERSION}/manifests/metallb.yaml

echo "waiting for metallb to come online"
${_kubectl} -n metallb-system wait deployment controller --for condition=Available --timeout=5m

mkdir -p ${_default_tmp_path}
local metal_config=${_default_tmp_path}/metallb-config.yaml

cat << EOF > $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
Expand Down Expand Up @@ -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
;;
Expand All @@ -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
;;
Expand Down