Skip to content

Commit f32b039

Browse files
author
Julien Girardin
committed
WIP to be squashed properly
1 parent 8181515 commit f32b039

File tree

7 files changed

+57
-49
lines changed

7 files changed

+57
-49
lines changed

roles/bootstrap_token/tasks/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
nodes_to_join: >-
55
{{ q('inventory_hostnames', kube_cp_group ~ ':' ~ kube_worker_group)
66
|map('extract', hostvars)
7+
|selectattr('_kubelet_config_stat', 'defined')
78
|rejectattr('_kubelet_config_stat.stat.exists')
89
|map(attribute='inventory_hostname')|list }}
910
run_once: true

roles/common_vars/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ kube_cp_group: kube_control_plane
66
kube_worker_group: kube_workers
77

88
cp_node: '{{ (groups.cp_running|default(groups[kube_cp_group]))|first }}'
9+
10+
target_kube_version: '{{ hostvars[cp_node].target_kube_version }}'
11+
target_kubeadm_version: '{{ hostvars[cp_node].target_kubeadm_version }}'

roles/packages/meta/main.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
---
22
dependencies:
33
- role: packages_common
4-
galaxy_info:
5-
author: Julien Girardin
6-
description: Install kubernetes related packages
7-
company: Enix
8-
license: Apache
9-
min_ansible_version: 2.7
10-
platforms:
11-
- name: Ubuntu
12-
versions:
13-
- 18.04
14-
- 20.04
15-
galaxy_tags:
16-
- kubernetes
17-
- kubeadm
18-
- kubelet
19-
- kubectl
4+
- role: common_vars

tests/conftest.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def vagrant(tmpdir):
9595
return LocalVagrant(inventory_dir_copy=tmpdir)
9696

9797

98-
@then("Set cluster {variable} = {value}")
99-
@given("The cluster {variable) = {value}")
98+
@then(parsers.parse("Set cluster {variable} = {value}"))
99+
@given(parsers.parse("The cluster {variable} = {value}"))
100100
def cluster_set_param(provider, variable, value):
101101
provider.vars[variable] = value
102102
# Refresh infrastructure
@@ -179,18 +179,12 @@ def ansible_playbook(
179179
dry_run = True
180180
else:
181181
dry_run = False
182-
playbook_list = re.findall(r"[\w./]+", playbooks)
183-
if not all(os.path.exists(p) for p in playbook_list):
184-
playbook_list_subdir = [os.path.join("playbooks", p) for p in playbook_list]
185-
if all(os.path.exists(p) for p in playbook_list_subdir):
186-
playbook_list = playbook_list_subdir
187-
else:
188-
raise ValueError("All playbooks could not be found")
182+
playbook_list = re.findall(r"[^\s]+", playbooks)
189183
result = run_ansible_playbook(
190184
virtualenv,
191-
playbook_list,
192-
ansible_extra_args=ansible_extra_args,
193185
inventory=inventory,
186+
playbooks=playbook_list,
187+
ansible_extra_args=ansible_extra_args,
194188
dry_run=dry_run,
195189
)
196190
if error:

tests/features/join_nodes.feature

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Feature: Upgrade
2-
A test to upgrade a kubeadm cluster
1+
Feature: Join Nodes
2+
A test to join nodes to a kubeadm cluster
33

4-
Scenario: Upgrade via ansible-kubeadm
4+
Scenario: Join nodes via ansible-kubeadm
55
Given I want ansible 3
66
Given The cluster control_plane_count = 1
7-
Given The cluster worker_count = 1
7+
Given The cluster worker_count = 0
88
Given Some running VMs
99

1010
When With those group_vars on group all:
@@ -18,14 +18,22 @@ Feature: Upgrade
1818
cgroupDriver: "systemd"
1919
kube_version: 1.23
2020
When I run the playbook tests/playbooks/prepare.yml
21-
When I run the playbooks 00_apiserver_proxy.yml
22-
01_site.yml
23-
When I run the playbook tests/playbooks/cni.yml
21+
When I run the playbooks playbooks/00_apiserver_proxy.yml
22+
playbooks/01_site.yml
23+
When I run the playbooks tests/playbooks/delete_bootstrap_token.yml
2424

25-
Then Set cluster worker_count = 2
25+
Then Set cluster worker_count = 1
26+
When I run the playbook tests/playbooks/prepare.yml
27+
When I run the playbooks playbooks/01_site.yml --tags bootstrap_token
28+
When I reset tasks counters
29+
When I run the playbooks playbooks/01_site.yml --tags bootstrap_token
30+
Then I should see no orange/yellow changed tasks
31+
When I run the playbooks playbooks/01_site.yml --tags join -l *-node-1
32+
Then I should have a working cluster
2633

27-
When With those group_vars on group all: kube_version: 1.24
28-
When I run the playbooks 00_apiserver_proxy.yml
29-
01_site.yml
34+
Then Set cluster control_plane_count = 2
35+
When I run the playbook tests/playbooks/prepare.yml
36+
When I run the playbooks playbooks/00_apiserver_proxy.yml
37+
playbooks/01_site.yml
3038

3139
Then I should have a working cluster

tests/helpers/ansible.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
import ansible_runner
5+
import ansible_runner.interface
56

67

78
def install_ansible(virtualenv, version=None):
@@ -22,36 +23,47 @@ def install_galaxy_deps(virtualenv):
2223
"install",
2324
"-r",
2425
os.path.join(test_dir, "ansible.requirements.yml"),
25-
"-p",
26-
os.path.join(test_dir, "playbooks/roles"),
2726
]
2827
)
28+
# [
29+
# "ansible-galaxy",
30+
# "collection",
31+
# "install",
32+
# "git+file://{}".format(os.path.dirname(os.path.dirname(os.path.dirname(test_dir)))),
33+
# ]
34+
# )
2935

