blob: 9033e9266e0e3bc1c9eef46ed56ae2aaf85d06ea [file] [log] [blame]
Mohammed Naser096ade02022-12-15 09:53:33 -05001# Copyright (c) 2022 VEXXHOST, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Mohammed Naserfef69422023-01-18 02:38:06 +000015# NOTE(mnaser): We should get rid of this task eventually as it is suspending
16# the old HelmRelease and removing it to avoid uninstalling the
17# Helm chart.
18- name: Uninstall the legacy HelmRelease
19 run_once: true
20 block:
21 - name: Suspend the existing HelmRelease
Mohammed Naserf0314a82023-04-11 18:53:30 +000022 failed_when: false
Mohammed Naserfef69422023-01-18 02:38:06 +000023 kubernetes.core.k8s:
24 state: patched
25 api_version: helm.toolkit.fluxcd.io/v2beta1
26 kind: HelmRelease
Mohammed Naser2145fc32023-01-29 23:23:03 +000027 name: "{{ magnum_helm_release_name }}"
28 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naserfef69422023-01-18 02:38:06 +000029 definition:
30 spec:
31 suspend: true
32
33 - name: Remove the existing HelmRelease
Mohammed Naserf0314a82023-04-11 18:53:30 +000034 failed_when: false
Mohammed Naserfef69422023-01-18 02:38:06 +000035 kubernetes.core.k8s:
36 state: absent
37 api_version: helm.toolkit.fluxcd.io/v2beta1
38 kind: HelmRelease
Mohammed Naser2145fc32023-01-29 23:23:03 +000039 name: "{{ magnum_helm_release_name }}"
40 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naserfef69422023-01-18 02:38:06 +000041
Mohammed Naser65850fd2023-02-22 21:36:27 -050042- name: Install "clusterctl"
43 ansible.builtin.get_url:
44 url: "{{ magnum_clusterctl_url }}"
45 dest: /usr/local/bin/clusterctl
Mohammed Naser2fec6412023-03-01 12:55:37 +000046 mode: "0755"
Mohammed Naser65850fd2023-02-22 21:36:27 -050047 owner: root
48 group: root
49
50- name: Create a configuration file
51 ansible.builtin.copy:
52 content: "{{ magnum_clusterctl_config | to_nice_yaml }}"
53 dest: "{{ magnum_clusterctl_config_file }}"
Mohammed Naser2fec6412023-03-01 12:55:37 +000054 mode: "0644"
Mohammed Naser65850fd2023-02-22 21:36:27 -050055 owner: root
56 group: root
57
58- name: Initialize the management cluster
okozachenko120319b530e2023-01-27 23:52:04 +110059 run_once: true
okozachenko12035b9d0f12023-01-28 01:24:40 +110060 changed_when: false
Mohammed Naser65850fd2023-02-22 21:36:27 -050061 ansible.builtin.command: |
62 clusterctl init \
63 --config {{ magnum_clusterctl_config_file }} \
64 --core cluster-api:v1.3.3 \
65 --bootstrap kubeadm:v1.3.3 \
66 --control-plane kubeadm:v1.3.3 \
Oleksandr Kozachenko92175702023-03-03 09:55:29 +010067 --infrastructure openstack:v0.7.1
Mohammed Naser65850fd2023-02-22 21:36:27 -050068 environment:
69 CLUSTER_TOPOLOGY: "true"
70 EXP_CLUSTER_RESOURCE_SET: "true"
okozachenko120319b530e2023-01-27 23:52:04 +110071
Oleksandr Kozachenko77653522023-05-11 23:23:39 +020072
73# NOTE(okozachenko1203): We should get rid of this task eventually as it is removing
74# the old RBAC resources.
75- name: Remove the legacy mcapi RBAC resources
76 run_once: true
77 block:
78 - name: Remove the Role
79 failed_when: false
80 kubernetes.core.k8s:
81 state: absent
82 api_version: rbac.authorization.k8s.io/v1
83 kind: Role
84 name: magnum-cluster-api
85 namespace: magnum-system
86
87 - name: Remove the RoleBinding
88 failed_when: false
89 kubernetes.core.k8s:
90 state: absent
91 api_version: rbac.authorization.k8s.io/v1
92 kind: RoleBinding
93 name: magnum-cluster-api
94 namespace: magnum-system
95
Mohammed Naser7943cf82023-02-23 04:31:30 +000096- name: Deploy Cluster API for Magnum RBAC
97 kubernetes.core.k8s:
98 state: present
99 definition:
100 - apiVersion: v1
101 kind: Namespace
102 metadata:
103 name: magnum-system
104
Mohammed Naser15882362023-04-04 20:38:56 +0000105 # TODO(mnaser): This should be removed once we have a proper Helm chart
106 # for Cluster API for Magnum.
Mohammed Naser7943cf82023-02-23 04:31:30 +0000107 - apiVersion: rbac.authorization.k8s.io/v1
Mohammed Naser15882362023-04-04 20:38:56 +0000108 kind: ClusterRoleBinding
Mohammed Naser7943cf82023-02-23 04:31:30 +0000109 metadata:
110 name: magnum-cluster-api
Mohammed Naser7943cf82023-02-23 04:31:30 +0000111 roleRef:
112 apiGroup: rbac.authorization.k8s.io
Mohammed Naser15882362023-04-04 20:38:56 +0000113 kind: ClusterRole
114 name: cluster-admin
Mohammed Naser7943cf82023-02-23 04:31:30 +0000115 subjects:
116 - kind: ServiceAccount
117 name: magnum-conductor
118 namespace: "{{ magnum_helm_release_namespace }}"
119
Mohammed Naserfef69422023-01-18 02:38:06 +0000120- name: Deploy Helm chart
121 run_once: true
122 kubernetes.core.helm:
Mohammed Naser2145fc32023-01-29 23:23:03 +0000123 name: "{{ magnum_helm_release_name }}"
124 chart_ref: "{{ magnum_helm_chart_ref }}"
125 release_namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naserfef69422023-01-18 02:38:06 +0000126 create_namespace: true
127 kubeconfig: /etc/kubernetes/admin.conf
Mohammed Naser2145fc32023-01-29 23:23:03 +0000128 values: "{{ _magnum_helm_values | combine(magnum_helm_values, recursive=True) }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500129
Mohammed Naserf0314a82023-04-11 18:53:30 +0000130- name: Deploy "magnum-cluster-api-proxy"
131 run_once: true
132 kubernetes.core.k8s:
133 state: present
134 definition:
135 - apiVerison: v1
136 kind: ConfigMap
137 metadata:
138 name: magnum-cluster-api-proxy-config
139 namespace: "{{ magnum_helm_release_namespace }}"
140 data:
141 magnum_capi_sudoers: |
142 Defaults !requiretty
143 Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/var/lib/openstack/bin:/var/lib/kolla/venv/bin"
144 magnum ALL = (root) NOPASSWD: /var/lib/openstack/bin/privsep-helper
145
146 - apiVersion: apps/v1
147 kind: DaemonSet
148 metadata:
149 name: magnum-cluster-api-proxy
150 namespace: openstack
151 labels:
152 application: magnum
153 component: cluster-api-proxy
154 spec:
155 selector:
156 matchLabels:
157 application: magnum
158 component: cluster-api-proxy
159 template:
160 metadata:
161 labels:
162 application: magnum
163 component: cluster-api-proxy
164 spec:
165 containers:
166 - name: magnum-cluster-api-proxy
167 command: ["magnum-cluster-api-proxy"]
168 image: "{{ atmosphere_images['magnum_cluster_api_proxy'] | vexxhost.kubernetes.docker_image('ref') }}"
169 securityContext:
170 privileged: true
171 readOnlyRootFilesystem: true
172 volumeMounts:
173 - name: pod-tmp
174 mountPath: /tmp
175 - name: pod-run
176 mountPath: /run
177 - name: config
178 mountPath: /etc/sudoers.d/magnum_capi_sudoers
179 subPath: magnum_capi_sudoers
180 readOnly: true
181 - name: haproxy-state
182 mountPath: /var/lib/magnum/.magnum-cluster-api-proxy
183 - name: host-run-netns
184 mountPath: /run/netns
185 mountPropagation: Bidirectional
186 nodeSelector:
187 openstack-control-plane: enabled
188 securityContext:
189 runAsUser: 42424
190 serviceAccountName: magnum-conductor
191 volumes:
192 - name: pod-tmp
193 emptyDir: {}
194 - name: pod-run
195 emptyDir: {}
196 - name: config
197 configMap:
198 name: magnum-cluster-api-proxy-config
199 - name: haproxy-state
200 emptyDir: {}
201 - name: host-run-netns
202 hostPath:
203 path: /run/netns
204
Mohammed Naser4c33bb52023-01-18 03:23:18 +0000205- name: Create Ingress
206 ansible.builtin.include_role:
207 name: openstack_helm_ingress
208 vars:
209 openstack_helm_ingress_endpoint: container_infra
210 openstack_helm_ingress_service_name: magnum-api
211 openstack_helm_ingress_service_port: 9511
Mohammed Naser2145fc32023-01-29 23:23:03 +0000212 openstack_helm_ingress_annotations: "{{ magnum_ingress_annotations }}"
Mohammed Naser4c33bb52023-01-18 03:23:18 +0000213
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000214- name: Delete un-used job and PVC
215 run_once: true
216 kubernetes.core.k8s:
217 state: absent
218 definition:
219 - apiVersion: batch/v1
220 kind: Job
221 metadata:
222 name: magnum-registry-init
223 namespace: "{{ magnum_helm_release_namespace }}"
224 - apiVersion: v1
225 kind: PersistentVolumeClaim
226 metadata:
227 name: magnum-registry
228 namespace: "{{ magnum_helm_release_namespace }}"
229
okozachenko120319b530e2023-01-27 23:52:04 +1100230- name: Deploy magnum registry
Mohammed Naser65850fd2023-02-22 21:36:27 -0500231 run_once: true
Mohammed Naser096ade02022-12-15 09:53:33 -0500232 kubernetes.core.k8s:
233 state: present
234 definition:
Mohammed Naser096ade02022-12-15 09:53:33 -0500235 - apiVersion: apps/v1
236 kind: Deployment
237 metadata:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000238 name: magnum-registry
239 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500240 labels:
241 application: magnum
242 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500243 spec:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000244 replicas: 3
Mohammed Naser096ade02022-12-15 09:53:33 -0500245 selector:
246 matchLabels:
247 application: magnum
248 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500249 template:
250 metadata:
251 labels:
252 application: magnum
253 component: registry
254 spec:
255 containers:
256 - name: registry
Mohammed Naser31171f42023-03-19 00:10:46 +0000257 image: "{{ atmosphere_images['magnum_registry'] | vexxhost.kubernetes.docker_image('ref') }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500258 ports:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000259 - name: registry
260 containerPort: 5000
Mohammed Naser096ade02022-12-15 09:53:33 -0500261 protocol: TCP
262 livenessProbe:
263 httpGet:
264 path: /
265 port: 5000
266 scheme: HTTP
267 readinessProbe:
268 httpGet:
269 path: /
270 port: 5000
271 scheme: HTTP
Mohammed Naser096ade02022-12-15 09:53:33 -0500272 nodeSelector:
273 openstack-control-plane: enabled
Mohammed Naser096ade02022-12-15 09:53:33 -0500274
275 - apiVersion: v1
276 kind: Service
277 metadata:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000278 name: magnum-registry
279 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500280 labels:
281 application: magnum
282 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500283 spec:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000284 type: ClusterIP
Mohammed Naser096ade02022-12-15 09:53:33 -0500285 ports:
286 - name: magnum
287 port: 5000
288 protocol: TCP
289 targetPort: 5000
290 selector:
291 application: magnum
292 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500293
Mohammed Naser096ade02022-12-15 09:53:33 -0500294- name: Create magnum registry Ingress
295 ansible.builtin.include_role:
296 name: openstack_helm_ingress
297 vars:
298 openstack_helm_ingress_endpoint: container_infra_registry
299 openstack_helm_ingress_service_name: magnum-registry
300 openstack_helm_ingress_service_port: 5000
Mohammed Naser756b7172023-02-03 04:01:53 +0000301 openstack_helm_ingress_annotations: "{{ _magnum_registry_ingress_annotations | combine(magnum_registry_ingress_annotations) }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500302
Mohammed Naser4b630042023-02-07 20:47:45 +0000303- name: Upload images
304 ansible.builtin.include_role:
305 name: glance_image
306 loop: "{{ magnum_images }}"
307 vars:
308 glance_image_name: "{{ item.name }}"
309 glance_image_url: "{{ item.url }}"
310 glance_image_container_format: "{{ magnum_image_container_format }}"
311 glance_image_disk_format: "{{ magnum_image_disk_format }}"
Mohammed Naser38a74382023-02-07 22:48:11 +0000312 glance_image_properties:
313 os_distro: "{{ item.distro }}"