Skip to content

Commit e48d3b4

Browse files
alanbchristiea.b.christie
andauthored
feat: Initial scaleway changes (#1)
Co-authored-by: a.b.christie <alan.christie@matildapeak.com>
1 parent 81523d3 commit e48d3b4

9 files changed

Lines changed: 115 additions & 66 deletions

File tree

parameters-scw-production.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
3+
# A parameter file to replicate the variables used by AWX.
4+
# The user would run this (armed with a suitable Ansible) with: -
5+
#
6+
# export KUBECONFIG=~/k8s-config/kubeconfig-im-main-scw-admin.yaml
7+
# ansible-playbook site.yaml -e @parameters-scw-production.yaml \
8+
# -e jo_image_tag=35.0.0 \
9+
# --vault-password-file ../scw-production-vault.password
10+
11+
jo_installation_name: scw-production
12+
jo_image_tag: SetMe

parameters-sd.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

parameters-template.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

roles/operator/defaults/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
jo_state: present
66

77
# The kubernetes config file.
8-
jo_kubeconfig: SetMe
8+
jo_kubeconfig: ''
99

1010
# The Operator container image and tag
1111
jo_image: informaticsmatters/data-manager-jupyter-operator

roles/operator/tasks/dm-patch.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- name: Assert Namespace ({{ jo_dmapi_namespace }})
1010
ansible.builtin.assert:
1111
that:
12-
- ns_result.resources|length == 1
12+
- ns_result.resources | length == 1
1313

1414
- name: Get Data Manager ServiceAccount
1515
kubernetes.core.k8s_info:
@@ -21,7 +21,7 @@
2121
- name: Assert ServiceAccount
2222
ansible.builtin.assert:
2323
that:
24-
- sa_result.resources|length == 1
24+
- sa_result.resources | length == 1
2525

2626
- name: Deploy Data Manager Material
2727
kubernetes.core.k8s:

roles/operator/tasks/dm.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
---
22

3-
# A ply to deploy objects to the chosen Data Manager namespace.
3+
# A play to deploy objects to the chosen Data Manager namespace.
44
# In this case it's a Role and RoleBinding
55

66
- name: Prep
77
ansible.builtin.include_tasks: prep.yaml
8+
vars:
9+
kubeconfig: "{{ jo_kubeconfig }}"
10+
11+
# Include sensitive (Ansible Vault) variables based on the installation name.
12+
# We include 'sensitive-local.vault' variables if the installation name is 'local'.
13+
# The user will need to provide the vault password.
14+
15+
- name: Include sensitive (vault) variables ({{ jo_installation_name }})
16+
ansible.builtin.include_vars:
17+
file: sensitive-{{ jo_installation_name }}.vault
18+
when: jo_installation_name | length > 0
819

920
# Check the Data Manager Namespace and Service Account exists...
1021

roles/operator/tasks/main.yaml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@
22

33
- name: Prep
44
ansible.builtin.include_tasks: prep.yaml
5+
vars:
6+
kubeconfig: "{{ jo_kubeconfig }}"
7+
8+
# Include sensitive (Ansible Vault) variables based on the installation name.
9+
# We include 'sensitive-local.vault' variables if the installation name is 'local'.
10+
# The user will need to provide the vault password.
11+
12+
- name: Include sensitive (vault) variables ({{ jo_installation_name }})
13+
ansible.builtin.include_vars:
14+
file: sensitive-{{ jo_installation_name }}.vault
15+
when: jo_installation_name | length > 0
516

617
- name: Assert operator version defined
718
ansible.builtin.assert:
819
that:
9-
- jo_image_tag|length > 0
20+
- jo_image_tag | length > 0
1021
- jo_image_tag != 'SetMe'
1122

12-
- name: Deploy (with k8s kubeconfig)
13-
when: jo_kubeconfig != 'SetMe'
23+
- name: Go
1424
module_defaults:
1525
group/k8s:
16-
kubeconfig: "{{ jo_kubeconfig }}"
26+
host: "{{ k8s_auth_host }}"
27+
api_key: "{{ k8s_auth_api_key }}"
28+
kubeconfig: "{{ k8s_auth_kubeconfig }}"
1729
block:
1830

19-
- name: Deploy (k8s kubeconfig)
31+
- name: Deploy
2032
ansible.builtin.include_tasks: deploy.yaml
21-
when: jo_state|string == 'present'
22-
- name: Undeploy (k8s kubeconfig)
23-
ansible.builtin.include_tasks: undeploy.yaml
24-
when: jo_state|string == 'absent'
33+
when: jo_state | string == 'present'
2534

26-
- name: Deploy (with k8s host and API key)
27-
when: jo_kubeconfig == 'SetMe'
28-
block:
29-
30-
- name: Deploy (k8s API key)
31-
ansible.builtin.include_tasks: deploy.yaml
32-
when: jo_state|string == 'present'
33-
- name: Undeploy (k8s API key)
35+
- name: Undeploy
3436
ansible.builtin.include_tasks: undeploy.yaml
35-
when: jo_state|string == 'absent'
37+
when: jo_state | string == 'absent'

roles/operator/tasks/prep.yaml

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
---
22

33
# Common playbook preparation.
4+
#
5+
# We expect: -
6+
#
7+
# - kubeconfig (defined, that might point to a KUBECONFIG file)
8+
#
9+
# We process: -
10+
#
11+
# - K8S_AUTH_HOST (optional)
12+
# - K8S_AUTH_API_KEY (optional)
13+
# - KUBECONFIG (optional)
14+
#
15+
# One method of Kubernetes authentication must be provided.
16+
# On exit the following variables have been set (although some may be blank/None): -
17+
#
18+
# - k8s_auth_api_key
19+
# - k8s_auth_host
20+
# - k8s_auth_kubeconfig
21+
22+
- name: Assert inputs
23+
ansible.builtin.assert:
24+
that:
25+
- kubeconfig is defined
426

527
# Expose ansible version
628
- name: Display Ansible version
@@ -20,29 +42,58 @@
2042

2143
# Kubernetes credentials ------------------------------------------------------
2244

23-
# We don't use the Kubernetes credentials directly,
24-
# but we load them into variables here from their
25-
# expected environment variables so that we can assert they've been set.
45+
# If a kubeconfig value is set we use that.
46+
# Otherwise if K8S_AUTH_HOST is defined we use that (AWX).
47+
# Otherwise if KUBECONFIG is defined we use that.
2648

27-
- name: Set initial authentication facts
49+
- name: Load K8S_AUTH_HOST and K8S_AUTH_API_KEY
2850
ansible.builtin.set_fact:
2951
k8s_auth_host: "{{ lookup('env', 'K8S_AUTH_HOST') }}"
3052
k8s_auth_api_key: "{{ lookup('env', 'K8S_AUTH_API_KEY') }}"
3153

32-
# A kubernetes host and an API key must be set.
33-
# Either environment variables will have been set by the user
34-
# or AWX 'kubernetes' credentials will have injected them.
35-
# Either way the variables 'k8s_auth_host' and
36-
# 'k8s_auth_api_key' must have been set.
37-
- name: Assert kubernetes authentication (no kubeconfig)
54+
- name: Use kubernetes authentication (kubeconfig)
55+
ansible.builtin.set_fact:
56+
k8s_auth_kubeconfig: "{{ kubeconfig }}"
57+
when: kubeconfig | string | length > 0
58+
59+
- name: Use kubernetes authentication (k8s_auth_host)
3860
ansible.builtin.assert:
3961
that:
40-
- k8s_auth_host|string|length > 0
41-
- k8s_auth_api_key|string|length > 0
42-
when: jo_kubeconfig == 'SetMe'
62+
- k8s_auth_host | string | length > 0
63+
- k8s_auth_api_key | string | length > 0
64+
when:
65+
- kubeconfig | string | length == 0
66+
- k8s_auth_host | string | length > 0
67+
68+
- name: Use kubernetes authentication (KUBECONFIG)
69+
ansible.builtin.set_fact:
70+
k8s_auth_kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}"
71+
when:
72+
- kubeconfig | string | length == 0
73+
- k8s_auth_host | string | length == 0
4374

