| # Copyright (c) 2022 VEXXHOST, Inc. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| # not use this file except in compliance with the License. You may obtain |
| # a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations |
| # under the License. |
| |
| # NOTE(mnaser): We should get rid of this task eventually as it is suspending |
| # the old HelmRelease and removing it to avoid uninstalling the |
| # Helm chart. |
| - name: Uninstall the legacy HelmRelease |
| run_once: true |
| block: |
| - name: Suspend the existing HelmRelease |
| kubernetes.core.k8s: |
| state: patched |
| api_version: helm.toolkit.fluxcd.io/v2beta1 |
| kind: HelmRelease |
| name: "{{ magnum_helm_release_name }}" |
| namespace: "{{ magnum_helm_release_namespace }}" |
| definition: |
| spec: |
| suspend: true |
| |
| - name: Remove the existing HelmRelease |
| kubernetes.core.k8s: |
| state: absent |
| api_version: helm.toolkit.fluxcd.io/v2beta1 |
| kind: HelmRelease |
| name: "{{ magnum_helm_release_name }}" |
| namespace: "{{ magnum_helm_release_namespace }}" |
| |
| - name: Deploy cluster api |
| kubernetes.core.k8s: |
| kubeconfig: /etc/kubernetes/admin.conf |
| state: present |
| template: |
| - path: 'templates/capi-bootstrap.yml.j2' |
| - path: 'templates/capi-control-plane.yml.j2' |
| - path: 'templates/capi-core.yml.j2' |
| - path: 'templates/capi-provider.yml.j2' |
| - path: 'templates/capi-rbac.yml.j2' |
| run_once: true |
| changed_when: false |
| |
| - name: Deploy Helm chart |
| run_once: true |
| kubernetes.core.helm: |
| name: "{{ magnum_helm_release_name }}" |
| chart_ref: "{{ magnum_helm_chart_ref }}" |
| release_namespace: "{{ magnum_helm_release_namespace }}" |
| create_namespace: true |
| kubeconfig: /etc/kubernetes/admin.conf |
| values: "{{ _magnum_helm_values | combine(magnum_helm_values, recursive=True) }}" |
| |
| - name: Create Ingress |
| ansible.builtin.include_role: |
| name: openstack_helm_ingress |
| vars: |
| openstack_helm_ingress_endpoint: container_infra |
| openstack_helm_ingress_service_name: magnum-api |
| openstack_helm_ingress_service_port: 9511 |
| openstack_helm_ingress_annotations: "{{ magnum_ingress_annotations }}" |
| |
| - name: Deploy magnum registry |
| kubernetes.core.k8s: |
| state: present |
| definition: |
| - apiVersion: v1 |
| kind: PersistentVolumeClaim |
| metadata: |
| labels: |
| application: magnum |
| component: registry |
| name: magnum-registry |
| namespace: "{{ magnum_helm_release_namespace }}" |
| spec: |
| accessModes: |
| - ReadWriteOnce |
| resources: |
| requests: |
| storage: 50Gi |
| |
| - apiVersion: apps/v1 |
| kind: Deployment |
| metadata: |
| labels: |
| application: magnum |
| component: registry |
| name: magnum-registry |
| namespace: "{{ magnum_helm_release_namespace }}" |
| spec: |
| replicas: 1 |
| selector: |
| matchLabels: |
| application: magnum |
| component: registry |
| strategy: |
| type: Recreate |
| template: |
| metadata: |
| labels: |
| application: magnum |
| component: registry |
| spec: |
| containers: |
| - name: registry |
| env: |
| - name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY |
| value: /var/lib/registry |
| - name: REGISTRY_COMPATIBILITY_SCHEMA1_ENABLED |
| value: "true" |
| image: "{{ atmosphere_images['magnum_registry'] | vexxhost.atmosphere.docker_image('ref') }}" |
| ports: |
| - containerPort: 5000 |
| name: registry |
| protocol: TCP |
| livenessProbe: |
| httpGet: |
| path: / |
| port: 5000 |
| scheme: HTTP |
| readinessProbe: |
| httpGet: |
| path: / |
| port: 5000 |
| scheme: HTTP |
| volumeMounts: |
| - mountPath: /var/lib/registry |
| name: magnum-registry |
| nodeSelector: |
| openstack-control-plane: enabled |
| volumes: |
| - name: magnum-registry |
| persistentVolumeClaim: |
| claimName: magnum-registry |
| |
| - apiVersion: v1 |
| kind: Service |
| metadata: |
| labels: |
| application: magnum |
| component: registry |
| name: magnum-registry |
| namespace: "{{ magnum_helm_release_namespace }}" |
| spec: |
| ports: |
| - name: magnum |
| port: 5000 |
| protocol: TCP |
| targetPort: 5000 |
| selector: |
| application: magnum |
| component: registry |
| type: ClusterIP |
| |
| - apiVersion: batch/v1 |
| kind: Job |
| metadata: |
| name: magnum-registry-init |
| namespace: "{{ magnum_helm_release_namespace }}" |
| labels: |
| application: magnum |
| component: registry |
| spec: |
| backoffLimit: 5 |
| template: |
| metadata: |
| labels: |
| application: magnum |
| spec: |
| restartPolicy: OnFailure |
| containers: |
| - name: loader |
| image: "{{ atmosphere_images['magnum_api'] | vexxhost.atmosphere.docker_image('ref') }}" |
| command: |
| - magnum-cluster-api-image-loader |
| - --insecure |
| - --repository |
| - magnum-registry.openstack.svc.cluster.local:5000 |
| nodeSelector: |
| openstack-control-plane: enabled |
| |
| - name: Create magnum registry Ingress |
| ansible.builtin.include_role: |
| name: openstack_helm_ingress |
| vars: |
| openstack_helm_ingress_endpoint: container_infra_registry |
| openstack_helm_ingress_service_name: magnum-registry |
| openstack_helm_ingress_service_port: 5000 |
| openstack_helm_ingress_annotations: "{{ _magnum_registry_ingress_annotations | combine(magnum_registry_ingress_annotations) }}" |
| |
| - name: Create k8s images |
| when: magnum_images | length > 0 |
| block: |
| - name: Wait until image service ready |
| kubernetes.core.k8s_info: |
| api_version: apps/v1 |
| kind: Deployment |
| name: glance-api |
| namespace: openstack |
| wait_sleep: 10 |
| wait_timeout: 600 |
| wait: true |
| wait_condition: |
| type: Available |
| status: true |
| |
| - name: Download images |
| ansible.builtin.get_url: |
| url: "{{ item.source_url | regex_replace('\\/$', '') }}/{{ item.image_file }}" |
| dest: "/tmp/{{ item.image_file }}" |
| mode: "0600" |
| loop: "{{ magnum_images }}" |
| |
| - name: Upload images |
| openstack.cloud.image: |
| cloud: atmosphere |
| name: "{{ item.name }}" |
| state: present |
| filename: "/tmp/{{ item.image_file }}" |
| container_format: "{{ item.container_format | default(omit) }}" |
| disk_format: "{{ item.disk_format | default(omit) }}" |
| properties: |
| os_distro: ubuntu-focal |
| loop: "{{ magnum_images }}" |
| # NOTE(mnaser): This often fails since the SSL certificates are not |
| # ready yet. We need to wait for them to be ready. |
| retries: 60 |
| delay: 5 |
| register: _result |
| until: _result is not failed |