Add helm_cli & helm_cli_info

This commit is contained in:
LucasBoisserie
2020-03-17 16:16:58 +01:00
parent dd8b7162b1
commit 720326ebb4
17 changed files with 1266 additions and 1 deletions

View File

@@ -2,7 +2,6 @@
- name: Converge
hosts: localhost
connection: local
gather_facts: false
collections:
- community.kubernetes
@@ -27,3 +26,6 @@
- include_tasks: tasks/full.yml
- include_tasks: tasks/exec.yml
- include_tasks: tasks/log.yml
roles:
- helm

View File

@@ -0,0 +1,15 @@
---
helm_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz"
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"
helm_namespace: helm
tiller_namespace: tiller
tiller_cluster_role: cluster-admin
chart_test: "nginx-ingress"
chart_test_version: 1.32.0
chart_test_version_upgrade: 1.33.0
chart_test_repo: "https://kubernetes-charts.storage.googleapis.com"
chart_test_git_repo: "http://github.com/helm/charts.git"
chart_test_values:
revisionHistoryLimit: 0

View File

@@ -0,0 +1,11 @@
---
- name: Init Helm folders
file:
path: /tmp/helm/
state: directory
- name: Unarchive Helm binary
unarchive:
src: 'https://get.helm.sh/{{ helm_archive_name }}'
dest: /tmp/helm/
remote_src: yes

View File

@@ -0,0 +1,8 @@
---
- name: Run tests
include_tasks: run_test.yml
loop_control:
loop_var: helm_version
with_items:
- "v2.16.0"
- "v3.1.2"

View File

@@ -0,0 +1,43 @@
---
- name: Ensure helm is not install
file:
path: "{{ item }}"
state: absent
with_items:
- "/tmp/helm"
- name: Check failed if helm is not install
include_tasks: test_helm_not_installed.yml
- name: "Install {{ helm_version }}"
include_tasks: install.yml
- name: Check if failed when tiller is not installed
include_tasks: test_missing_tiller.yml
when: "helm_version.startswith('v2')"
- name: Install tiller
include_tasks: tiller.yml
when: "helm_version.startswith('v2')"
- name: Deploy charts
include_tasks: "tests_chart/{{ test_chart_type }}.yml"
loop_control:
loop_var: test_chart_type
with_items:
- from_local_path
- from_repository
- from_url
- name: Clean tiller
include_tasks: tiller.yml
vars:
status: absent
when: "helm_version.startswith('v2')"
- name: Clean helm install
file:
path: "{{ item }}"
state: absent
with_items:
- "/tmp/helm/"

View File

@@ -0,0 +1,14 @@
---
- name: Failed test when helm is not install
helm_cli:
binary_path: "{{ helm_binary}}_fake"
name: test
chart_ref: "{{ chart_test }}"
ignore_errors: yes
register: helm_missing_binary
- name: Assert that helm is not installed
assert:
that:
- helm_missing_binary is failed
- "'No such file or directory' in helm_missing_binary.msg"

View File

@@ -0,0 +1,15 @@
---
- name: Failed test when tiller is missing
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_test }}"
tiller_namespace: helm
ignore_errors: yes
register: missing_tiller
- name: Assert that tiller is missing
assert:
that:
- missing_tiller is failed
- "'could not find tiller' in missing_tiller.msg"

View File

