blob: 2ac6e9aae0ce5b71dac4323bdb97da4b5096308a [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
Mohammed Naser7943cf82023-02-23 04:31:30 +000072- name: Deploy Cluster API for Magnum RBAC
73 kubernetes.core.k8s:
74 state: present
75 definition:
76 - apiVersion: v1
77 kind: Namespace
78 metadata:
79 name: magnum-system
80
Mohammed Naser15882362023-04-04 20:38:56 +000081 # TODO(mnaser): This should be removed once we have a proper Helm chart
82 # for Cluster API for Magnum.
Mohammed Naser7943cf82023-02-23 04:31:30 +000083 - apiVersion: rbac.authorization.k8s.io/v1
Mohammed Naser15882362023-04-04 20:38:56 +000084 kind: ClusterRoleBinding
Mohammed Naser7943cf82023-02-23 04:31:30 +000085 metadata:
86 name: magnum-cluster-api
Mohammed Naser7943cf82023-02-23 04:31:30 +000087 roleRef:
88 apiGroup: rbac.authorization.k8s.io
Mohammed Naser15882362023-04-04 20:38:56 +000089 kind: ClusterRole
90 name: cluster-admin
Mohammed Naser7943cf82023-02-23 04:31:30 +000091 subjects:
92 - kind: ServiceAccount
93 name: magnum-conductor
94 namespace: "{{ magnum_helm_release_namespace }}"
95
Mohammed Naserfef69422023-01-18 02:38:06 +000096- name: Deploy Helm chart
97 run_once: true
98 kubernetes.core.helm:
Mohammed Naser2145fc32023-01-29 23:23:03 +000099 name: "{{ magnum_helm_release_name }}"
100 chart_ref: "{{ magnum_helm_chart_ref }}"
101 release_namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naserfef69422023-01-18 02:38:06 +0000102 create_namespace: true
103 kubeconfig: /etc/kubernetes/admin.conf
Mohammed Naser2145fc32023-01-29 23:23:03 +0000104 values: "{{ _magnum_helm_values | combine(magnum_helm_values, recursive=True) }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500105
Mohammed Naserf0314a82023-04-11 18:53:30 +0000106- name: Deploy "magnum-cluster-api-proxy"
107 run_once: true
108 kubernetes.core.k8s:
109 state: present
110 definition:
111 - apiVerison: v1
112 kind: ConfigMap
113 metadata:
114 name: magnum-cluster-api-proxy-config
115 namespace: "{{ magnum_helm_release_namespace }}"
116 data:
117 magnum_capi_sudoers: |
118 Defaults !requiretty
119 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"
120 magnum ALL = (root) NOPASSWD: /var/lib/openstack/bin/privsep-helper
121
122 - apiVersion: apps/v1
123 kind: DaemonSet
124 metadata:
125 name: magnum-cluster-api-proxy
126 namespace: openstack
127 labels:
128 application: magnum
129 component: cluster-api-proxy
130 spec:
131 selector:
132 matchLabels:
133 application: magnum
134 component: cluster-api-proxy
135 template:
136 metadata:
137 labels:
138 application: magnum
139 component: cluster-api-proxy
140 spec:
141 containers:
142 - name: magnum-cluster-api-proxy
143 command: ["magnum-cluster-api-proxy"]
144 image: "{{ atmosphere_images['magnum_cluster_api_proxy'] | vexxhost.kubernetes.docker_image('ref') }}"
145 securityContext:
146 privileged: true
147 readOnlyRootFilesystem: true
148 volumeMounts:
149 - name: pod-tmp
150 mountPath: /tmp
151 - name: pod-run
152 mountPath: /run
153 - name: config
154 mountPath: /etc/sudoers.d/magnum_capi_sudoers
155 subPath: magnum_capi_sudoers
156 readOnly: true
157 - name: haproxy-state
158 mountPath: /var/lib/magnum/.magnum-cluster-api-proxy
159 - name: host-run-netns
160 mountPath: /run/netns
161 mountPropagation: Bidirectional
162 nodeSelector:
163 openstack-control-plane: enabled
164 securityContext:
165 runAsUser: 42424
166 serviceAccountName: magnum-conductor
167 volumes:
168 - name: pod-tmp
169 emptyDir: {}
170 - name: pod-run
171 emptyDir: {}
172 - name: config
173 configMap:
174 name: magnum-cluster-api-proxy-config
175 - name: haproxy-state
176 emptyDir: {}
177 - name: host-run-netns
178 hostPath:
179 path: /run/netns
180
Mohammed Naser4c33bb52023-01-18 03:23:18 +0000181- name: Create Ingress
182 ansible.builtin.include_role:
183 name: openstack_helm_ingress
184 vars:
185 openstack_helm_ingress_endpoint: container_infra
186 openstack_helm_ingress_service_name: magnum-api
187 openstack_helm_ingress_service_port: 9511
Mohammed Naser2145fc32023-01-29 23:23:03 +0000188 openstack_helm_ingress_annotations: "{{ magnum_ingress_annotations }}"
Mohammed Naser4c33bb52023-01-18 03:23:18 +0000189
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000190- name: Delete un-used job and PVC
191 run_once: true
192 kubernetes.core.k8s:
193 state: absent
194 definition:
195 - apiVersion: batch/v1
196 kind: Job
197 metadata:
198 name: magnum-registry-init
199 namespace: "{{ magnum_helm_release_namespace }}"
200 - apiVersion: v1
201 kind: PersistentVolumeClaim
202 metadata:
203 name: magnum-registry
204 namespace: "{{ magnum_helm_release_namespace }}"
205
okozachenko120319b530e2023-01-27 23:52:04 +1100206- name: Deploy magnum registry
Mohammed Naser65850fd2023-02-22 21:36:27 -0500207 run_once: true
Mohammed Naser096ade02022-12-15 09:53:33 -0500208 kubernetes.core.k8s:
209 state: present
210 definition:
Mohammed Naser096ade02022-12-15 09:53:33 -0500211 - apiVersion: apps/v1
212 kind: Deployment
213 metadata:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000214 name: magnum-registry
215 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500216 labels:
217 application: magnum
218 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500219 spec:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000220 replicas: 3
Mohammed Naser096ade02022-12-15 09:53:33 -0500221 selector:
222 matchLabels:
223 application: magnum
224 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500225 template:
226 metadata:
227 labels:
228 application: magnum
229 component: registry
230 spec:
231 containers:
232 - name: registry
Mohammed Naser31171f42023-03-19 00:10:46 +0000233 image: "{{ atmosphere_images['magnum_registry'] | vexxhost.kubernetes.docker_image('ref') }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500234 ports:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000235 - name: registry
236 containerPort: 5000
Mohammed Naser096ade02022-12-15 09:53:33 -0500237 protocol: TCP
238 livenessProbe:
239 httpGet:
240 path: /
241 port: 5000
242 scheme: HTTP
243 readinessProbe:
244 httpGet:
245 path: /
246 port: 5000
247 scheme: HTTP
Mohammed Naser096ade02022-12-15 09:53:33 -0500248 nodeSelector:
249 openstack-control-plane: enabled
Mohammed Naser096ade02022-12-15 09:53:33 -0500250
251 - apiVersion: v1
252 kind: Service
253 metadata:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000254 name: magnum-registry
255 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500256 labels:
257 application: magnum
258 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500259 spec:
Mohammed Nasere97c6a52023-04-13 17:50:29 +0000260 type: ClusterIP
Mohammed Naser096ade02022-12-15 09:53:33 -0500261 ports:
262 - name: magnum
263 port: 5000
264 protocol: TCP
265 targetPort: 5000
266 selector:
267 application: magnum
268 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500269
Mohammed Naser096ade02022-12-15 09:53:33 -0500270- name: Create magnum registry Ingress
271 ansible.builtin.include_role:
272 name: openstack_helm_ingress
273 vars:
274 openstack_helm_ingress_endpoint: container_infra_registry
275 openstack_helm_ingress_service_name: magnum-registry
276 openstack_helm_ingress_service_port: 5000
Mohammed Naser756b7172023-02-03 04:01:53 +0000277 openstack_helm_ingress_annotations: "{{ _magnum_registry_ingress_annotations | combine(magnum_registry_ingress_annotations) }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500278
Mohammed Naser4b630042023-02-07 20:47:45 +0000279- name: Upload images
280 ansible.builtin.include_role:
281 name: glance_image
282 loop: "{{ magnum_images }}"
283 vars:
284 glance_image_name: "{{ item.name }}"
285 glance_image_url: "{{ item.url }}"
286 glance_image_container_format: "{{ magnum_image_container_format }}"
287 glance_image_disk_format: "{{ magnum_image_disk_format }}"
Mohammed Naser38a74382023-02-07 22:48:11 +0000288 glance_image_properties:
289 os_distro: "{{ item.distro }}"