From 4bce40e26e01f2a6244faf2266ab811d2262afac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Tue, 21 Nov 2017 10:13:21 +0100 Subject: [PATCH] update 3scale to version 2.1 (see #20), cleanup unneeded components and prepare for offline install (see #19) --- roles/3scale/defaults/main.yml | 7 +++-- roles/3scale/tasks/apicast_cors.yml | 17 ++++++---- .../tasks/configure_apicast_for_oauth.yml | 7 ----- roles/3scale/tasks/main.yml | 31 ++++++++++--------- 4 files changed, 32 insertions(+), 30 deletions(-) delete mode 100644 roles/3scale/tasks/configure_apicast_for_oauth.yml diff --git a/roles/3scale/defaults/main.yml b/roles/3scale/defaults/main.yml index 17a2781..a3e4a09 100644 --- a/roles/3scale/defaults/main.yml +++ b/roles/3scale/defaults/main.yml @@ -1,7 +1,7 @@ --- threescale_apicast_git_repo: https://github.com/3scale/apicast.git - threescale_webhooks_git_repo: https://github.com/nmasse-itix/3scale-webhooks-sample.git + threescale_apicast_tag: 3.1-stable threescale_template: https://raw.githubusercontent.com/3scale/3scale-amp-openshift-templates/2.0.0.GA/amp/amp.yml threescale_template_format: YAML threescale_project: 3scale @@ -9,8 +9,6 @@ threescale_wildcard_domain: "{{ openshift_master_default_subdomain }}" threescale_delay: 5 threescale_retries: 30 - threescale_apicast_cors_lua: https://raw.githubusercontent.com/3scale/apicast/master/examples/cors/cors.lua - threescale_apicast_cors_conf: https://raw.githubusercontent.com/3scale/apicast/master/examples/cors/cors.conf threescale_webhooks_secret: supersecret threescale_expected_deployment_configs: - apicast-staging @@ -26,6 +24,9 @@ - system-sidekiq - backend-cron - system-sphinx + - zync + - zync-database + - apicast-wildcard-router threescale_apis_to_create: - service: name: "Hello API" diff --git a/roles/3scale/tasks/apicast_cors.yml b/roles/3scale/tasks/apicast_cors.yml index 8b14b02..fe6219a 100644 --- a/roles/3scale/tasks/apicast_cors.yml +++ b/roles/3scale/tasks/apicast_cors.yml @@ -3,20 +3,25 @@ tempfile: state=directory register: tempfile - - name: Download 'cors.lua' - get_url: dest='{{ tempfile.path }}/cors.lua' url={{ threescale_apicast_cors_lua }} + - name: Use a local copy of the 3scale/apicast GIT repo + set_fact: + threescale_apicast_git_repo: 'http://{{ offline_git_route }}/{{ threescale_apicast_git_repo|basename|regex_replace(''[.]git$'', '''') }}' + when: 'is_offline|default(false)|bool' - - name: Download 'cors.conf' - get_url: dest='{{ tempfile.path }}/cors.conf' url={{ threescale_apicast_cors_conf }} + - name: Check out the 3scale/apicast GIT repo + git: + repo: '{{ threescale_apicast_git_repo }}' + dest: '{{ tempfile.path }}' + version: '{{ threescale_apicast_tag|default(''master'') }}' - name: Create ConfigMap 'apicast-custom-module' - command: chdir={{ tempfile.path }} oc create configmap apicast-custom-module --from-file=cors.lua -n "{{ threescale_project }}" + command: chdir={{ tempfile.path }} oc create configmap apicast-custom-module --from-file=examples/cors/cors.lua -n "{{ threescale_project }}" register: oc failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr changed_when: oc.rc == 0 - name: Create ConfigMap 'cors-conf' - command: chdir={{ tempfile.path }} oc create configmap apicast.d --from-file=cors.conf -n "{{ threescale_project }}" + command: chdir={{ tempfile.path }} oc create configmap apicast.d --from-file=examples/cors/cors.conf -n "{{ threescale_project }}" register: oc failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr changed_when: oc.rc == 0 diff --git a/roles/3scale/tasks/configure_apicast_for_oauth.yml b/roles/3scale/tasks/configure_apicast_for_oauth.yml deleted file mode 100644 index 1505c9e..0000000 --- a/roles/3scale/tasks/configure_apicast_for_oauth.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- - - - name: Update the APICast DeploymentConfig to point to RH-SSO - command: oc env dc/{{ item }} -n {{ threescale_project }} RHSSO_ENDPOINT=https://{{ sso_route_name }}/auth/realms/{{ sso_realm }} - - - name: Deploy latest revision of APICast DeploymentConfig - command: oc rollout latest dc/{{ item }} -n {{ threescale_project }} diff --git a/roles/3scale/tasks/main.yml b/roles/3scale/tasks/main.yml index d77b4a1..18838f7 100644 --- a/roles/3scale/tasks/main.yml +++ b/roles/3scale/tasks/main.yml @@ -20,16 +20,17 @@ - name: Fetch the latest 3scale AMP template from the 3scale repo uri: url={{threescale_template}} return_content=yes register: template + when: deploy_needed - name: Parse the YAML file set_fact: template: '{{template.content |from_yaml }}' - when: "threescale_template_format|upper == 'YAML'" + when: "deploy_needed and threescale_template_format|upper == 'YAML'" - name: Parse the JSON file set_fact: template: '{{template.content |from_json }}' - when: "threescale_template_format|upper == 'JSON'" + when: "deploy_needed and threescale_template_format|upper == 'JSON'" - name: Disable the triggers and set the replicas to 0 set_fact: @@ -40,13 +41,16 @@ {% endif -%} {% endfor -%} {{ template }} + when: deploy_needed - name: Create a temporary directory tempfile: state=directory register: tempfile + when: deploy_needed - name: Write the template template: src=amp.json dest={{tempfile.path}}/amp.json + when: deploy_needed - name: Process the OpenShift Template and create the OpenShift objects for the 3scale API Management Platform shell: oc process -f "{{tempfile.path}}/amp.json" -p "TENANT_NAME={{ threescale_tenant_name }}" -p "WILDCARD_DOMAIN={{ threescale_wildcard_domain }}" -n "{{ threescale_project }}" | oc create -f - -n "{{ threescale_project }}" @@ -69,23 +73,25 @@ project: "{{ threescale_project }}" tags: status - - name: Deploy the storage tier (MySQL, Redis and Memcache) without any replicas + - name: Deploy the storage tier (MySQL, Redis, PostgreSQL and Memcache) without any replicas command: oc rollout latest "{{ item }}" -n "{{ threescale_project }}" with_items: - backend-redis - system-memcache - system-mysql - system-redis + - zync-database when: item not in deployment_configs tags: rollout - - name: Scale the storage tier (MySQL, Redis and Memcache) + - name: Scale the storage tier (MySQL, Redis, PostgreSQL and Memcache) command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_project }}" with_items: - backend-redis - system-memcache - system-mysql - system-redis + - zync-database when: item not in replication_controllers tags: rollout @@ -97,6 +103,7 @@ - system-memcache - system-mysql - system-redis + - zync-database delay: "{{ threescale_delay }}" retries: "{{ threescale_retries }}" project: "{{ threescale_project }}" @@ -137,6 +144,8 @@ - system-sphinx - apicast-staging - apicast-production + - apicast-wildcard-router + - zync when: item not in deployment_configs tags: rollout @@ -182,15 +191,11 @@ project: "{{ threescale_project }}" tags: status - - include: configure_apicast_for_oauth.yml - with_items: - - apicast-staging - - apicast-production - tags: oauth - - - name: Deploy apicast-staging, apicast-production + - name: Deploy zync, apicast-staging, apicast-production command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_project }}" with_items: + - zync + - apicast-wildcard-router - apicast-staging - apicast-production when: item not in replication_controllers @@ -240,9 +245,7 @@ - include: oauth-client.yml tags: oauth-client - - - include: webhooks.yml - tags: webhooks + when: 'not is_offline|default(False)|bool' - name: Get Admin Username command: oc get dc system-app -n "{{ threescale_project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_LOGIN")].value}'