From e658f7e23c8610e6bf00fb802750f9b8c62bc117 Mon Sep 17 00:00:00 2001 From: Jakub Filipczak <79512239+jfilipcz@users.noreply.github.com> Date: Mon, 7 Feb 2022 22:50:05 +0100 Subject: [PATCH] Introduce support for `helm install` (#170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- roles/openshift-applier/README.md | 1 + roles/openshift-applier/defaults/main.yml | 25 +++++++++++++++++-- .../openshift-applier/tasks/process-helm.yml | 14 ++++------- .../tasks/process-template.yml | 8 +----- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/roles/openshift-applier/README.md b/roles/openshift-applier/README.md index 58ef1be..35218b7 100644 --- a/roles/openshift-applier/README.md +++ b/roles/openshift-applier/README.md @@ -76,6 +76,7 @@ openshift_cluster_content: - name: helm: name: # Required + action: # Optional: defaults to 'template' chart: # Required version: # Optional namespace: # Optional diff --git a/roles/openshift-applier/defaults/main.yml b/roles/openshift-applier/defaults/main.yml index 62f8e43..ec2fbee 100644 --- a/roles/openshift-applier/defaults/main.yml +++ b/roles/openshift-applier/defaults/main.yml @@ -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 }} + diff --git a/roles/openshift-applier/tasks/process-helm.yml b/roles/openshift-applier/tasks/process-helm.yml index b526f55..b3b235c 100644 --- a/roles/openshift-applier/tasks/process-helm.yml +++ b/roles/openshift-applier/tasks/process-helm.yml @@ -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: @@ -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: diff --git a/roles/openshift-applier/tasks/process-template.yml b/roles/openshift-applier/tasks/process-template.yml index 1343589..82cdba0 100644 --- a/roles/openshift-applier/tasks/process-template.yml +++ b/roles/openshift-applier/tasks/process-template.yml @@ -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: