From 1200460f26646493f42be0a83775710c18dfe7af Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Wed, 12 Feb 2020 12:07:19 -0600 Subject: [PATCH] Issue #10: Attempt setting up a KinD cluster in CI workflow.g --- .github/workflows/ansible-test.yml | 40 ++++++++++++++++++++++++++++-- README.md | 9 +++++++ codecov.yml | 1 + galaxy.yml | 1 + molecule/default/molecule.yml | 34 +++++++++++++++++++++++++ molecule/default/playbook.yml | 23 +++++++++++++++++ 6 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/playbook.yml diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index e0872b94..9761fe48 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -1,6 +1,6 @@ +--- name: CI -on: - push: +'on': pull_request: schedule: - cron: '0 6 * * *' @@ -53,3 +53,39 @@ jobs: - name: Upload coverage data run: tests/coverage.sh + + molecule: + runs-on: ubuntu-latest + strategy: + matrix: + python_version: ['3.7'] + steps: + - name: Check out code + uses: actions/checkout@v1 + with: + path: ansible_collections/community/kubernetes + + - name: Set up KinD cluster + uses: engineerd/setup-kind@v0.3.0 + + - name: Set up Python ${{ matrix.python_version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python_version }} + + - name: Install molecule and openshift dependencies + run: pip install molecule openshift + + - name: Install ansible-base + run: pip install git+https://github.com/ansible-collection-migration/ansible-base.git --disable-pip-version-check + + - name: Create default collection path symlink + run: | + mkdir -p /home/runner/.ansible + ln -s /home/runner/work/kubernetes /home/runner/.ansible/collections + + - name: Copy kubernetes integration test role into roles directory. + run: cp -R tests/integration/targets/kubernetes roles/ + + - name: Run molecule default test scenario + run: molecule --debug test diff --git a/README.md b/README.md index ecbf5577..2ad55d1e 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ For documentation on how to use individual modules and other content included in If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured [`COLLECTIONS_PATHS`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and work on it there. +### Testing with `ansible-test` + The `tests` directory contains configuration for running sanity and integration tests using [`ansible-test`](https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html). You can run the collection's test suites with the commands: @@ -112,6 +114,13 @@ You can run the collection's test suites with the commands: ansible-test sanity --docker -v --color ansible-test integration --docker -v --color +### Testing with `molecule` + +There are also integration tests in the `molecule` directory which are meant to be run against a local Kubernetes cluster, e.g. using [KinD](https://kind.sigs.k8s.io) or [Minikube](https://minikube.sigs.k8s.io). To run the tests, set up a local cluster, then run Molecule: + + kind create cluster + molecule test + ## Publishing New Versions The current process for publishing new versions of the Kubernetes Collection is manual, and requires a user who has access to the `community.kubernetes` namespace on Ansible Galaxy to publish the build artifact. diff --git a/codecov.yml b/codecov.yml index f0f6358e..33c8f6ee 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,4 @@ +--- coverage: precision: 2 round: down diff --git a/galaxy.yml b/galaxy.yml index 069d5af1..5c57a6e3 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,3 +1,4 @@ +--- authors: - chouseknecht (https://github.com/chouseknecht) - geerlingguy (https://www.jeffgeerling.com/) diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 00000000..be33836a --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,34 @@ +--- +driver: + name: delegated + options: + managed: false + login_cmd_template: 'docker exec -ti {instance} bash' + ansible_connection_options: + ansible_connection: docker +lint: + name: yamllint + options: + config-data: + line-length: + max: 160 +platforms: + - name: instance-kind +provisioner: + name: ansible + log: true + lint: {} + inventory: + host_vars: + localhost: + ansible_python_interpreter: '{{ ansible_playbook_python }}' + env: + ANSIBLE_ROLES_PATH: ${ANSIBLE_ROLES_PATH}:../../tests/integration/targets +scenario: + name: default + test_sequence: + # - lint + - syntax + - converge + - idempotence + - verify diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 00000000..3b628765 --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +1,23 @@ +--- +- name: Converge + hosts: localhost + connection: local + gather_facts: false + + collections: + - community.kubernetes + + tasks: + - name: Testing. + k8s_info: + namespace: kube-system + kind: Pod + register: pod_list + + - name: Testing listing. + debug: + msg: "{{ pod_list.resources | count }}" + + - name: Include Kubernetes integration testing role. + include_role: + name: kubernetes