Skip to content

Commit

Permalink
Introduce support for helm install (#170)
Browse files Browse the repository at this point in the history
* Add support for:
* Helm install subcommand
* Timeout parameter for helm install

* Yamllint fixes

* Fix variable name

* Applied changes based on PR CR

* Updated handling of oc_action to be more robust

* Updated handling of oc_action to be more robust

* Updated handling of oc_action to be more robust

Co-authored-by: Øystein Bedin <[email protected]>
  • Loading branch information
jfilipcz and oybed authored Feb 7, 2022
1 parent a140756 commit e658f7e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions roles/openshift-applier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ openshift_cluster_content:
- name: <definition_name>
helm:
name: <helm chart name> # Required
action: <template|install> # Optional: defaults to 'template'
chart: <helm chart source> # Required
version: <chart version to use> # Optional
namespace: <namespace scope> # Optional
Expand Down
25 changes: 23 additions & 2 deletions roles/openshift-applier/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
---
client: oc
default_oc_action: apply

tmp_inv_dir: ''

include_tags: ''
exclude_tags: ''

provision: true

params_from_vars: {}



##########################################################################################
### OpenShift Client options
# these default values are meant to be replaced runtime if other values are to be used
# - for example 'client=kubectl'

client: oc
default_oc_action: apply
oc_ignore_unknown_parameters: true

oc_action_command: >-
| {{ client }} {{ oc_action }} \
{{ target_namespace }} \
-f - \
{{ (oc_action | regex_search('delete')) | ternary(' --ignore-not-found', '') }} \
{{ (client == 'kubectl' and not (oc_action | regex_search('delete|patch'))) | ternary(' --validate=false', '') }} \
{{ flags }}
14 changes: 5 additions & 9 deletions roles/openshift-applier/tasks/process-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
helm_values_option: ''
helm_version_option: "{{ (helm.version|d('')|trim == '') | ternary('', ' --version \"' + helm.version|d('') + '\"') }}"
helm_namespace_option: "{{ (helm.namespace|d('')|trim == '') | ternary('', ' --namespace \"' + helm.namespace|d('') + '\"') }}"
helm_timeout_option: "{{ (helm.timeout|d('')|trim == '') | ternary('', ' --timeout \"' + helm.timeout|d('') + '\"') }}"

- name: "Add helm repo(s) to be used (if applicable)"
block:
Expand All @@ -28,22 +29,17 @@
helm_values_option: "{{ helm_values_option }} --values '{{ item }}'"
loop: "{{ helm.values_param | default([]) }}"

- name: "{{ oc_action | capitalize }} OpenShift objects based on helm template for '{{ entry.object }} : {{ content.name | default(helm.name) }}'"
- name: "Process OpenShift objects based on helm content for '{{ entry.object }} : {{ content.name | default(helm.name) }}'"
shell: >
helm template \
helm {{ helm.action|d('template') }} \
{{ helm.name }} {{ helm.chart }} \
{{ helm_version_option }} \
{{ helm_namespace_option }} \
{{ helm_timeout_option }} \
{{ helm_set_option }} \
{{ helm_values_option }} \
{{ helm.flags|d('') }} \
| \
{{ client }} {{ oc_action }} \
{{ target_namespace }} \
-f - \
{{ (oc_action | regex_search('delete')) | ternary(' --ignore-not-found', '') }} \
{{ (client == 'kubectl' and not (oc_action | regex_search('delete|patch'))) | ternary(' --validate=false', '') }} \
{{ flags }}
{{ (helm.action|d('template') == 'template') | ternary(oc_action_command, '') }}
register: command_result
no_log: "{{ no_log }}"
failed_when:
Expand Down
8 changes: 1 addition & 7 deletions roles/openshift-applier/tasks/process-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,7 @@
{{ oc_param_option }} \
{{ (oc_param_file_item.oc_path|trim == '') | ternary('', ' --param-file="' + oc_param_file_item.oc_path + '"') }} \
{{ oc_ignore_unknown_parameters | ternary('--ignore-unknown-parameters', '') }} \
| \
{{ client }} {{ oc_action }} \
{{ target_namespace }} \
-f - \
{{ (oc_action | regex_search('delete')) | ternary(' --ignore-not-found', '') }} \
{{ (client == 'kubectl' and not (oc_action | regex_search('delete|patch'))) | ternary(' --validate=false', '') }} \
{{ flags }}
{{ oc_action_command }}
register: command_result
no_log: "{{ no_log }}"
failed_when:
Expand Down

0 comments on commit e658f7e

Please sign in to comment.