diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 236c4f4ea..ba15fe87f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,8 @@ jobs: matrix: scenario: - default + - single_node + fail-fast: false env: PYTHON_VERSION: "3.10" diff --git a/molecule/README.md b/molecule/README.md index f0c18b529..e14e90226 100644 --- a/molecule/README.md +++ b/molecule/README.md @@ -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 @@ -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 diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 597f6576c..afb367855 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -53,8 +53,6 @@ provisioner: inventory: links: group_vars: ../../inventory/sample/group_vars - env: - OVERRIDES_FILE: ../default/overrides.yml scenario: test_sequence: - dependency diff --git a/molecule/resources/converge.yml b/molecule/resources/converge.yml index 37d564ec7..c5efc8eb3 100644 --- a/molecule/resources/converge.yml +++ b/molecule/resources/converge.yml @@ -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 diff --git a/molecule/resources/reset.yml b/molecule/resources/reset.yml index e7a823a55..266ce859e 100644 --- a/molecule/resources/reset.yml +++ b/molecule/resources/reset.yml @@ -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 diff --git a/molecule/resources/verify/from_outside/tasks/test/get-nodes.yml b/molecule/resources/verify/from_outside/tasks/test/get-nodes.yml index 7f08f1399..aa7df6be8 100644 --- a/molecule/resources/verify/from_outside/tasks/test/get-nodes.yml +++ b/molecule/resources/verify/from_outside/tasks/test/get-nodes.yml @@ -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 + }} diff --git a/molecule/single_node/molecule.yml b/molecule/single_node/molecule.yml new file mode 100644 index 000000000..1a7ed84de --- /dev/null +++ b/molecule/single_node/molecule.yml @@ -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 diff --git a/molecule/single_node/overrides.yml b/molecule/single_node/overrides.yml new file mode 100644 index 000000000..777ef4b04 --- /dev/null +++ b/molecule/single_node/overrides.yml @@ -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"