Skip to content

Commit

Permalink
Fix helm integration tests (#830) (#833)
Browse files Browse the repository at this point in the history
SUMMARY
Fix charts ref on integration tests targets
ISSUE TYPE

Bugfix Pull Request

Reviewed-by: Yuriy Novostavskiy
Reviewed-by: Alina Buzachis
(cherry picked from commit 7559b65)

Co-authored-by: Bikouo Aubin <[email protected]>
  • Loading branch information
patchback[bot] and abikouo authored Dec 17, 2024
1 parent e1f52dd commit 410855c
Show file tree
Hide file tree
Showing 20 changed files with 220 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: test-chart-deployment-time
description: A chart with a config map containing the deployment time in data
type: application
version: 0.1.0
appVersion: "default"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ default "ansible-configmap" .Values.myConfigmapName }}
data:
myValue: {{ default "test" .Values.myValue }}
deploymentTime: {{ now }}
1 change: 1 addition & 0 deletions tests/integration/targets/helm_diff/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dependencies:
- remove_namespace
- install_helm
- setup_helm_registry
128 changes: 75 additions & 53 deletions tests/integration/targets/helm_diff/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
- name: Test helm diff functionality
vars:
test_chart_ref: "/tmp/test-chart"
redis_chart_version: '17.0.5'

block:

Expand All @@ -24,7 +23,7 @@
name: test-chart
namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}"
create_namespace: yes
create_namespace: true
register: install

- assert:
Expand All @@ -49,8 +48,8 @@
name: test-chart
namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}"
check_mode: yes
diff: yes
check_mode: true
diff: true
register: diff_result

- name: Check if helm diff check is correct
Expand Down Expand Up @@ -79,7 +78,7 @@
namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}"
check_mode: yes
diff: yes
diff: true
register: diff_result

- name: Check if no diff in check mode when no change
Expand All @@ -101,7 +100,7 @@

- name: Modify values
blockinfile:
create: yes
create: true
path: "{{ test_chart_ref }}/values.yml"
block: |
---
Expand Down Expand Up @@ -206,52 +205,76 @@
- install is not changed

# Test helm diff with chart_repo_url
- name: Define Redis chart values
- name: Uninstall helm diff
helm_plugin:
binary_path: "{{ helm_binary }}"
state: absent
plugin_name: diff
ignore_errors: true

- name: Define chart variables
set_fact:
redis_chart_values:
commonLabels:
phase: testing
company: RedHat
image:
tag: 6.2.6-debian-10-r135
architecture: standalone

- name: Install Redis chart
test_chart_values:
myValue: 'Some ConfigMap data value'
myConfigmapName: 'ansible-config-from-url'
test_chart_version: 0.1.0
test_chart_ref_url: "oci://localhost:6035/testing/test-chart-deployment-time"

- name: Deploy chart to remote registry
block:
- name: Create local directory to copy chart in
ansible.builtin.tempfile:
suffix: .chart
state: directory
register: _tmpd

- name: Copy local registry
ansible.builtin.copy:
dest: "{{ _tmpd.path }}"
src: '{{ role_path }}/files/test-chart-deployment-time'

- name: Push chart to helm registry
ansible.builtin.include_role:
name: push_to_helm_registry
vars:
chart_local_path: '{{ _tmpd.path }}/test-chart-deployment-time'
chart_repo_path: 'testing'
always:
- name: Delete temporary directory
ansible.builtin.file:
state: absent
path: '{{ _tmpd.path }}'

- name: Log into Helm registry
ansible.builtin.command: "{{ helm_binary }} registry login -u testuser -p 'pass123!' localhost:6035"

- name: Install chart from remote URL
helm:
binary_path: "{{ helm_binary }}"
chart_repo_url: https://charts.bitnami.com/bitnami
chart_ref: redis
chart_ref: "{{ test_chart_ref_url }}"
chart_version: 0.1.0
namespace: "{{ helm_namespace }}"
name: redis-chart
chart_version: "{{ redis_chart_version }}"
release_values: "{{ redis_chart_values }}"
name: another-chart
release_values: "{{ test_chart_values }}"

- name: Upgrade Redis chart
- name: Upgrade chart
helm:
binary_path: "{{ helm_binary }}"
chart_repo_url: https://charts.bitnami.com/bitnami
chart_ref: redis
chart_ref: "{{ test_chart_ref_url }}"
chart_version: 0.1.0
namespace: "{{ helm_namespace }}"
name: redis-chart
chart_version: "{{ redis_chart_version }}"
release_values: "{{ redis_chart_values }}"
check_mode: yes
register: redis_upgrade
name: another-chart
release_values: "{{ test_chart_values }}"
check_mode: true
register: _upgrade

- name: Assert that module raised a warning
assert:
that:
- not redis_upgrade.changed
- redis_upgrade.warnings is defined
- redis_upgrade.warnings | length == 1
- redis_upgrade.warnings[0] == "The default idempotency check can fail to report changes in certain cases. Install helm diff >= 3.4.1 for better results."

- name: Uninstall helm diff
helm_plugin:
binary_path: "{{ helm_binary }}"
state: absent
plugin_name: diff
ignore_errors: yes
- not _upgrade.changed
- _upgrade.warnings is defined
- _upgrade.warnings | length == 1
- _upgrade.warnings[0] == "The default idempotency check can fail to report changes in certain cases. Install helm diff >= 3.4.1 for better results."

- name: Install helm diff (version=3.4.1)
helm_plugin:
Expand All @@ -260,37 +283,36 @@
plugin_path: https://github.com/databus23/helm-diff
plugin_version: 3.4.1

