mirror of
https://github.com/PyratLabs/ansible-role-k3s.git
synced 2024-11-26 12:27:28 +01:00
Moved HA testing to a new scenario
This commit is contained in:
parent
09fc37e6ec
commit
7e7cf2b97d
@ -8,6 +8,7 @@ services: docker
|
||||
env:
|
||||
global:
|
||||
- ROLE_NAME: k3s
|
||||
- MOLECULE_SCENARIO: default
|
||||
matrix:
|
||||
- MOLECULE_DISTRO: geerlingguy/docker-centos8-ansible:latest
|
||||
- MOLECULE_DISTRO: geerlingguy/docker-centos7-ansible:latest
|
||||
@ -36,7 +37,7 @@ env:
|
||||
|
||||
# Test multiple masters in control plane with PostgreSQL
|
||||
- MOLECULE_DISTRO: geerlingguy/docker-centos8-ansible:latest
|
||||
MOLECULE_PLAYBOOK: playbook-ha-postgres.yml
|
||||
MOLECULE_SCENATIO: highavailability
|
||||
|
||||
install:
|
||||
# Install test dependencies.
|
||||
@ -45,12 +46,12 @@ install:
|
||||
before_script:
|
||||
# Use actual Ansible Galaxy role name for the project directory.
|
||||
- cd ../
|
||||
- mv ansible-role-$ROLE_NAME xanmanning.$ROLE_NAME
|
||||
- cd xanmanning.$ROLE_NAME
|
||||
- mv ansible-role-${ROLE_NAME} xanmanning.${ROLE_NAME}
|
||||
- cd xanmanning.${ROLE_NAME}
|
||||
|
||||
script:
|
||||
# Run tests.
|
||||
- molecule test
|
||||
- molecule test --scenario-name "${MOLECULE_SCENARIO}"
|
||||
|
||||
notifications:
|
||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||
|
@ -34,14 +34,6 @@ platforms:
|
||||
pre_build_image: ${MOLECULE_PREBUILT:-true}
|
||||
networks:
|
||||
- name: k3snet
|
||||
- name: database
|
||||
image: postgres:11-alpine
|
||||
pre_build_image: true
|
||||
command: "postgres"
|
||||
env:
|
||||
POSTGRES_PASSWORD: "verybadpass"
|
||||
networks:
|
||||
- name: k3snet
|
||||
provisioner:
|
||||
name: ansible
|
||||
options:
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
hosts: all
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: Prepare
|
||||
hosts: node*
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Debug Message
|
||||
debug:
|
||||
|
14
molecule/highavailability/Dockerfile.j2
Normal file
14
molecule/highavailability/Dockerfile.j2
Normal file
@ -0,0 +1,14 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
22
molecule/highavailability/INSTALL.rst
Normal file
22
molecule/highavailability/INSTALL.rst
Normal file
@ -0,0 +1,22 @@
|
||||
*******
|
||||
Docker driver installation guide
|
||||
*******
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
* Docker Engine
|
||||
|
||||
Install
|
||||
=======
|
||||
|
||||
Please refer to the `Virtual environment`_ documentation for installation best
|
||||
practices. If not using a virtual environment, please consider passing the
|
||||
widely recommended `'--user' flag`_ when invoking ``pip``.
|
||||
|
||||
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
|
||||
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip install 'molecule[docker]'
|
67
molecule/highavailability/molecule.yml
Normal file
67
molecule/highavailability/molecule.yml
Normal file
@ -0,0 +1,67 @@
|
||||
---
|
||||
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: docker
|
||||
lint:
|
||||
name: yamllint
|
||||
platforms:
|
||||
- name: node1
|
||||
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
|
||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
privileged: true
|
||||
pre_build_image: ${MOLECULE_PREBUILT:-true}
|
||||
networks:
|
||||
- name: k3snet
|
||||
- name: node2
|
||||
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
|
||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
privileged: true
|
||||
pre_build_image: ${MOLECULE_PREBUILT:-true}
|
||||
networks:
|
||||
- name: k3snet
|
||||
- name: node3
|
||||
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
|
||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
privileged: true
|
||||
pre_build_image: ${MOLECULE_PREBUILT:-true}
|
||||
networks:
|
||||
- name: k3snet
|
||||
- name: database
|
||||
image: postgres:11-alpine
|
||||
pre_build_image: true
|
||||
command: "postgres"
|
||||
env:
|
||||
POSTGRES_PASSWORD: "verybadpass"
|
||||
networks:
|
||||
- name: k3snet
|
||||
- name: loadbalancer
|
||||
image: nginx:1.16-alpine
|
||||
pre_build_image: true
|
||||
ports:
|
||||
- "6443:6443"
|
||||
volumes:
|
||||
- ${MOLECULE_SCENARIO_DIRECTORY}/nginx-loadbalancer.conf:/etc/nginx/nginx.conf:ro
|
||||
command: "nginx -g 'daemon off;'"
|
||||
networks:
|
||||
- name: k3snet
|
||||
provisioner:
|
||||
name: ansible
|
||||
options:
|
||||
verbose: true
|
||||
lint:
|
||||
name: ansible-lint
|
||||
playbooks:
|
||||
prepare: ${MOLECULE_PREPARE_PLAYBOOK:-prepare.yml}
|
||||
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
|
||||
verifier:
|
||||
name: testinfra
|
||||
lint:
|
||||
name: flake8
|
20
molecule/highavailability/nginx-loadbalancer.conf
Normal file
20
molecule/highavailability/nginx-loadbalancer.conf
Normal file
@ -0,0 +1,20 @@
|
||||
events { }
|
||||
|
||||
http {
|
||||
# Set up our upstream of control (master) nodes. The default load balancing
|
||||
# algorithm for nginx is to round-robin. Perfect!
|
||||
upstream control_plane {
|
||||
server node2:6443;
|
||||
server node3:6443;
|
||||
}
|
||||
|
||||
# Listen on port 6443, this is our default control plane port, then pass
|
||||
# all traffic to one of the control (master) nodes.
|
||||
server {
|
||||
listen 6443;
|
||||
|
||||
location / {
|
||||
proxy_pass http://control_plane;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
k3s_control_node_address: loadbalancer
|
||||
k3s_datastore_endpoint: "postgres://postgres:verybadpass@database:5432/postgres?sslmode=disable"
|
||||
pre_tasks:
|
||||
- name: Set each node to be a control node
|
7
molecule/highavailability/prepare.yml
Normal file
7
molecule/highavailability/prepare.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Prepare
|
||||
hosts: node*
|
||||
tasks:
|
||||
- name: Debug Message
|
||||
debug:
|
||||
msg: No prepare steps required
|
14
molecule/highavailability/tests/test_default.py
Normal file
14
molecule/highavailability/tests/test_default.py
Normal file
@ -0,0 +1,14 @@
|
||||
import os
|
||||
|
||||
import testinfra.utils.ansible_runner
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||
|
||||
|
||||
def test_hosts_file(host):
|
||||
f = host.file('/etc/hosts')
|
||||
|
||||
assert f.exists
|
||||
assert f.user == 'root'
|
||||
assert f.group == 'root'
|
BIN
molecule/highavailability/tests/test_default.pyc
Normal file
BIN
molecule/highavailability/tests/test_default.pyc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user