@@ -0,0 +1,185 @@
---
- name: Create helm namespace
k8s:
api_version: v1
kind: Namespace
name: "{{ helm_namespace }}"
wait: true
- name: "Install {{ chart_test }} from {{ source }}"
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: "Assert that {{ chart_test }} chart is installed from {{ source }}"
assert:
that:
- install is changed
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}"
- install.status.status | lower == 'deployed'
- name: Check idempotency
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: Assert idempotency
assert:
that:
- install is not changed
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}"
- install.status.status | lower == 'deployed'
- name: "Add vars to {{ chart_test }} from {{ source }}"
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
values: "{{ chart_test_values }}"
register: install
- name: "Assert that {{ chart_test }} chart is upgraded with new var from {{ source }}"
assert:
that:
- install is changed
- install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}"
- "install.status['values'].revisionHistoryLimit == 0"
- name: Check idempotency after add vars
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
values: "{{ chart_test_values }}"
register: install
- name: Assert idempotency after add vars
assert:
that:
- install is not changed
- install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}"
- "install.status['values'].revisionHistoryLimit == 0"
- name: "Remove Vars to {{ chart_test }} from {{ source }}"
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: "Assert that {{ chart_test }} chart is upgraded with new var from {{ source }}"
assert:
that:
- install is changed
- install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}"
- install.status['values'] == {}
- name: Check idempotency after remove vars
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: Assert idempotency after remove vars
assert:
that:
- install is not changed
- install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}"
- install.status['values'] == {}
- name: "Upgrade {{ chart_test }} from {{ source }}"
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source_upgrade | default(chart_source) }}"
chart_version: "{{ chart_source_version_upgrade | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: "Assert that {{ chart_test }} chart is upgraded with new version from {{ source }}"
assert:
that:
- install is changed
- install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version_upgrade }}"
- name: Check idempotency after upgrade
helm_cli:
binary_path: "{{ helm_binary}}"
name: test
chart_ref: "{{ chart_source_upgrade | default(chart_source) }}"
chart_version: "{{ chart_source_version_upgrade | default(omit)}}"
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: Assert idempotency after upgrade
assert:
that:
- install is not changed
- install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version_upgrade }}"
- name: "Remove {{ chart_test }} from {{ source }}"
helm_cli:
binary_path: "{{ helm_binary}}"
state: absent
name: test
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: "Assert that {{ chart_test }} chart is remove from {{ source }}"
assert:
that:
- install is changed
- name: Check idempotency after remove
helm_cli:
binary_path: "{{ helm_binary}}"
state: absent
name: test
namespace: "{{ helm_namespace }}"
tiller_namespace: "{{ tiller_namespace }}"
register: install
- name: Assert idempotency
assert:
that:
- install is not changed
- name: Remove helm namespace
k8s:
api_version: v1
kind: Namespace
name: "{{ helm_namespace }}"
state: absent
wait: true

View File

@@ -0,0 +1,27 @@
---
- name: Git clone stable repo
git:
repo: "{{ chart_test_git_repo }}"
dest: /tmp/helm_test_repo
version: 631eb8413f6728962439488f48d7d6fbb954a6db
- name: Git clone stable repo upgrade
git:
repo: "{{ chart_test_git_repo }}"
dest: /tmp/helm_test_repo_upgrade
version: d37b5025ffc8be49699898369fbb59661e2a8ffb
- name: Install Chart from local path
include_tasks: "../tests_chart.yml"
vars:
source: local_path
chart_source: "/tmp/helm_test_repo/stable/{{ chart_test }}/"
chart_source_upgrade: "/tmp/helm_test_repo_upgrade/stable/{{ chart_test }}/"
- name: Remove clone repos
file:
path: "{{ item }}"
state: absent
with_items:
- /tmp/helm_test_repo
- /tmp/helm_test_repo_upgrade

View File

@@ -0,0 +1,11 @@
---
- name: Add chart repo
shell: "helm repo add stable {{ chart_test_repo }}"
- name: Install Chart from repository
include_tasks: "../tests_chart.yml"
vars:
source: repository
chart_source: "stable/{{ chart_test }}"
chart_source_version: "{{ chart_test_version }}"
chart_source_version_upgrade: "{{ chart_test_version_upgrade }}"

View File

@@ -0,0 +1,7 @@
---
- name: Install Chart from URL
include_tasks: "../tests_chart.yml"
vars:
source: url
chart_source: "{{ chart_test_repo }}/{{ chart_test }}-{{ chart_test_version }}.tgz"
chart_source_upgrade: "{{ chart_test_repo }}/{{ chart_test }}-{{ chart_test_version_upgrade }}.tgz"

View File

@@ -0,0 +1,22 @@
---
- name: Tiller namespace
k8s:
api_version: v1
kind: Namespace
name: "{{ tiller_namespace }}"
state: "{{ status | default('present') }}"
wait: true
- name: Tiller requirements
k8s:
state: "{{ status | default('present') }}"
resource_definition: "{{ lookup('template', item) | from_yaml }}"
wait: true
with_fileglob:
- ../templates/*.yml
- name: deploy tiller
shell: "{{ helm_binary }} init --wait --service-account tiller --tiller-namespace {{ tiller_namespace }}"
environment:
ignore_errors: yes
when: "status | default('present') == 'present'"

View File

@@ -0,0 +1,13 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: "{{ tiller_cluster_role }}"
subjects:
- kind: ServiceAccount
name: tiller
namespace: "{{ tiller_namespace }}"

View File

@@ -0,0 +1,6 @@
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: tiller
namespace: "{{ tiller_namespace }}"