Browse Source

fix #12, Always use an up-to-date 3scale AMP template

master
Nicolas Massé 8 years ago
parent
commit
b3ae6d3bf3
  1. 2
      roles/3scale/files/.gitignore
  2. 2837
      roles/3scale/files/amp.json
  3. 9
      roles/3scale/files/get-default-templates.sh
  4. 51
      roles/3scale/tasks/main.yml
  5. 1
      roles/3scale/templates/amp.json
  6. 3
      roles/3scale/vars/main.yml

2
roles/3scale/files/.gitignore

@ -1,2 +0,0 @@
amp.yml

2837
roles/3scale/files/amp.json

File diff suppressed because it is too large

9
roles/3scale/files/get-default-templates.sh

@ -1,9 +0,0 @@
#!/bin/bash
#
# This script gets the original 3scale template, converts it to JSON,
# scales down the DeploymentConfig's replicas to 0 and disable triggers.
#
curl -s -o amp.yml https://raw.githubusercontent.com/3scale/3scale-amp-openshift-templates/2.0.0.GA/amp/amp.yml
yaml2json amp.yml |jq '(.objects[]|select(.kind== "DeploymentConfig").spec.replicas) |= 0 | (.objects[]|select(.kind== "DeploymentConfig").spec.triggers) |= []' > amp.json

51
roles/3scale/tasks/main.yml

@ -17,8 +17,57 @@
- set_fact:
deploy_needed: '{{ deployment_configs|intersect(threescale_expected_deployment_configs)|length < threescale_expected_deployment_configs|length }}'
- name: Fetch the latest 3scale AMP template from the 3scale repo
uri: url={{threescale_template}} return_content=yes
register: template
- name: Parse the YAML file
set_fact:
template: '{{template.content |from_yaml }}'
when: "threescale_template_format|upper == 'YAML'"
- name: Parse the JSON file
set_fact:
template: '{{template.content |from_json }}'
when: "threescale_template_format|upper == 'JSON'"
- name: Disable the triggers and set the replicas to 0
set_fact:
template: >-
{% for obj in template.objects -%}
{% if obj.kind == 'DeploymentConfig' -%}
{% if obj.spec.update({'replicas': 0, 'triggers': []}) -%}{% endif -%}
{% endif -%}
{% endfor -%}
{{ template }}
- name: Patch the template to workaround the subPath bug (https://bugzilla.redhat.com/show_bug.cgi?id=1481617)
set_fact:
template: >-
{% for obj in template.objects -%}
{% if obj.kind == 'DeploymentConfig' -%}
{% for c in obj.spec.template.spec.containers -%}
{% if 'volumeMounts' in c -%}
{% for m in c.volumeMounts -%}
{% if 'subPath' in m -%}
{% if m.update({'subPath': ('..data/' ~ m.subPath) }) -%}{% endif -%}
{% endif -%}
{% endfor -%}
{% endif -%}
{% endfor -%}
{% endif -%}
{% endfor -%}
{{ template }}
- name: Create a temporary directory
tempfile: state=directory
register: tempfile
- name: Write the template
template: src=amp.json dest={{tempfile.path}}/amp.json
- name: Process the OpenShift Template and create the OpenShift objects for the 3scale API Management Platform
shell: oc process -f "{{ threescale_template }}" -p "TENANT_NAME={{ threescale_tenant_name }}" -p "WILDCARD_DOMAIN={{ threescale_wildcard_domain }}" -n "{{ threescale_project }}" | oc create -f - -n "{{ threescale_project }}"
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 }}"
register: oc
failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr
changed_when: oc.rc == 0

1
roles/3scale/templates/amp.json

@ -0,0 +1 @@
{{template|to_json()}}

3
roles/3scale/vars/main.yml

@ -1,6 +1,7 @@
---
threescale_template: https://raw.githubusercontent.com/nmasse-itix/OpenShift-Lab/master/roles/3scale/files/amp.json
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
threescale_tenant_name: 3scale
threescale_wildcard_domain: "{{ openshift_master_default_subdomain }}"

Loading…
Cancel
Save