Skip to content

Commit

Permalink
Merge pull request #153 from dirgim/support-template-overwrite
Browse files Browse the repository at this point in the history
Add support for template overwriting
  • Loading branch information
dirgim authored Mar 25, 2019
2 parents 1c7dac4 + 59eacfe commit aa7b8ae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ or only certain components. ex. minishift, jenkins infra, pipeline containers,

* force_minishift_install: Override an existing install of minishift : default=false
* force_repo_clone: Force cloning of project repo : default=false
* force_template_overwrite: Force overwriting of OpenShift templates and their resources if they already exist : default=false

## Minishift and OpenShift setup options

Expand Down
3 changes: 3 additions & 0 deletions playbooks/group_vars/all/global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ setup_playbook_hooks: false
force_minishift_install: false
force_repo_clone: false

# Overwrite templates and their objects if they already exist
force_template_overwrite: false

# Use General DNS in case of VPN DNS failures
dns_server: 8.8.8.8

Expand Down
2 changes: 1 addition & 1 deletion playbooks/roles/os_temps/tasks/build_new_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- name: "{{ container_config_name }} :: Wait for {{ build_config_name_files[template_name] }} to be queued"
shell: "{{ oc_bin }} get builds | egrep \"{{ build_config_name_files[template_name] }}-[0-9]*\\s\" | sort -V | tail -n 1"
register: oc_build_result
until: oc_build_result.stdout.find(" Running ") != -1 or oc_build_result.stdout.find(" Failed ") != -1
until: oc_build_result.stdout.find(" Running ") != -1 or oc_build_result.stdout.find(" Failed ") != -1 or oc_build_result.stdout.find(" Completed ") != -1
retries: 6
delay: 10
ignore_errors: yes
Expand Down
12 changes: 12 additions & 0 deletions playbooks/roles/os_temps/tasks/setup_os_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
- debug:
msg: "{{ container_config_name }} :: Template Name from querying the cluster: {{ template_name_check.stdout }}"

- name: "{{ container_config_name }} :: The template {{ template_name }} already exists, finding the label applied to all its objects"
shell: "{{ oc_bin }} describe templates/{{ template_name_check.stdout }} | grep \"Object Labels:\" | sed 's/Object Labels:\\s*//g' | cut -f1"
register: "template_label"
when: template_name_check.stdout != ""

- name: "{{ container_config_name }} :: The template {{ template_name }} already exists, deleting all its labeled objects so they can be recreated"
shell: "{{ oc_bin }} delete all -l {{ template_label.stdout }}"
when:
- template_name_check.stdout != ""
- template_label.stdout != ""
- force_template_overwrite|bool == true

- name: "{{ container_config_name }} :: Updating template {{ template_name }}"
shell: "{{ oc_bin }} replace -f {{ template_name }}"
when: template_name_check.stdout != ""
Expand Down

0 comments on commit aa7b8ae

Please sign in to comment.