diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ef6e7a..c4434c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,11 +41,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - distro: - - centos8 - - ubuntu2004 - - ubuntu1804 - - debian10 + include: + - name: Centos 7 + distro: quay.io/jseguillon/kubevirt-images:centos-7-x86_64-genericcloud-2009 + # - ubuntu2004 + # - ubuntu1804 + # - debian10 + + env: + KUBERNETES_VERSION: v1.20.0 + PYTHON_BASE_IMAGE: python:3.9 steps: - name: Check out the codebase. @@ -53,17 +58,315 @@ jobs: with: path: 'geerlingguy.nginx' - - name: Set up Python 3. - uses: actions/setup-python@v2 + - name: Update packages index + run: | + sudo apt-get update + + - name: Install docker + uses: nick-invision/retry@v2 with: - python-version: '3.x' + timeout_minutes: 5 + max_attempts: 3 + command: | + . /etc/os-release + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + sudo apt-get update + sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce - - name: Install test dependencies. - run: pip3 install ansible molecule[docker] docker + - name: Install kubectl + uses: nick-invision/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 3 + command: | + curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/linux/amd64/kubectl; chmod +x ./kubectl + sudo install kubectl /usr/local/bin + + - name: Install kind + uses: nick-invision/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 3 + command: | + curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.9.0/kind-$(uname)-amd64" && chmod +x ./kind + sudo install kind /usr/local/bin + + - name: Create single node Cluster + run: | + cat < Dockerfile + ARG PYTHON_BASE_IMAGE + + FROM \${PYTHON_BASE_IMAGE} + ARG KUBERNETES_VERSION + + RUN python3 -m pip install ansible molecule molecule-kubevirt && \ + ansible-galaxy collection install community.crypto && \ + ansible-galaxy collection install git+https://github.com/ansible-collections/community.kubernetes.git + + RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/\${KUBERNETES_VERSION}/bin/linux/amd64/kubectl && \ + chmod +x kubectl && mv kubectl /usr/bin + + COPY molecule /molecule + COPY . /molecule/default/roles/geerlingguy.nginx + EOF + + docker build --build-arg PYTHON_BASE_IMAGE="${PYTHON_BASE_IMAGE}" --build-arg KUBERNETES_VERSION="${KUBERNETES_VERSION}" . -t molecule_kubevirt_runner:latest + # TODO : kind load is slow : set a private registry, as described here https://kind.sigs.k8s.io/docs/user/local-registry/ + sudo kind load docker-image molecule_kubevirt_runner:latest - - name: Run Molecule tests. - run: molecule test + - name: Push molecule test image to Kind + uses: nick-invision/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 3 + command: | + sudo kind load docker-image molecule_kubevirt_runner:latest + + - name: Install kail + uses: nick-invision/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 3 + command: | + curl -SL https://github.com/boz/kail/releases/download/v0.15.0/kail_0.15.0_linux_amd64.tar.gz -o kail.tar.gz + tar xf kail.tar.gz + sudo install kail /usr/local/bin + + - name: Wait and get kubevirt status + run: | + # wait network is ready + sudo kubectl wait --for=condition=ready pods --namespace=kubevirt -l kubevirt.io=virt-operator + sudo kubectl wait --for=condition=ready pods --namespace=kubevirt -l kubevirt.io=virt-api || true + sudo kubectl wait --for=condition=ready pods --namespace=kubevirt -l kubevirt.io=virt-controller || true + sudo kubectl wait --for=condition=ready pods --namespace=kubevirt -l kubevirt.io=virt-handler || true + sudo kubectl get nodes -o wide + sudo kubectl get pods -A + + - name: Prepare Job + run: | + # Service Account for Job + cat <&1 > /tmp/kail.log || true & + # Infinite script waits for new VMs up and fetch logs from console + ( + while true; do + until sudo kubectl wait --for=condition=Ready pod -l kubevirt.io=virt-launcher --namespace default; + do echo "Still Waiting Pod to start..."; sleep 5; + done + + LOGFILE="virtcl-console-$(date '+%Y-%m-%d-%H-%M-%S').log" + echo "Starting virtctl console" >> /tmp/${LOGFILE} + sudo script -e -c "virtctl console instance" >> /tmp/${LOGFILE} + done + ) & + # Event router reports any event as log, a great help for troubleshooting since Kind exports all running Pods logs + sudo kubectl create -f https://raw.githubusercontent.com/heptiolabs/eventrouter/master/yaml/eventrouter.yaml + + - name: Launch test + uses: nick-invision/retry@v2 + with: + timeout_minutes: 25 + max_attempts: 3 + on_retry_command: | + sudo kubectl delete pods --all || true + sudo kubectl delete configmaps --all || true + sudo kubectl delete job --all || true + command: | + # Configmap will be waitinig untill it is deleted, telling one Pod ended the Job + sudo kubectl create configmap molecule-job-running --from-literal status=Started + # Create Job + cat < ${LOG_DIR}/dmesg.txt || true + sudo kind export logs ${LOG_DIR} || true + sudo journalctl | cat > ${LOG_DIR}/journalctl.txt || true + sudo chown -R $USER:$USER ${LOG_DIR} || true env: - PY_COLORS: '1' - ANSIBLE_FORCE_COLOR: '1' - MOLECULE_DISTRO: ${{ matrix.distro }} + LOG_DIR: /tmp/molecule-kubevirt/logs + + - name: Upload logs + if: always() + uses: actions/upload-artifact@v2 + with: + name: molecule-kubevirt-${{ matrix.name }}-${{ github.run_id }} + path: /tmp/molecule-kubevirt/logs diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index ee65197..54bc65f 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,6 +1,7 @@ --- - name: Converge hosts: all + become: yes vars: nginx_use_ppa: true diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 7490710..fa60cc0 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -2,15 +2,11 @@ dependency: name: galaxy driver: - name: docker + name: kubevirt platforms: - name: instance - image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" - command: ${MOLECULE_DOCKER_COMMAND:-""} - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: true - pre_build_image: true + image: "${MOLECULE_DISTRO:-quay.io/jseguillon/kubevirt-images:centos-7-x86_64-genericcloud-2009}" + provisioner: name: ansible playbooks: