Split Helm v2 setup to separate playbook 24/117124/2
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 26 Jan 2021 08:35:25 +0000 (09:35 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 26 Jan 2021 08:39:21 +0000 (08:39 +0000)
Logically splitting the application playbook to put
Helm v2 and v3 specific setup actions into separate
tasks file.

Change-Id: I20446a196bb2687e27fdeb6a45a83565b676fc42
Issue-ID: OOM-2665
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
ansible/roles/application/molecule/default/tests/test_default.py
ansible/roles/application/tasks/install.yml
ansible/roles/application/tasks/setup-helm2.yml

index df50c47..1451a8f 100644 (file)
@@ -10,10 +10,7 @@ def test_helm_commands(host):
     fc = host.file('/tmp/helm_simu_output').content_string
     helm_release = host.ansible.get_variables()['helm_version']
     if helm_release == 'v2':
-        content_str1 = 'home'
-    elif helm_release == 'v3':
-        content_str1 = 'env'
-    expected_content = content_str1 + """
+        expected_content = """home
 init --upgrade --skip-refresh
 version --tiller-connection-timeout 10
 repo list
@@ -23,6 +20,12 @@ repo add local http://127.0.0.1:8879
 deploy moleculetestapp local/moleculetestapp --namespace \
 moleculetestapp -f /opt/moleculetestapp/helm_charts/onap/resources/\
 overrides/onap-all.yaml -f /opt/moleculetestapp/override.yaml \
+--timeout 1800"""
+    elif helm_release == 'v3':
+        expected_content = """env
+deploy moleculetestapp local/moleculetestapp --namespace \
+moleculetestapp -f /opt/moleculetestapp/helm_charts/onap/resources/\
+overrides/onap-all.yaml -f /opt/moleculetestapp/override.yaml \
 --timeout 1800"""
     assert fc == expected_content
 
index 9e27e2d..fdb74af 100644 (file)
@@ -1,51 +1,4 @@
 ---
-- name: Helm init and upgrade
-  command: |
-     {{ helm_bin_dir }}/helm init
-     --upgrade
-     --skip-refresh
-  changed_when: true  # init is always changed type of action
-
-# A correct way to implement this would be using --wait option in helm init invocation.
-# However, it does not work due to https://github.com/helm/helm/issues/4031 (fixed in newer helm release)
-- name: "Wait for helm upgrade to finish"
-  command: "{{ helm_bin_dir }}/helm version --tiller-connection-timeout 10"
-  register: result
-  until: result.rc == 0
-  delay: 10
-  retries: 12
-  changed_when: false  # for idempotency
-
-- name: Get all helm repos
-  command: "{{ helm_bin_dir }}/helm repo list"
-  register: repos
-  changed_when: false  # for idempotency
-
-- name: Remove stable repo
-  command: "{{ helm_bin_dir }}/helm repo remove stable"
-  changed_when: true  # when executed its a changed type of action
-  when: "'stable' in repos.stdout"
-
-- name: Helm Serve
-  shell: "{{ helm_bin_dir }}/helm serve &"
-  async: 45
-  poll: 3  # wait 3sec to get a chance for some stderr
-  register: helm_serve
-  changed_when: "'address already in use' not in helm_serve.stderr"
-
-- name: List helm repos
-  command: "{{ helm_bin_dir }}/helm repo list"
-  register: helm_repo_list
-  changed_when: false  # for idempotency
-  failed_when:
-    - helm_repo_list.rc > 0
-    - "'Error: no repositories to show' not in helm_repo_list.stderr"
-
-- name: Helm Add Repo
-  command: "{{ helm_bin_dir }}/helm repo add {{ helm_repository_name | mandatory }} {{ helm_repository_url | mandatory }}"
-  when: "'local' not in helm_repo_list.stdout"
-  changed_when: true  # when executed its a changed type of action
-
 # Make utility is missing in Ubuntu by default and it's necessary for building local helm repository
 - name: Install build-essential
   package:
@@ -53,6 +6,11 @@
     state: present
   when: ansible_os_family == "Debian"
 
+- include_tasks: setup-helm2.yml
+  when: helm_version | regex_search("^v2" )
+- include_tasks: setup-helm3.yml
+  when: helm_version | regex_search("^v3" )
+
 - name: Build local helm repository
   make:
     chdir: "{{ app_helm_charts_infra_directory }}"
   debug:
     var: helm_override_files
 
-- include_tasks: setup-helm2.yml
-  when: helm_version | regex_search("^v2" )
-- include_tasks: setup-helm3.yml
-  when: helm_version | regex_search("^v3" )
-
 - name: "Helm Install application {{ app_name }}"
   command: >
           {{ helm_bin_dir }}/helm
index 77f0ee9..8479e1a 100644 (file)
@@ -1,4 +1,51 @@
 ---
+- name: Helm init and upgrade
+  command: |
+     {{ helm_bin_dir }}/helm init
+     --upgrade
+     --skip-refresh
+  changed_when: true  # init is always changed type of action
+
+# A correct way to implement this would be using --wait option in helm init invocation.
+# However, it does not work due to https://github.com/helm/helm/issues/4031 (fixed in newer helm release)
+- name: "Wait for helm upgrade to finish"
+  command: "{{ helm_bin_dir }}/helm version --tiller-connection-timeout 10"
+  register: result
+  until: result.rc == 0
+  delay: 10
+  retries: 12
+  changed_when: false  # for idempotency
+
+- name: Get all helm repos
+  command: "{{ helm_bin_dir }}/helm repo list"
+  register: repos
+  changed_when: false  # for idempotency
+
+- name: Remove stable repo
+  command: "{{ helm_bin_dir }}/helm repo remove stable"
+  changed_when: true  # when executed its a changed type of action
+  when: "'stable' in repos.stdout"
+
+- name: Helm Serve
+  shell: "{{ helm_bin_dir }}/helm serve &"
+  async: 45
+  poll: 3  # wait 3sec to get a chance for some stderr
+  register: helm_serve
+  changed_when: "'address already in use' not in helm_serve.stderr"
+
+- name: List helm repos
+  command: "{{ helm_bin_dir }}/helm repo list"
+  register: helm_repo_list
+  changed_when: false  # for idempotency
+  failed_when:
+    - helm_repo_list.rc > 0
+    - "'Error: no repositories to show' not in helm_repo_list.stderr"
+
+- name: Helm Add Repo
+  command: "{{ helm_bin_dir }}/helm repo add {{ helm_repository_name | mandatory }} {{ helm_repository_url | mandatory }}"
+  when: "'local' not in helm_repo_list.stdout"
+  changed_when: true  # when executed its a changed type of action
+
 - name: Check for deploy plugin presence
   stat:
     path: '{{ helm_home_dir.stdout }}/plugins/deploy/deploy.sh'