blob: c546565964ddc3cdbaadc2359b13cf4490727914 [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
22 kubernetes.core.k8s:
23 state: patched
24 api_version: helm.toolkit.fluxcd.io/v2beta1
25 kind: HelmRelease
Mohammed Naser2145fc32023-01-29 23:23:03 +000026 name: "{{ magnum_helm_release_name }}"
27 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naserfef69422023-01-18 02:38:06 +000028 definition:
29 spec:
30 suspend: true
31
32 - name: Remove the existing HelmRelease
33 kubernetes.core.k8s:
34 state: absent
35 api_version: helm.toolkit.fluxcd.io/v2beta1
36 kind: HelmRelease
Mohammed Naser2145fc32023-01-29 23:23:03 +000037 name: "{{ magnum_helm_release_name }}"
38 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naserfef69422023-01-18 02:38:06 +000039
Mohammed Naser65850fd2023-02-22 21:36:27 -050040- name: Install "clusterctl"
41 ansible.builtin.get_url:
42 url: "{{ magnum_clusterctl_url }}"
43 dest: /usr/local/bin/clusterctl
Mohammed Naser2fec6412023-03-01 12:55:37 +000044 mode: "0755"
Mohammed Naser65850fd2023-02-22 21:36:27 -050045 owner: root
46 group: root
47
48- name: Create a configuration file
49 ansible.builtin.copy:
50 content: "{{ magnum_clusterctl_config | to_nice_yaml }}"
51 dest: "{{ magnum_clusterctl_config_file }}"
Mohammed Naser2fec6412023-03-01 12:55:37 +000052 mode: "0644"
Mohammed Naser65850fd2023-02-22 21:36:27 -050053 owner: root
54 group: root
55
56- name: Initialize the management cluster
okozachenko120319b530e2023-01-27 23:52:04 +110057 run_once: true
okozachenko12035b9d0f12023-01-28 01:24:40 +110058 changed_when: false
Mohammed Naser65850fd2023-02-22 21:36:27 -050059 ansible.builtin.command: |
60 clusterctl init \
61 --config {{ magnum_clusterctl_config_file }} \
62 --core cluster-api:v1.3.3 \
63 --bootstrap kubeadm:v1.3.3 \
64 --control-plane kubeadm:v1.3.3 \
Oleksandr Kozachenko92175702023-03-03 09:55:29 +010065 --infrastructure openstack:v0.7.1
Mohammed Naser65850fd2023-02-22 21:36:27 -050066 environment:
67 CLUSTER_TOPOLOGY: "true"
68 EXP_CLUSTER_RESOURCE_SET: "true"
okozachenko120319b530e2023-01-27 23:52:04 +110069
Mohammed Naser7943cf82023-02-23 04:31:30 +000070- name: Deploy Cluster API for Magnum RBAC
71 kubernetes.core.k8s:
72 state: present
73 definition:
74 - apiVersion: v1
75 kind: Namespace
76 metadata:
77 name: magnum-system
78
Mohammed Naser15882362023-04-04 20:38:56 +000079 # TODO(mnaser): This should be removed once we have a proper Helm chart
80 # for Cluster API for Magnum.
Mohammed Naser7943cf82023-02-23 04:31:30 +000081 - apiVersion: rbac.authorization.k8s.io/v1
Mohammed Naser15882362023-04-04 20:38:56 +000082 kind: ClusterRoleBinding
Mohammed Naser7943cf82023-02-23 04:31:30 +000083 metadata:
84 name: magnum-cluster-api
Mohammed Naser7943cf82023-02-23 04:31:30 +000085 roleRef:
86 apiGroup: rbac.authorization.k8s.io
Mohammed Naser15882362023-04-04 20:38:56 +000087 kind: ClusterRole
88 name: cluster-admin
Mohammed Naser7943cf82023-02-23 04:31:30 +000089 subjects:
90 - kind: ServiceAccount
91 name: magnum-conductor
92 namespace: "{{ magnum_helm_release_namespace }}"
93
Mohammed Naserfef69422023-01-18 02:38:06 +000094- name: Deploy Helm chart
95 run_once: true
96 kubernetes.core.helm:
Mohammed Naser2145fc32023-01-29 23:23:03 +000097 name: "{{ magnum_helm_release_name }}"
98 chart_ref: "{{ magnum_helm_chart_ref }}"
99 release_namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naserfef69422023-01-18 02:38:06 +0000100 create_namespace: true
101 kubeconfig: /etc/kubernetes/admin.conf
Mohammed Naser2145fc32023-01-29 23:23:03 +0000102 values: "{{ _magnum_helm_values | combine(magnum_helm_values, recursive=True) }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500103
Mohammed Naser4c33bb52023-01-18 03:23:18 +0000104- name: Create Ingress
105 ansible.builtin.include_role:
106 name: openstack_helm_ingress
107 vars:
108 openstack_helm_ingress_endpoint: container_infra
109 openstack_helm_ingress_service_name: magnum-api
110 openstack_helm_ingress_service_port: 9511
Mohammed Naser2145fc32023-01-29 23:23:03 +0000111 openstack_helm_ingress_annotations: "{{ magnum_ingress_annotations }}"
Mohammed Naser4c33bb52023-01-18 03:23:18 +0000112
okozachenko120319b530e2023-01-27 23:52:04 +1100113- name: Deploy magnum registry
Mohammed Naser65850fd2023-02-22 21:36:27 -0500114 run_once: true
Mohammed Naser096ade02022-12-15 09:53:33 -0500115 kubernetes.core.k8s:
116 state: present
117 definition:
118 - apiVersion: v1
119 kind: PersistentVolumeClaim
120 metadata:
121 labels:
122 application: magnum
123 component: registry
124 name: magnum-registry
Mohammed Naser756b7172023-02-03 04:01:53 +0000125 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500126 spec:
127 accessModes:
128 - ReadWriteOnce
129 resources:
130 requests:
131 storage: 50Gi
Mohammed Naser096ade02022-12-15 09:53:33 -0500132
133 - apiVersion: apps/v1
134 kind: Deployment
135 metadata:
136 labels:
137 application: magnum
138 component: registry
139 name: magnum-registry
Mohammed Naser756b7172023-02-03 04:01:53 +0000140 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500141 spec:
142 replicas: 1
143 selector:
144 matchLabels:
145 application: magnum
146 component: registry
147 strategy:
148 type: Recreate
149 template:
150 metadata:
151 labels:
152 application: magnum
153 component: registry
154 spec:
155 containers:
156 - name: registry
157 env:
158 - name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
159 value: /var/lib/registry
160 - name: REGISTRY_COMPATIBILITY_SCHEMA1_ENABLED
161 value: "true"
Mohammed Naser31171f42023-03-19 00:10:46 +0000162 image: "{{ atmosphere_images['magnum_registry'] | vexxhost.kubernetes.docker_image('ref') }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500163 ports:
164 - containerPort: 5000
165 name: registry
166 protocol: TCP
167 livenessProbe:
168 httpGet:
169 path: /
170 port: 5000
171 scheme: HTTP
172 readinessProbe:
173 httpGet:
174 path: /
175 port: 5000
176 scheme: HTTP
177 volumeMounts:
178 - mountPath: /var/lib/registry
179 name: magnum-registry
180 nodeSelector:
181 openstack-control-plane: enabled
182 volumes:
183 - name: magnum-registry
184 persistentVolumeClaim:
185 claimName: magnum-registry
186
187 - apiVersion: v1
188 kind: Service
189 metadata:
190 labels:
191 application: magnum
192 component: registry
193 name: magnum-registry
Mohammed Naser756b7172023-02-03 04:01:53 +0000194 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500195 spec:
196 ports:
197 - name: magnum
198 port: 5000
199 protocol: TCP
200 targetPort: 5000
201 selector:
202 application: magnum
203 component: registry
204 type: ClusterIP
205
206 - apiVersion: batch/v1
207 kind: Job
208 metadata:
Mohammed Naser756b7172023-02-03 04:01:53 +0000209 name: magnum-registry-init
210 namespace: "{{ magnum_helm_release_namespace }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500211 labels:
212 application: magnum
213 component: registry
Mohammed Naser096ade02022-12-15 09:53:33 -0500214 spec:
215 backoffLimit: 5
216 template:
217 metadata:
218 labels:
219 application: magnum
220 spec:
221 restartPolicy: OnFailure
222 containers:
Mohammed Naser756b7172023-02-03 04:01:53 +0000223 - name: loader
Mohammed Naser31171f42023-03-19 00:10:46 +0000224 image: "{{ atmosphere_images['magnum_api'] | vexxhost.kubernetes.docker_image('ref') }}"
Mohammed Naser756b7172023-02-03 04:01:53 +0000225 command:
226 - magnum-cluster-api-image-loader
227 - --insecure
228 - --repository
229 - magnum-registry.openstack.svc.cluster.local:5000
Mohammed Naser096ade02022-12-15 09:53:33 -0500230 nodeSelector:
231 openstack-control-plane: enabled
232
Mohammed Naser096ade02022-12-15 09:53:33 -0500233- name: Create magnum registry Ingress
234 ansible.builtin.include_role:
235 name: openstack_helm_ingress
236 vars:
237 openstack_helm_ingress_endpoint: container_infra_registry
238 openstack_helm_ingress_service_name: magnum-registry
239 openstack_helm_ingress_service_port: 5000
Mohammed Naser756b7172023-02-03 04:01:53 +0000240 openstack_helm_ingress_annotations: "{{ _magnum_registry_ingress_annotations | combine(magnum_registry_ingress_annotations) }}"
Mohammed Naser096ade02022-12-15 09:53:33 -0500241
Mohammed Naser4b630042023-02-07 20:47:45 +0000242- name: Upload images
243 ansible.builtin.include_role:
244 name: glance_image
245 loop: "{{ magnum_images }}"
246 vars:
247 glance_image_name: "{{ item.name }}"
248 glance_image_url: "{{ item.url }}"
249 glance_image_container_format: "{{ magnum_image_container_format }}"
250 glance_image_disk_format: "{{ magnum_image_disk_format }}"
Mohammed Naser38a74382023-02-07 22:48:11 +0000251 glance_image_properties:
252 os_distro: "{{ item.distro }}"