- name: Upgrade Redis chart once again
- name: Upgrade chart once again
helm:
binary_path: "{{ helm_binary }}"
chart_repo_url: https://charts.bitnami.com/bitnami
chart_ref: redis
chart_ref: "{{ test_chart_ref_url }}"
chart_version: 0.1.0
namespace: "{{ helm_namespace }}"
name: redis-chart
chart_version: "{{ redis_chart_version }}"
release_values: "{{ redis_chart_values }}"
check_mode: yes
register: redis_upgrade_2
name: another-chart
release_values: "{{ test_chart_values }}"
check_mode: true
register: _upgrade_2

- name: Assert that module raised a warning
assert:
that:
- redis_upgrade_2.changed
- redis_upgrade_2.warnings is not defined
- _upgrade_2.changed
- _upgrade_2.warnings is not defined

always:
- name: Remove chart directory
file:
path: "{{ test_chart_ref }}"
state: absent
ignore_errors: yes
ignore_errors: true

- name: Uninstall helm diff
helm_plugin:
binary_path: "{{ helm_binary }}"
state: absent
plugin_name: diff
ignore_errors: yes
ignore_errors: true

- name: Remove helm namespace
k8s:
Expand All @@ -299,6 +321,6 @@
name: "{{ helm_namespace }}"
state: absent
wait: true
ignore_errors: yes
ignore_errors: true

- include_tasks: reuse_values.yml
27 changes: 16 additions & 11 deletions tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
- set_fact:
saved_kubeconfig_path: "{{ _dir.path }}/config"

- block:
- vars:
helm_repo_name: autoscaler
helm_repo_url: "https://kubernetes.github.io/autoscaler"
helm_release_name: "autoscaler"
helm_chart_name: "cluster-autoscaler"
block:
- name: Copy default kubeconfig
copy:
remote_src: true
Expand Down Expand Up @@ -59,14 +64,14 @@
- plugin_info.plugin_list != []

# helm_repository, helm, helm_info
- name: Add test_bitnami chart repository
- name: 'Add "{{ helm_repo_name }}" chart repository'
helm_repository:
binary_path: "{{ helm_binary }}"
name: test_bitnami
name: "{{ helm_repo_name }}"
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}"
repo_url: https://charts.bitnami.com/bitnami
repo_url: "{{ helm_repo_url }}"
register: repository

- name: Assert that repository was added
Expand All @@ -77,8 +82,8 @@
- name: Install chart from repository added before
helm:
binary_path: "{{ helm_binary }}"
name: rabbitmq
chart_ref: test_bitnami/rabbitmq
name: "{{ helm_release_name }}"
chart_ref: "{{ helm_repo_name }}/{{ helm_chart_name }}"
namespace: "{{ helm_namespace }}"
update_repo_cache: true
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
Expand All @@ -98,7 +103,7 @@
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}"
name: "rabbitmq"
name: "{{ helm_release_name }}"
namespace: "{{ helm_namespace }}"
register: chart_info

Expand All @@ -112,7 +117,7 @@
- name: Remove chart
helm:
binary_path: "{{ helm_binary }}"
name: rabbitmq
name: "{{ helm_release_name }}"
namespace: "{{ helm_namespace }}"
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}"
Expand All @@ -131,7 +136,7 @@
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}"
name: "rabbitmq"
name: "{{ helm_release_name }}"
namespace: "{{ helm_namespace }}"
register: chart_info

Expand All @@ -143,7 +148,7 @@
- name: Remove chart repository
helm_repository:
binary_path: "{{ helm_binary }}"
name: test_bitnami
name: "{{ helm_repo_name }}"
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}"
Expand Down Expand Up @@ -192,6 +197,6 @@
- name: Delete helm repository
helm_repository:
binary_path: "{{ helm_binary }}"
name: test_bitnami
name: "{{ helm_repo_name }}"
state: absent
ignore_errors: true
1 change: 1 addition & 0 deletions tests/integration/targets/push_to_helm_registry/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
helm_binary_path: "helm"
chart_repo_url: 'localhost:6035'
chart_repo_username: testuser
chart_repo_password: 'pass123!'
38 changes: 38 additions & 0 deletions tests/integration/targets/push_to_helm_registry/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
- name: Ensure we can log into the helm registry
command: >-
{{ helm_binary_path }} registry login
-u {{ chart_repo_username }}
-p {{ chart_repo_password }}
{{ chart_repo_url }}
- name: Package chart and push to helm registry
block:
- name: Create temporary directory to store chart
ansible.builtin.tempfile:
state: directory
suffix: .chart
register: _tmpfile

- name: Package helm chart
command: '{{ helm_binary_path }} package {{ chart_local_path }} --destination {{ _tmpfile.path }}'

- name: Locate helm chart package
ansible.builtin.find:
paths: "{{ _tmpfile.path }}"
patterns: '*.tgz'
register: _files

- name: Helm push chart to the registry
command: '{{ helm_binary_path }} push {{ _files.files.0.path }} oci://{{ chart_repo_url }}/{{ chart_repo_path }}'

always:
- name: Logout from registry
command: '{{ helm_binary_path }} registry logout {{ chart_repo_url }}'
ignore_errors: true

- name: Delete temporary directory
ansible.builtin.file:
state: absent
path: '{{ _tmpfile.path }}'
ignore_errors: true
1 change: 1 addition & 0 deletions tests/integration/targets/setup_helm_registry/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# user: testuser, password: pass123!
registry_credentials: testuser:$2y$05$d8tw6L1hojRFW.FjHOAnIOihJWAvFb0/Pu/30hLbQNJIYzCmlyBCi
registry_name: helm_registry
registry_port: 6035
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Teardown registry
include_tasks: teardown_registry.yml
Loading

0 comments on commit 410855c

Please sign in to comment.