Add Helm v3 plugin deployment playbook 09/117109/3
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Fri, 22 Jan 2021 14:09:51 +0000 (15:09 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 26 Jan 2021 08:34:31 +0000 (08:34 +0000)
Change-Id: I3999dd64dd87f163a3306b74cec88019d821759e
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/molecule/helm3/Dockerfile.j2 [new symlink]
ansible/roles/application/molecule/helm3/molecule.yml [new file with mode: 0644]
ansible/roles/application/molecule/helm3/tests [new symlink]
ansible/roles/application/tasks/install-helm3-plugins.yml [new file with mode: 0644]
ansible/roles/application/tasks/install.yml
ansible/roles/application/tasks/setup-helm2.yml [new file with mode: 0644]
ansible/roles/application/tasks/setup-helm3.yml [new file with mode: 0644]
ansible/roles/application/tasks/transfer-helm-charts.yml

index 22298e3..21fc40e 100644 (file)
@@ -8,7 +8,12 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
 def test_helm_commands(host):
     fc = host.file('/tmp/helm_simu_output').content_string
-    expected_content = """home
+    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 + """
 init --upgrade --skip-refresh
 version --tiller-connection-timeout 10
 repo list
diff --git a/ansible/roles/application/molecule/helm3/Dockerfile.j2 b/ansible/roles/application/molecule/helm3/Dockerfile.j2
new file mode 120000 (symlink)
index 0000000..867ec5c
--- /dev/null
@@ -0,0 +1 @@
+../default/Dockerfile.j2
\ No newline at end of file
diff --git a/ansible/roles/application/molecule/helm3/molecule.yml b/ansible/roles/application/molecule/helm3/molecule.yml
new file mode 100644 (file)
index 0000000..fce5909
--- /dev/null
@@ -0,0 +1,54 @@
+---
+dependency:
+  name: galaxy
+driver:
+  name: docker
+lint:
+  name: yamllint
+platforms:
+  - name: instance-helm3
+    image: centos:7
+provisioner:
+  name: ansible
+  env:
+    ANSIBLE_ROLES_PATH: ../../../../test/roles
+  inventory:
+    group_vars:
+      all:
+        app_name: moleculetestapp
+        app_data_path: "/opt/{{ app_name }}"
+        app_helm_release_name: "{{ app_name }}"
+        app_kubernetes_namespace: "{{ app_name }}"
+        app_helm_charts_install_directory: application/helm_charts
+        app_helm_plugins_directory: "{{ app_helm_charts_install_directory}}/helm/plugins/"
+        app_helm_charts_infra_directory: "{{ app_data_path }}/helm_charts"
+        helm_bin_dir: /usr/local/bin
+        app_helm_build_targets:
+          - all
+          - onap
+        app_helm_chart_name: "{{ app_name }}"
+        helm_version: v3
+  lint:
+    name: ansible-lint
+  playbooks:
+    prepare: ../default/prepare.yml
+    converge: ../default/playbook.yml
+    cleanup: ../default/cleanup.yml
+scenario:
+  name: helm3
+  test_sequence:
+    - lint
+    - cleanup
+    - destroy
+    - dependency
+    - syntax
+    - create
+    - prepare
+    - converge
+    - verify
+    - cleanup
+    - destroy
+verifier:
+  name: testinfra
+  lint:
+    name: flake8
diff --git a/ansible/roles/application/molecule/helm3/tests b/ansible/roles/application/molecule/helm3/tests
new file mode 120000 (symlink)
index 0000000..b8ac440
--- /dev/null
@@ -0,0 +1 @@
+../default/tests/
\ No newline at end of file
diff --git a/ansible/roles/application/tasks/install-helm3-plugins.yml b/ansible/roles/application/tasks/install-helm3-plugins.yml
new file mode 100644 (file)
index 0000000..da402f3
--- /dev/null
@@ -0,0 +1,33 @@
+---
+- name: Install helm plugins if needed
+  block:
+    - name: Get helm environment information
+      command: "{{ helm_bin_dir }}/helm env"
+      register: helm_env
+    - name: Set helm data dir
+      set_fact:
+        helm_data_dir: |
+          "{% if 'HELM_DATA_HOME' in helm_env.stdout %}
+           {{ (helm_env.stdout | replace('\"', '') | regex_search('HELM_DATA_HOME.*')).split('=')[1] }}
+           {% else %}
+           {{ '~/.local/share/helm' }}
+           {% endif %}"
+    - name: Ensure that dir for helm plugins exists
+      file:
+        path: "{{ helm_data_dir }}/plugins"
+        state: directory
+        mode: 0755
+    - name: Register all plugins to be inserted by dir names
+      find:
+        paths: "{{ app_helm_plugins_directory }}"
+        file_type: "directory"
+      register: list_of_plugins
+      delegate_to: localhost
+    - name: Install all helm plugins from {{ app_helm_plugins_directory }} dir
+      copy:
+        src: "{{ item.path }}"
+        dest: "{{ helm_data_dir }}/plugins"
+        directory_mode: true
+        mode: 0755
+      loop: "{{ list_of_plugins.files }}"
+  when: app_helm_plugins_directory is defined and app_helm_plugins_directory is not none
index 81e145a..9e27e2d 100644 (file)
   debug:
     var: helm_override_files
 
-- name: Check for deploy plugin presence
-  stat:
-    path: '{{ helm_home_dir.stdout }}/plugins/deploy/deploy.sh'
-  register: deploy_plugin_presence
+- 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: >
diff --git a/ansible/roles/application/tasks/setup-helm2.yml b/ansible/roles/application/tasks/setup-helm2.yml
new file mode 100644 (file)
index 0000000..77f0ee9
--- /dev/null
@@ -0,0 +1,5 @@
+---
+- name: Check for deploy plugin presence
+  stat:
+    path: '{{ helm_home_dir.stdout }}/plugins/deploy/deploy.sh'
+  register: deploy_plugin_presence
diff --git a/ansible/roles/application/tasks/setup-helm3.yml b/ansible/roles/application/tasks/setup-helm3.yml
new file mode 100644 (file)
index 0000000..ce8cbb3
--- /dev/null
@@ -0,0 +1,5 @@
+---
+- name: Check for deploy plugin presence
+  stat:
+    path: '{{ helm_data_dir }}/plugins/deploy/deploy.sh'
+  register: deploy_plugin_presence
index ac91073..2101a5a 100644 (file)
@@ -22,3 +22,5 @@
 
 - include_tasks: install-helm2-plugins.yml
   when: helm_version | regex_search("^v2" )
+- include_tasks: install-helm3-plugins.yml
+  when: helm_version | regex_search("^v3" )