Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into helm_login
Browse files Browse the repository at this point in the history
this commit bring a fix for the integration text merged witin the PR #830
  • Loading branch information
yurnov committed Dec 17, 2024
2 parents a80fb34 + 6609abd commit 099b57e
Show file tree
Hide file tree
Showing 24 changed files with 260 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Parameter insecure_registry added to helm_template as equivalent of insecure-skip-tls-verify (https://github.com/ansible-collections/kubernetes.core/pull/805).
20 changes: 20 additions & 0 deletions docs/kubernetes.core.helm_template_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@ Parameters
<div>Include custom resource descriptions in rendered templates.</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>insecure_registry</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 5.1.0</div>
</td>
<td>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li><div style="color: blue"><b>no</b>&nbsp;&larr;</div></li>
<li>yes</li>
</ul>
</td>
<td>
<div>Skip TLS certificate checks for the chart download</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
14 changes: 14 additions & 0 deletions plugins/modules/helm_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@
- If the directory already exists, it will be overwritten.
required: false
type: path
insecure_registry:
description:
- Skip TLS certificate checks for the chart download
required: false
type: bool
default: false
version_added: 5.1.0
release_name:
description:
- Release name to use in rendered templates.
Expand Down Expand Up @@ -221,6 +228,7 @@ def template(
dependency_update=None,
disable_hook=None,
output_dir=None,
insecure_registry=None,
show_only=None,
release_name=None,
release_namespace=None,
Expand Down Expand Up @@ -251,6 +259,9 @@ def template(
if output_dir:
cmd += " --output-dir=" + output_dir

if insecure_registry:
cmd += " --insecure-skip-tls-verify"

if show_only:
for template in show_only:
cmd += " -s " + template
Expand Down Expand Up @@ -289,6 +300,7 @@ def main():
include_crds=dict(type="bool", default=False),
release_name=dict(type="str", aliases=["name"]),
output_dir=dict(type="path"),
insecure_registry=dict(type="bool", default=False),
release_namespace=dict(type="str"),
release_values=dict(type="dict", default={}, aliases=["values"]),
show_only=dict(type="list", default=[], elements="str"),
Expand All @@ -308,6 +320,7 @@ def main():
include_crds = module.params.get("include_crds")
release_name = module.params.get("release_name")
output_dir = module.params.get("output_dir")
insecure_registry = module.params.get("insecure_registry")
show_only = module.params.get("show_only")
release_namespace = module.params.get("release_namespace")
release_values = module.params.get("release_values")
Expand Down Expand Up @@ -337,6 +350,7 @@ def main():
disable_hook=disable_hook,
release_name=release_name,
output_dir=output_dir,
insecure_registry=insecure_registry,
release_namespace=release_namespace,
release_values=release_values,
show_only=show_only,
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/k8s_drain.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
kubernetes.core.k8s_drain:
state: drain
name: foo
force: yes
delete_options:
force: yes
- name: Drain node "foo", but abort if there are pods not managed by a ReplicationController, Job, or DaemonSet, and use a grace period of 15 minutes.
kubernetes.core.k8s_drain:
Expand Down
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
Loading

0 comments on commit 099b57e

Please sign in to comment.