44-
- name: Assert kubeconfig defined (kubeconfig)
75+
- name: Kubernetes authentication must be set
4576
ansible.builtin.assert:
4677
that:
47-
- jo_kubeconfig|length > 0
48-
when: jo_kubeconfig != 'SetMe'
78+
- k8s_auth_kubeconfig is defined or k8s_auth_host is defined
79+
msg: "You must provide a means to authenticate against Kubernetes"
80+
81+
# We 'set' all the expected variables now (even to None)
82+
# to avoid the following playbooks having to apply 'default(none)'.
83+
# Basically we 'define' all three variables here,
84+
# whether they have a value or not, so any following playbook
85+
# won't encounter a 'variable not defined error'.
86+
87+
- name: Set variables (with defaults)
88+
ansible.builtin.set_fact:
89+
k8s_auth_api_key: "{{ k8s_auth_api_key | default(None) }}"
90+
k8s_auth_host: "{{ k8s_auth_host | default(None) }}"
91+
k8s_auth_kubeconfig: "{{ k8s_auth_kubeconfig | default(None) }}"
92+
93+
- name: Display Host
94+
ansible.builtin.debug:
95+
var: k8s_auth_host
96+
97+
- name: Display KUBECONFIG
98+
ansible.builtin.debug:
99+
var: k8s_auth_kubeconfig

roles/operator/tasks/undeploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
register: ns_result
1111

1212
- name: Remove operator material
13-
when: ns_result.resources|length == 1
13+
when: ns_result.resources | length == 1
1414
block:
1515

1616
- name: Remove operator Data Manager API RBAC

0 commit comments

Comments
 (0)