mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-13 13:02:01 +00:00
Helm uninstall now support wait parameter (#235)
Helm uninstall now support wait parameter SUMMARY closes #33 ISSUE TYPE Feature Pull Request COMPONENT NAME ADDITIONAL INFORMATION - helm: chart_name: test state: absent wait: yes Reviewed-by: Abhijeet Kasurde <None> Reviewed-by: Mike Graves <mgraves@redhat.com> Reviewed-by: None <None> Reviewed-by: None <None>
This commit is contained in:
93
molecule/default/roles/helm/library/helm_test_version.py
Normal file
93
molecule/default/roles/helm/library/helm_test_version.py
Normal file
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright: (c) 2021, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: helm_test_version
|
||||
short_description: check helm executable version
|
||||
author:
|
||||
- Aubin Bikouo (@abikouo)
|
||||
requirements:
|
||||
- "helm (https://github.com/helm/helm/releases)"
|
||||
description:
|
||||
- validate version of helm binary is lower than the specified version.
|
||||
options:
|
||||
binary_path:
|
||||
description:
|
||||
- The path of a helm binary to use.
|
||||
required: false
|
||||
type: path
|
||||
version:
|
||||
description:
|
||||
- version to test against helm binary.
|
||||
type: str
|
||||
default: 3.7.0
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
- name: validate helm binary version is lower than 3.5.0
|
||||
helm_test_version:
|
||||
binary_path: path/to/helm
|
||||
version: "3.5.0"
|
||||
'''
|
||||
|
||||
RETURN = r'''
|
||||
message:
|
||||
type: str
|
||||
description: Text message describing the test result.
|
||||
returned: always
|
||||
sample: 'version installed: 3.4.5 is lower than version 3.5.0'
|
||||
result:
|
||||
type: bool
|
||||
description: Test result.
|
||||
returned: always
|
||||
sample: 1
|
||||
'''
|
||||
|
||||
import re
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
binary_path=dict(type='path'),
|
||||
version=dict(type='str', default='3.7.0'),
|
||||
),
|
||||
)
|
||||
|
||||
bin_path = module.params.get('binary_path')
|
||||
version = module.params.get('version')
|
||||
|
||||
if bin_path is not None:
|
||||
helm_cmd_common = bin_path
|
||||
else:
|
||||
helm_cmd_common = 'helm'
|
||||
|
||||
helm_cmd_common = module.get_bin_path(helm_cmd_common, required=True)
|
||||
rc, out, err = module.run_command([helm_cmd_common, "version"])
|
||||
if rc != 0:
|
||||
module.fail_json(msg="helm version failed.", err=err, out=out, rc=rc)
|
||||
|
||||
m = re.match(r'version.BuildInfo{Version:"v([0-9\.]*)",', out)
|
||||
installed_version = m.group(1)
|
||||
|
||||
message = "version installed: %s" % installed_version
|
||||
if LooseVersion(installed_version) < LooseVersion(version):
|
||||
message += " is lower than version %s" % version
|
||||
module.exit_json(changed=False, result=True, message=message)
|
||||
else:
|
||||
message += " is greater than version %s" % version
|
||||
module.exit_json(changed=False, result=False, message=message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -33,6 +33,9 @@
|
||||
- name: Test helm diff
|
||||
include_tasks: tests_helm_diff.yml
|
||||
|
||||
- name: Test helm uninstall
|
||||
include_tasks: test_helm_uninstall.yml
|
||||
|
||||
# https://github.com/ansible-collections/community.kubernetes/issues/296
|
||||
- name: Test Skip CRDS feature in helm chart install
|
||||
include_tasks: test_crds.yml
|
||||
|
||||
81
molecule/default/roles/helm/tasks/test_helm_uninstall.yml
Normal file
81
molecule/default/roles/helm/tasks/test_helm_uninstall.yml
Normal file
@@ -0,0 +1,81 @@
|
||||
- name: validate helm version lower than 3.7.0
|
||||
helm_test_version:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
version: "3.7.0"
|
||||
register: test_version
|
||||
|
||||
- block:
|
||||
- set_fact:
|
||||
chart_source: "https://github.com/kubernetes/kube-state-metrics/releases/download/kube-state-metrics-helm-chart-2.13.3/kube-state-metrics-2.13.3.tgz"
|
||||
chart_name: "test-wait-uninstall"
|
||||
|
||||
- name: Install chart
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: "{{ chart_name }}"
|
||||
chart_ref: "{{ chart_source }}"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
create_namespace: true
|
||||
|
||||
- name: Delete chart with wait
|
||||
helm:
|
||||
state: absent
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: "{{ chart_name }}"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
wait: yes
|
||||
register: uninstall
|
||||
|
||||
- name: assert warning has been raised
|
||||
assert:
|
||||
that:
|
||||
- uninstall.warnings
|
||||
|
||||
- name: Create temp directory
|
||||
tempfile:
|
||||
state: directory
|
||||
suffix: .test
|
||||
register: _result
|
||||
|
||||
- set_fact:
|
||||
helm_tmp_dir: "{{ _result.path }}"
|
||||
|
||||
- name: Unarchive Helm binary
|
||||
unarchive:
|
||||
src: 'https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz'
|
||||
dest: "{{ helm_tmp_dir }}"
|
||||
remote_src: yes
|
||||
|
||||
- name: Install chart
|
||||
helm:
|
||||
binary_path: "{{ helm_tmp_dir }}/linux-amd64/helm"
|
||||
name: "{{ chart_name }}"
|
||||
chart_ref: "{{ chart_source }}"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
create_namespace: true
|
||||
|
||||
- name: uninstall chart again using recent version
|
||||
helm:
|
||||
state: absent
|
||||
binary_path: "{{ helm_tmp_dir }}/linux-amd64/helm"
|
||||
name: "{{ chart_name }}"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
wait: yes
|
||||
register: uninstall
|
||||
|
||||
always:
|
||||
- name: Delete temp directory
|
||||
file:
|
||||
path: "{{ helm_tmp_dir }}"
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
|
||||
- name: Remove namespace
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: "{{ helm_namespace }}"
|
||||
state: absent
|
||||
wait: true
|
||||
wait_timeout: 180
|
||||
ignore_errors: true
|
||||
when: test_version.result
|
||||
Reference in New Issue
Block a user