3036

3137
def run_ansible_playbook(
32-
virtualenv, playbooks, dry_run=False, ansible_extra_args=None, **kwargs
38+
virtualenv, inventory, playbooks, dry_run=False, ansible_extra_args=None, **kwargs
3339
):
3440
if isinstance(playbooks, str):
3541
playbooks = [playbooks]
36-
playbooks = [
37-
os.path.join(os.path.dirname(__file__), "../..", pbk) for pbk in playbooks
38-
]
42+
# playbooks = [
43+
# os.path.join(os.path.dirname(__file__), "../..", pbk) for pbk in playbooks
44+
# ]
3945
# ansible_runner has several "bugs":
4046
# - Don't accept multiple playbooks on the parameter "playbook" (which is supposed to accept list)
4147
# - If you pass custom binary it cannot say if ansible or ansible-playbook so doesn't inject playbook anymore
4248
# => thus, pass playbooks as cmdline
4349
envvars = dict(os.environ)
4450
envvars.setdefault("ANSIBLE_HOST_KEY_CHECKING", "false")
4551
envvars.setdefault("ANSIBLE_FORCE_COLOR", "true")
46-
cmdline = " ".join(itertools.chain(ansible_extra_args or [], playbooks))
52+
cmdline_args = [
53+
"-i",
54+
inventory,
55+
*itertools.chain(playbooks, ansible_extra_args or []),
56+
]
4757
if dry_run:
48-
cmdline += " -C"
49-
return ansible_runner.run(
50-
binary=os.path.join(virtualenv.virtualenv, "bin/ansible-playbook"),
51-
cmdline=cmdline,
58+
cmdline_args += ["-C"]
59+
runner = ansible_runner.interface.init_command_config(
60+
executable_cmd=os.path.join(virtualenv.virtualenv, "bin/ansible-playbook"),
61+
cmdline_args=cmdline_args,
5262
envvars=envvars,
5363
**kwargs
5464
)
65+
runner.run()
66+
return runner
5567

5668

5769
def assert_ansible_error(run):

tests/test_basic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ def test_upgrade(operating_system):
1717
@scenario("features/haproxy.feature", "Test upgrade to haproxy pkg")
1818
def test_haproxy(operating_system):
1919
pass
20+
21+
22+
@scenario("features/join_nodes.feature", "Join nodes via ansible-kubeadm")
23+
def test_join_nodes(operating_system):
24+
pass

0 commit comments

Comments
 (0)