Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into support_local_env_f…
Browse files Browse the repository at this point in the history
…or_kustomize
  • Loading branch information
yurnov committed Dec 17, 2024
2 parents f24d82a + 6609abd commit c3d3759
Show file tree
Hide file tree
Showing 31 changed files with 285 additions and 83 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).
2 changes: 2 additions & 0 deletions changelogs/fragments/798-drain-pdb-error-message.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- k8s_drain - Improve error message for pod disruption budget when draining a node (https://github.com/ansible-collections/kubernetes.core/issues/797).
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
17 changes: 15 additions & 2 deletions 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 Expand Up @@ -143,6 +144,7 @@
"""

import copy
import json
import time
import traceback
from datetime import datetime
Expand Down Expand Up @@ -187,6 +189,17 @@
HAS_EVICTION_API = False


def format_dynamic_api_exc(exc):
if exc.body:
if exc.headers and exc.headers.get("Content-Type") == "application/json":
message = json.loads(exc.body).get("message")
if message:
return message
return exc.body
else:
return "%s Reason: %s" % (exc.status, exc.reason)


def filter_pods(pods, force, ignore_daemonset, delete_emptydir_data):
k8s_kind_mirror = "kubernetes.io/config.mirror"
daemonSet, unmanaged, mirror, localStorage, to_delete = [], [], [], [], []
Expand Down Expand Up @@ -338,7 +351,7 @@ def evict_pods(self, pods):
if exc.reason != "Not Found":
self._module.fail_json(
msg="Failed to delete pod {0}/{1} due to: {2}".format(
namespace, name, exc.reason
namespace, name, to_native(format_dynamic_api_exc(exc))
)
)
except Exception as exc:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/helm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
loop_control:
loop_var: helm_version
with_items:
- "v3.7.0"
- "v3.8.0"
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
- name: Initial chart installation
helm:
binary_path: "{{ helm_binary }}"
chart_ref: redis
chart_repo_url: https://charts.bitnami.com/bitnami
chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
release_name: test-redis
release_namespace: "{{ helm_namespace }}"
create_namespace: true
Expand All @@ -42,8 +41,7 @@
- name: Upgrade chart using reuse_values=true
helm:
binary_path: "{{ helm_binary }}"
chart_ref: redis
chart_repo_url: https://charts.bitnami.com/bitnami
chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
release_name: test-redis
release_namespace: "{{ helm_namespace }}"
reuse_values: true
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/targets/helm/tasks/tests_chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit) }}"
disable_hook: True
release_name: "MyRelease"
release_namespace: "MyReleaseNamespace"
release_name: "myrelease"
release_namespace: "myreleasenamespace"
show_only:
- "templates/configmap.yaml"
release_values:
Expand All @@ -388,7 +388,7 @@
- result is changed
- result is not failed
- result.rc == 0
- result.command is match(helm_binary+" template MyRelease "+chart_source)
- result.command is match(helm_binary+" template myrelease "+chart_source)
- result.stdout is search("ThisValue")
when: chart_source is search("test-chart")
# limit assertion of test result to controlled (local) chart_source
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
Loading

0 comments on commit c3d3759

Please sign in to comment.