Skip to content

Commit

Permalink
Test single-node cluster (techno-tim#78)
Browse files Browse the repository at this point in the history
* Molecule: Derive overrides.yml location from scenario dir

# Conflicts:
#	molecule/default/molecule.yml
#	molecule/ipv6/molecule.yml

* Molecule: Add single_node scenario

* Fix get_nodes test for the case of empty groups
  • Loading branch information
sleiner authored Sep 9, 2022
1 parent b1df966 commit 9ff3bb6
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
matrix:
scenario:
- default
- single_node
fail-fast: false
env:
PYTHON_VERSION: "3.10"

Expand Down
4 changes: 3 additions & 1 deletion molecule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ We have these scenarios:

- **default**:
A 3 control + 2 worker node cluster based very closely on the [sample inventory](../inventory/sample/).
- **single_node**:
Very similar to the default scenario, but uses only a single node for all cluster functionality.

## How to execute

Expand All @@ -29,7 +31,7 @@ Furthermore, the test cluster uses the `192.168.30.0/24` subnet which is [not se
To set the subnet up for use with VirtualBox, please make sure that `/etc/vbox/networks.conf` exists and that it contains this line:

```
* 192.168.30.0/24`
* 192.168.30.0/24
```

### Install Python dependencies
Expand Down
2 changes: 0 additions & 2 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ provisioner:
inventory:
links:
group_vars: ../../inventory/sample/group_vars
env:
OVERRIDES_FILE: ../default/overrides.yml
scenario:
test_sequence:
- dependency
Expand Down
2 changes: 1 addition & 1 deletion molecule/resources/converge.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Apply overrides
ansible.builtin.import_playbook: >-
{{ lookup("ansible.builtin.env", "OVERRIDES_FILE") }}
{{ lookup("ansible.builtin.env", "MOLECULE_SCENARIO_DIRECTORY") }}/overrides.yml
- name: Converge
ansible.builtin.import_playbook: ../../site.yml
2 changes: 1 addition & 1 deletion molecule/resources/reset.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Apply overrides
ansible.builtin.import_playbook: >-
{{ lookup("ansible.builtin.env", "OVERRIDES_FILE") }}
{{ lookup("ansible.builtin.env", "MOLECULE_SCENARIO_DIRECTORY") }}/overrides.yml
- name: Reset
ansible.builtin.import_playbook: ../../reset.yml
13 changes: 10 additions & 3 deletions molecule/resources/verify/from_outside/tasks/test/get-nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
fail_msg: "Expected nodes {{ expected_nodes }}, but found nodes {{ found_nodes }}"
vars:
found_nodes: >-
{{ cluster_nodes | json_query('resources[*].metadata.name') | unique }}
expected_nodes: >-
{{ (groups['master'] + groups['node']) | unique }}
{{ cluster_nodes | json_query('resources[*].metadata.name') | unique | sort }}
expected_nodes: |-
{{
(
( groups['master'] | default([]) ) +
( groups['node'] | default([]) )
)
| unique
| sort
}}
48 changes: 48 additions & 0 deletions molecule/single_node/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
dependency:
name: galaxy
driver:
name: vagrant
platforms:
- name: control1
box: generic/ubuntu2204
memory: 4096
cpus: 4
config_options:
# We currently can not use public-key based authentication on Ubuntu 22.04,
# see: https://github.com/chef/bento/issues/1405
ssh.username: "vagrant"
ssh.password: "vagrant"
groups:
- k3s_cluster
- master
interfaces:
- network_name: private_network
ip: 192.168.30.50
provisioner:
name: ansible
playbooks:
converge: ../resources/converge.yml
side_effect: ../resources/reset.yml
verify: ../resources/verify.yml
inventory:
links:
group_vars: ../../inventory/sample/group_vars
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
- create
- prepare
- converge
# idempotence is not possible with the playbook in its current form.
- verify
# We are repurposing side_effect here to test the reset playbook.
# This is why we do not run it before verify (which tests the cluster),
# but after the verify step.
- side_effect
- cleanup
- destroy
15 changes: 15 additions & 0 deletions molecule/single_node/overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Apply overrides
hosts: all
tasks:
- name: Override host variables
ansible.builtin.set_fact:
# See: https://github.com/flannel-io/flannel/blob/67d603aaf45ef80f5dd39f43714fc5e6f8a637eb/Documentation/troubleshooting.md#Vagrant # noqa yaml[line-length]
flannel_iface: eth1

# The test VMs might be a bit slow, so we give them more time to join the cluster:
retry_count: 45

# Make sure that our IP ranges do not collide with those of the default scenario
apiserver_endpoint: "192.168.30.223"
metal_lb_ip_range: "192.168.30.91-192.168.30.99"

0 comments on commit 9ff3bb6

Please sign in to comment.