Browse Source

Fix changing urls for the Apicast CORS module

master
Nicolas Massé 8 years ago
parent
commit
8a71c3b332
  1. 10
      roles/3scale/tasks/apicast_cors.yml
  2. 29
      roles/3scale/tasks/patch_apicast.yml
  3. 2
      roles/3scale/vars/main.yml

10
roles/3scale/tasks/apicast_cors.yml

@ -3,20 +3,20 @@
tempfile: state=directory tempfile: state=directory
register: tempfile register: tempfile
- name: Download 'apicast_cors.lua' - name: Download 'cors.lua'
get_url: dest='{{ tempfile.path }}/apicast_cors.lua' url={{ threescale_apicast_cors_lua }} get_url: dest='{{ tempfile.path }}/cors.lua' url={{ threescale_apicast_cors_lua }}
- name: Download 'cors.conf' - name: Download 'cors.conf'
get_url: dest='{{ tempfile.path }}/cors.conf' url={{ threescale_apicast_cors_conf }} get_url: dest='{{ tempfile.path }}/cors.conf' url={{ threescale_apicast_cors_conf }}
- name: Create ConfigMap 'apicast-cors' - name: Create ConfigMap 'apicast-custom-module'
command: chdir={{ tempfile.path }} oc create configmap apicast-cors --from-file=apicast_cors.lua -n "{{ threescale_project }}" command: chdir={{ tempfile.path }} oc create configmap apicast-custom-module --from-file=cors.lua -n "{{ threescale_project }}"
register: oc register: oc
failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr
changed_when: oc.rc == 0 changed_when: oc.rc == 0
- name: Create ConfigMap 'cors-conf' - name: Create ConfigMap 'cors-conf'
command: chdir={{ tempfile.path }} oc create configmap cors-conf --from-file=cors.conf -n "{{ threescale_project }}" command: chdir={{ tempfile.path }} oc create configmap apicast.d --from-file=cors.conf -n "{{ threescale_project }}"
register: oc register: oc
failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr
changed_when: oc.rc == 0 changed_when: oc.rc == 0

29
roles/3scale/tasks/patch_apicast.yml

@ -7,28 +7,13 @@
register: volumes register: volumes
changed_when: false changed_when: false
- name: Add volume 'apicast-cors' - name: Add volume 'apicast-custom-module'
command: 'oc set volume dc/{{ item }} -n {{ threescale_project }} --add --name=apicast-cors --mount-path /opt/app-root/src/src/apicast_cors.lua --source=''{"configMap":{"name":"apicast-cors","items":[{"key":"apicast_cors.lua","path":"apicast_cors.lua"}]}}'' ' command: 'oc set volume dc/{{ item }} -n {{ threescale_project }} --add --name=apicast-custom-module --mount-path /opt/app-root/src/src/custom/ --configmap-name=apicast-custom-module -t configmap'
when: "'apicast-cors' not in volumes.stdout_lines" when: "'apicast-custom-module' not in volumes.stdout_lines"
- name: Add volume 'cors-conf' - name: Add volume 'apicastd'
command: 'oc set volume dc/{{ item }} -n {{ threescale_project }} --add --name=cors-conf --mount-path /opt/app-root/src/apicast.d/cors.conf --source=''{"configMap":{"name":"cors-conf","items":[{"key":"cors.conf","path":"cors.conf"}]}}'' ' command: 'oc set volume dc/{{ item }} -n {{ threescale_project }} --add --name=apicastd --mount-path /opt/app-root/src/apicast.d/ --configmap-name=apicast.d -t configmap'
when: "'cors-conf' not in volumes.stdout_lines" when: "'apicastd' not in volumes.stdout_lines"
- name: Check if APICast's DC has already been patched
command: oc get dc {{ item }} -o jsonpath='{range .spec.template.spec.containers[*].volumeMounts[?(@.subPath)]}{.name}{"\n"}{end}' -n "{{ threescale_project }}"
register: patched
changed_when: false
# TODO: Temporary fix for https://bugzilla.redhat.com/show_bug.cgi?id=1481617. Remove as soon as the bug is fixed (see #13) !
- name: Patch volume 'apicast-cors'
command: 'oc patch dc/{{ item }} -n {{ threescale_project }} --type=json -p ''[ {"op": "add", "path": "/spec/template/spec/containers/0/volumeMounts/0/subPath", "value":"..data/apicast_cors.lua"} ]'' '
when: "'apicast-cors' not in patched.stdout_lines"
# TODO: Temporary fix for https://bugzilla.redhat.com/show_bug.cgi?id=1481617. Remove as soon as the bug is fixed (see #13) !
- name: Patch volume 'cors-conf'
command: 'oc patch dc/{{ item }} -n {{ threescale_project }} --type=json -p ''[ {"op": "add", "path": "/spec/template/spec/containers/0/volumeMounts/1/subPath", "value":"..data/cors.conf"} ]'' '
when: "'cors-conf' not in patched.stdout_lines"
- name: Add environment variable APICAST_MODULE to the APICast DeploymentConfig - name: Add environment variable APICAST_MODULE to the APICast DeploymentConfig
command: oc env dc/{{ item }} APICAST_MODULE=apicast_cors -n {{ threescale_project }} command: oc env dc/{{ item }} APICAST_MODULE=custom/cors -n {{ threescale_project }}

2
roles/3scale/vars/main.yml

@ -7,7 +7,7 @@
threescale_wildcard_domain: "{{ openshift_master_default_subdomain }}" threescale_wildcard_domain: "{{ openshift_master_default_subdomain }}"
threescale_delay: 5 threescale_delay: 5
threescale_retries: 30 threescale_retries: 30
threescale_apicast_cors_lua: https://raw.githubusercontent.com/3scale/apicast/master/examples/cors/apicast_cors.lua 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_apicast_cors_conf: https://raw.githubusercontent.com/3scale/apicast/master/examples/cors/cors.conf
threescale_webhooks_secret: supersecret threescale_webhooks_secret: supersecret
threescale_expected_deployment_configs: threescale_expected_deployment_configs:

Loading…
Cancel
Save