From ea333c4052ceb3e7a5c03cc83004890cffe9c972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Mon, 29 May 2017 16:51:22 +0200 Subject: [PATCH] 3scale rollout playbook --- roles/3scale/tasks/main.yml | 126 +++++++++++++++++++++++++++++++- roles/3scale/tasks/status.yml | 22 ++++++ roles/3scale/tasks/wait_for.yml | 9 +++ roles/3scale/vars/main.yml | 2 + 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 roles/3scale/tasks/status.yml create mode 100644 roles/3scale/tasks/wait_for.yml diff --git a/roles/3scale/tasks/main.yml b/roles/3scale/tasks/main.yml index b2a50ad..ca7811d 100644 --- a/roles/3scale/tasks/main.yml +++ b/roles/3scale/tasks/main.yml @@ -23,15 +23,139 @@ - name: Process the OpenShift Template and create the OpenShift objects for the 3scale API Management Platform shell: oc process -f "{{ threescale_options.template }}" -p "TENANT_NAME={{ threescale_options.tenant_name }}" -p "WILDCARD_DOMAIN={{ threescale_options.wildcard_domain }}" | oc create -f - -n "{{ threescale_options.project }}" - # TODO + - include: status.yml + tags: status + + - name: Deploy the storage tier (MySQL, Redis and Memcache) without any replicas + command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}" + with_items: + - backend-redis + - system-memcache + - system-mysql + - system-redis + when: item not in deployment_configs + tags: rollout + + - name: Scale the storage tier (MySQL, Redis and Memcache) + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + with_items: + - backend-redis + - system-memcache + - system-mysql + - system-redis + when: item not in replication_controllers + tags: rollout + + - include: wait_for.yml + static: no + vars: + pod_to_wait: + - backend-redis + - system-memcache + - system-mysql + - system-redis + tags: status + + - name: Deploy the backend-listener without any replicas + command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}" + with_items: + - backend-listener + when: item not in deployment_configs + tags: rollout + + - name: Scale backend-listener + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + with_items: + - backend-listener + when: item not in replication_controllers + tags: rollout + + - include: wait_for.yml + static: no + vars: + pod_to_wait: + - backend-listener + tags: status + + - name: Deploy everything else without any replicas + command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}" + with_items: + - backend-listener + - backend-worker + - system-app + - system-resque + - system-sidekiq + - backend-cron + - system-sphinx + - apicast-staging + - apicast-production + when: item not in deployment_configs + tags: rollout + + - name: Scale system-app, system-resque and system-sidekiq + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + with_items: + - system-app + - system-resque + - system-sidekiq + when: item not in replication_controllers + tags: rollout + + - include: wait_for.yml + static: no + vars: + pod_to_wait: + - system-app + - system-resque + - system-sidekiq + tags: status + + - name: Scale backend-cron, backend-worker and system-sphinx + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + with_items: + - backend-worker + - backend-cron + - system-sphinx + when: item not in replication_controllers + tags: rollout + + - include: wait_for.yml + static: no + vars: + pod_to_wait: + - backend-worker + - backend-cron + - system-sphinx + tags: status + + - name: Deploy apicast-staging, apicast-production + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + with_items: + - apicast-staging + #- apicast-production + when: item not in replication_controllers + tags: rollout + + - include: wait_for.yml + static: no + vars: + pod_to_wait: + - apicast-staging + #- apicast-production + tags: status - name: Get Admin Username command: oc get dc system-app -n "{{ threescale_options.project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_LOGIN")].value}' register: username + changed_when: false + tags: status - name: Get Admin Password command: oc get dc system-app -n "{{ threescale_options.project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_PASSWORD")].value}' register: password + changed_when: false + tags: status - name: 3scale is ready ! debug: msg="Login on https://{{ threescale_options.tenant_name }}-admin.{{ threescale_options.wildcard_domain }} with username = '{{ username.stdout }}' and password = '{{ password.stdout }}'" + tags: status diff --git a/roles/3scale/tasks/status.yml b/roles/3scale/tasks/status.yml new file mode 100644 index 0000000..18b7cfe --- /dev/null +++ b/roles/3scale/tasks/status.yml @@ -0,0 +1,22 @@ +--- + + - name: Retrieve current ReplicationController status + command: 'oc get rc -o json -n "{{ threescale_options.project }}"' + register: rc_state + changed_when: false + + - name: Parse the list of deployed ReplicationController + set_fact: + replication_controllers: '{{ rc_state.stdout |from_json |json_query(''items[? @.status.replicas && @.status.replicas != `0`].metadata.annotations."openshift.io/deployment-config.name"'') }}' + replication_controllers_status: '{{ rc_state.stdout |from_json |json_query(''items[? @.status.replicas && @.status.replicas != `0`].{"name": metadata.annotations."openshift.io/deployment-config.name", "status": status.readyReplicas}'') }}' + + + - name: Retrieve current DeploymentConfig status + command: 'oc get dc -o json -n "{{ threescale_options.project }}"' + register: dc_state + changed_when: false + + - name: Parse the list of DeploymentConfig + set_fact: + deployment_configs: '{{ dc_state.stdout |from_json |json_query(''items[? metadata.generation > `1`].metadata.name'') }}' + deployment_configs_status: '{{ dc_state.stdout |from_json |json_query(''items[? metadata.generation > `1` ].{"name": metadata.name, "status": status.replicas}'') }}' diff --git a/roles/3scale/tasks/wait_for.yml b/roles/3scale/tasks/wait_for.yml new file mode 100644 index 0000000..3c8f2b6 --- /dev/null +++ b/roles/3scale/tasks/wait_for.yml @@ -0,0 +1,9 @@ +--- + + - name: Wait for all pending deployments to become ready + command: 'oc get rc -o json -n "{{ threescale_options.project }}"' + register: rc_state + changed_when: false + retries: "{{ threescale_options.retries }}" + delay: "{{ threescale_options.delay }}" + until: 'rc_state.stdout |from_json |json_query(''items[? status.replicas != `0` && (status.readyReplicas == ""|| status.readyReplicas == `0`) ].metadata.annotations."openshift.io/deployment-config.name"'') |intersect(pod_to_wait) |length == 0' diff --git a/roles/3scale/vars/main.yml b/roles/3scale/vars/main.yml index 41824dc..2ce12bd 100644 --- a/roles/3scale/vars/main.yml +++ b/roles/3scale/vars/main.yml @@ -5,3 +5,5 @@ project: 3scale tenant_name: 3scale wildcard_domain: "{{ openshift_master_default_subdomain }}" + delay: 5 + retries: 30