Compare commits

54 Commits
3.2.0 ... 5.1.0

Author SHA1 Message Date
Yuriy Novostavskiy
c93a7e2459 prepare release 5.1.0 (#865)
SUMMARY
This release came with new module helm_registry_auth, and improvements to the error messages in the k8s_drain module, new parameter insecure_registry for helm_template module and several bug fixes.
ISSUE TYPE

New release pull request

Changelog
Minor Changes

Bump version of ansible-lint to minimum 24.7.0 (#765).
Parameter insecure_registry added to helm_template as equivalent of insecure-skip-tls-verify (#805).
connection/kubectl.py - Added an example of using the kubectl connection plugin to the documentation (#741).
k8s_drain - Improve error message for pod disruption budget when draining a node (#797).

Bugfixes

helm - Helm version checks did not support RC versions. They now accept any version tags. (#745).
helm_pull - Apply no_log=True to pass_credentials to silence false positive warning.. (#796).
k8s_drain - Fix k8s_drain does not wait for single pod (#769).
k8s_drain - Fix k8s_drain runs into a timeout when evicting a pod which is part of a stateful set  (#792).
kubeconfig option should not appear in module invocation log (#782).
kustomize - kustomize plugin fails with deprecation warnings (#639).
waiter - Fix waiting for daemonset when desired number of pods is 0. (#756).

New Modules

helm_registry_auth - Helm registry authentication module

ADDITIONAL INFORMATION
Collection kubernets.core version 3.1.0 is compatible with ansible-core>=2.15.0

Reviewed-by: Mike Graves <mgraves@redhat.com>
2025-01-20 15:23:54 +00:00
patchback[bot]
2d68a37a52 trivial doc: replace 2.5.0 with 3.0.0 (#831) (#856)
This is a backport of PR #831 as merged into main (bc0de24).
SUMMARY
Some parameters were added to the master in time where the latest version was 2.4.0 with version_added: 2.5.0, however the next version after 2.4.0 was a 3.0.0.
So, with this trivial doc PR (that most probably doesn't require a changelog fragment and including to changelog) I replacing  version_added: 2.5.0 to  version_added: 3.0.0 for:

reuse_values in kubernetes.core.helm module
reset_values in kubernetes.core.helm module
delete_all in  kubernetes.core.k8s module
hidden_fields  in  kubernetes.core.k8s module
hidden_fields   in  kubernetes.core.k8s_info module

All of them are introduced in kubernetes.core 3.0.0
ISSUE TYPE

Docs Pull Request

COMPONENT NAME

helm
k8s
8s_info


ADDITIONAL INFORMATION
PR to be backported to stable-3 and stable-5
2025-01-17 19:01:57 +00:00
patchback[bot]
c5f5398e9e Remove deprecated .github/stale.yml to address #837 (#838) (#860)
SUMMARY
I noticed that even config for probot/stale is present in the repo, but the old issues and PRs weren't marked as stale and not closed by the bot. Investigated and found that this bot was added to community.kubernetes as ansible-collections/community.kubernetes#53 but wasn't moved to kubernetes.core and never worked here.
Moreover, this bot is completely deprecated and down, ref: probot/stale#430
So, the config to be removed.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
.github/stale.yml
ADDITIONAL INFORMATION
Closes #837
Trivial change that not require changelog

Reviewed-by: Mike Graves <mgraves@redhat.com>
(cherry picked from commit eb731cd3a5)

Co-authored-by: Yuriy Novostavskiy <yuriy@novostavskiy.kiev.ua>
2025-01-17 11:53:31 -05:00
patchback[bot]
05aea7727d helm_pull: Silence false no_log warning (#796) (#858)
This is a backport of PR #796 as merged into main (ecc64ca).
SUMMARY
Apply no_log=True to pass_credentials to silence false positive warning.
Fixes similar issue to: #423
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
changelog/fragements/796-false-positive-helmull.yaml
plugins/modules/helm_pull.py
2025-01-17 16:21:23 +00:00
patchback[bot]
d3f6dd186c fix linters in github actions (#848) (#849)
This is a backport of PR #848 as merged into main (159a63a).
SUMMARY
After the release 25.0.0 of ansible-compat the linters in CI become failing. In the ansible-lint issue already created
COMPONENT NAME
.github/workflows/linters.yaml
ADDITIONAL INFORMATION
Fix bug #846
within this commit ansible/ansible-lint is updated to 24.12.2 and the ansible-lint config moved to the .config folder
2025-01-17 15:52:51 +00:00
patchback[bot]
8cee9fddbe Clean up test namespace (#852) (#854)
This is a backport of PR #852 as merged into main (9f60b15).
SUMMARY

The helm_set_values test target did not clean up its namespace which is leading to unstable tests in the k8s_drain target.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION
2025-01-17 15:29:22 +00:00
patchback[bot]
05a942e41e helm_registry_auth module to authenticate in OCI registry (#800) (#836)
* new module helm_registry_auth

* Initial integration tests

* final update copyright and integration test before pr

* update link to pr in changelog fragment

* reformat plugins/module_utils/helm.py with black

to fix linters in actions

* attempt to fix unit test

unit test was missing initially

* fix https://pycqa.github.io/isort/ linter

* next attemp to fix unit-test

* remove unused and unsupported helm_args_common

* remove unused imports and fix other linters errors

* another fix for unit test

* fix issue introducied by commit ff02893a12a31f9c44b5c48f9a8bf85057295961

* add binary_path to arg_spec

* return helm_cmd in the output of check mode

remove changlog fragment

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* description suggestion from reviewer/maintainer

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* remove changed from module return

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* remove redundant code

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* Update plugins/modules/helm_registry_auth.py

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* consider support of logout when user is not logged in

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* consider support helm < 3.0.0

* Revert "consider support helm < 3.0.0"

This reverts commit f20004d196.

* reintroduce support of helm version less than 3.8.0

reference: https://helm.sh/docs/topics/registries/#enabling-oci-support-prior-to-v380

* revert reintroducing support of helm < 3.8.0

reason: didn't find a quick way to deal with tests

* update documentation with the recent module updates

* Update plugins/modules/helm_registry_auth.py

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* add test of logout impendency

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>

* fix linters

* fix intendations in the integration tests

* create tests/integration/targets/helm_registry_auth/aliases

* fix integration test (typo)

* fix integration tests (test wrong cred)

* add stderr when module fail

* another attempt to fix integration test

* fix assertion in integration test to be not affceted by the #830

---------

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
(cherry picked from commit aee847431a)

Co-authored-by: Yuriy Novostavskiy <yuriy@novostavskiy.kiev.ua>
2024-12-17 18:33:15 +01:00
patchback[bot]
fcd47ca995 Remove kubeconfig value from module invocation log (#826) (#840)
(cherry picked from commit 6efabd3418)

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
2024-12-17 18:32:59 +01:00
patchback[bot]
f1729ce186 fix: typo (#804) (#834)
* fix: typo

replaces https://github.com/ansible-collections/kubernetes.core/pull/799

* doc: add changelog fragment

* Delete changelogs/fragments/804-drain-typo.yaml

---------

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
(cherry picked from commit 219c747a24)

Co-authored-by: Pierre Ozoux <pierre@ozoux.net>
2024-12-17 17:49:56 +01:00
patchback[bot]
c37dc5b566 Parameter insecure_registry added to helm_template (#805) (#835)
* Parameter insecure_registry added to helm_template as equivalent of insecure-skip-tls-verify

(cherry picked from commit 6609abdd5a)

Co-authored-by: Yuriy Novostavskiy <yuriy@novostavskiy.kiev.ua>
2024-12-17 17:47:35 +01:00
patchback[bot]
410855cd36 Fix helm integration tests (#830) (#833)
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 7559b65946)

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
2024-12-17 12:16:41 +01:00
patchback[bot]
e1f52ddbee Fix helm tests (#827) (#828)
This is a backport of PR #827 as merged into main (c8a33c7).
SUMMARY

Some of the charts we've used for testing are no longer available at the old helm repository urls, as they've been moved to oci registries. This updates those charts.
In the longer term, we should find a better way to handle these kinds of test fixtures, probably by switching to local charts as much as possible.

ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
2024-12-16 08:32:45 +00:00
patchback[bot]
5d038db848 Update README.md with removing outdated communication channels (#790) (#825)
This is a backport of PR #790 as merged into main (b8e9873).
SUMMARY
As part of the consolidating Ansible discussion platforms and communication channels was decided to use the Ansible forum as the main place for questions and discussion.
Reference: https://forum.ansible.com/t/proposal-consolidating-ansible-discussion-platforms/6812
As part of this change, the IRC channel was removed by the PRs #778 and #774.
However, the README.md file wasn't fully cleaned up from the outdated information.
The #ansible-kubernetes channel on libera.chat IRC isn't used by maintainers and contributors anymore.
The Wiki page on the https://github.com/ansible/community/ was deprecated a long time ago
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
README.md
2024-12-11 20:35:22 +00:00
patchback[bot]
9d3195641e CONTRIBUTING.md remove IRC (#778) (#824)
This is a backport of PR #778 as merged into main (c8a9326).
SUMMARY
As a part of https://forum.ansible.com/t/proposal-consolidating-ansible-discussion-platforms/6812
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
CONTRIBUTING.md
2024-12-11 20:35:19 +00:00
Yuriy Novostavskiy
dac1448b9c README: Add Communication section with Forum information (#774) (#823)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-12-11 18:54:13 +00:00
patchback[bot]
4bdff5d672 Make k8s_drain work when only one pod is present (#770) (#820)
This is a backport of PR #770 as merged into main (4c305e7).
SUMMARY
Fixes #769 .
k8s_drain was not checking if a pod has been deleted when there was only one pod on the node to be drained.
The list of pods, pods, was being "popped" before the first iteration of the while loop:
        pod = pods.pop()
        while (_elapsed_time() < wait_timeout or wait_timeout == 0) and pods:
When pods contains only one element, the while loop is skipped.


ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

k8s_drain
2024-12-11 16:23:41 +00:00
patchback[bot]
19a71c82ba Update Readme to match the template (#767) (#819)
This is a backport of PR #767 as merged into main (fdb8af7).
SUMMARY


Refer: https://issues.redhat.com/browse/ACA-1749
This PR updates the README doc to match the template
ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION
2024-12-11 16:17:45 +00:00
patchback[bot]
c73f3e3f75 Bump the ansible-lint version to 24.7.0 (#765) (#818)
This is a backport of PR #765 as merged into main (a89f19b).
SUMMARY

Bump the ansible-lint version to 24.7.0

ISSUE TYPE

COMPONENT NAME

ADDITIONAL INFORMATION
2024-12-11 15:58:13 +00:00
patchback[bot]
2cdcc195e6 fix shields.io badges in README.md (#749) (#817)
This is a backport of PR #749 as merged into main (0afd257).
SUMMARY
This PR fixes shields.io badges in README.md. It's just cosmetic bugfix
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
README.md
ADDITIONAL INFORMATION
Current README.md:

This PR:
2024-12-11 15:26:43 +00:00
patchback[bot]
e98605eb16 Improve error message for pod disruption budget when draining a node (#798) (#816)
This is a backport of PR #798 as merged into main (52f2cb5).
SUMMARY
Closes #797 .
The error message "Too Many Requests" is confusing and is changed to a more meaningful message:
TASK [Drain node] *************************************************************************
Montag 25 November 2024  09:20:28 +0100 (0:00:00.014)       0:00:00.014 ******* 
fatal: [host -> localhost]: FAILED! => {"changed": false, "msg": "Failed to delete pod kube-public/draintest-6b84677b99-9jf7m due to: Cannot evict pod as it would violate the pod's disruption budget."}


The new task output would allow to deal with a pod disruption budget with the retries/until logic in a more controlled way:
---
- hosts: "{{ target }}"
  serial: 1
  gather_facts: false
  tasks:
    - name: Drain node
      kubernetes.core.k8s_drain:
        kubeconfig: "{{ kubeconfig_path }}"
        name: "{{ inventory_hostname }}"
        delete_options:
          ignore_daemonsets: true
          delete_emptydir_data: true
          wait_timeout: 100
          disable_eviction: false
          wait_sleep: 1
      delegate_to: localhost
      retries: 10
      delay: 5
      until: drain_result is success or 'disruption budget' not in drain_result.msg
      register: drain_result

ISSUE TYPE


Feature Pull Request

COMPONENT NAME
k8s_drain
2024-12-11 15:14:49 +00:00
patchback[bot]
e13a7fd0c6 update changelog with release 3.2.0 (#750) (#814)
This is a backport of PR #750 as merged into main (d192157).
SUMMARY
Minor/cosmetic documentation change with adding release 3.2.0 to changelog for master as the release is from stable-3 branch
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
CHANGELOG.md
ADDITIONAL INFORMATION
Most probably this PR should be backported to the stable-5 branch after the merge to the main and should be with a skip-changelog tag.
2024-12-11 15:14:44 +00:00
patchback[bot]
2098dfea5e Fix k8s_drain runs into timeout with pods from stateful sets. (#793) (#808)
This is a backport of PR #793 as merged into main (fca0dc0).
SUMMARY
Fixes #792 .
The function wait_for_pod_deletion in k8s_drain never checks on which node a pod is actually running:
            try:
                response = self._api_instance.read_namespaced_pod(
                    namespace=pod[0], name=pod[1]
                )
                if not response:
                    pod = None
                time.sleep(wait_sleep)
This means that if a pod is successfully evicted and restarted with the same name on a new node, k8s_drain does not notice and thinks that the original pod is still running. This is the case for pods which are part of a stateful set.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME
k8s_drain
2024-12-11 14:12:35 +00:00
patchback[bot]
10a9b9e811 Remove kubevirt integration test workflow (#806) (#810)
This is a backport of PR #806 as merged into main (513ff66).
SUMMARY

This removes the kubevirt integration tests. We don't maintain that collection or have any permissions on that repo, so there's no reason for these tests to be here.

ISSUE TYPE


Bugfix Pull Request


COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-12-10 18:22:42 +00:00
patchback[bot]
67868442f3 [ci] fix github actions post 2.18 (#789) (#812)
This is a backport of PR #789 as merged into main (cd68631).
This PR includes a trivial fix for the GitHub Actions issue #788 and related to switching milestone and devel branches of ansible/ansible to version 2.19 and prepare repo to be ready to include test with Python 3.13 when ansible-network/github_actions/pull/162 is merged.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
GitHub actions/test

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-12-10 17:13:53 +00:00
patchback[bot]
5eefa9c308 fix: kustomize plugin fails with deprecation warnings (#728) (#764)
This is a backport of PR #728 as merged into main (5bc53db).
SUMMARY

error judgments are based on the exit codes of command execution, where 0 represents success and non-zero represents failure.
Optimize the run_command function to return a tuple like the run_command method of AnsibleModule.

Fixes #639
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

kustomize lookup plugin
ADDITIONAL INFORMATION

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-07-15 13:56:34 +00:00
patchback[bot]
4ed9105797 Fix waiting for daemonset when desired number of pods is 0 (#756) (#762)
This is a backport of PR #756 as merged into main (b07fbd6).
Fixes #755
SUMMARY
Because we don't have any node with non_exisiting_label (see code below) desired number of Pods will be 0. Kubernetes won't create .status.updatedNumberScheduled field (at least on version v1.27), because we still are not going to create any Pods. So that if .status.updatedNumberScheduled doesn't exist we should assume that number is 0
Code to reproduce:
- name: Create daemonset
  kubernetes.core.k8s:
    state: present
    wait: true
    definition:
      apiVersion: apps/v1
      kind: DaemonSet
      metadata:
        name: my-daemonset
        namespace: default
      spec:
        selector:
          matchLabels:
            app: my-app
        template:
          metadata:
            labels:
              app: my-app
          spec:
            containers:
              - name: my-container
                image: nginx
            nodeSelector:
              non_exisiting_label: 1
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
kubernetes.core.plugins.module_utils.k8s.waiter
ADDITIONAL INFORMATION



TASK [Create daemonset] **********************************************************************************************************************************
changed: [controlplane] => {"changed": true, "duration": 5, "method": "create", "result": {"apiVersion": "apps/v1", "kind": "DaemonSet", "metadata": {"annotations": {"deprecated.daemonset.template.generation": "1"}, "creationTimestamp": "2024-06-28T08:23:41Z", "generation": 1, "managedFields": [{"apiVersion": "apps/v1", "fieldsType": "FieldsV1", "fieldsV1": {"f:metadata": {"f:annotations": {".": {}, "f:deprecated.daemonset.template.generation": {}}}, "f:spec": {"f:revisionHistoryLimit": {}, "f:selector": {}, "f:template": {"f:metadata": {"f:labels": {".": {}, "f:app": {}}}, "f:spec": {"f:containers": {"k:{\"name\":\"my-container\"}": {".": {}, "f:image": {}, "f:imagePullPolicy": {}, "f:name": {}, "f:resources": {}, "f:terminationMessagePath": {}, "f:terminationMessagePolicy": {}}}, "f:dnsPolicy": {}, "f:nodeSelector": {}, "f:restartPolicy": {}, "f:schedulerName": {}, "f:securityContext": {}, "f:terminationGracePeriodSeconds": {}}}, "f:updateStrategy": {"f:rollingUpdate": {".": {}, "f:maxSurge": {}, "f:maxUnavailable": {}}, "f:type": {}}}}, "manager": "OpenAPI-Generator", "operation": "Update", "time": "2024-06-28T08:23:41Z"}, {"apiVersion": "apps/v1", "fieldsType": "FieldsV1", "fieldsV1": {"f:status": {"f:observedGeneration": {}}}, "manager": "kube-controller-manager", "operation": "Update", "subresource": "status", "time": "2024-06-28T08:23:41Z"}], "name": "my-daemonset", "namespace": "default", "resourceVersion": "1088421", "uid": "faafdbf7-4388-4cec-88d5-84657966312d"}, "spec": {"revisionHistoryLimit": 10, "selector": {"matchLabels": {"app": "my-app"}}, "template": {"metadata": {"creationTimestamp": null, "labels": {"app": "my-app"}}, "spec": {"containers": [{"image": "nginx", "imagePullPolicy": "Always", "name": "my-container", "resources": {}, "terminationMessagePath": "/dev/termination-log", "terminationMessagePolicy": "File"}], "dnsPolicy": "ClusterFirst", "nodeSelector": {"non_exisiting_label": "1"}, "restartPolicy": "Always", "schedulerName": "default-scheduler", "securityContext": {}, "terminationGracePeriodSeconds": 30}}, "updateStrategy": {"rollingUpdate": {"maxSurge": 0, "maxUnavailable": 1}, "type": "RollingUpdate"}}, "status": {"currentNumberScheduled": 0, "desiredNumberScheduled": 0, "numberMisscheduled": 0, "numberReady": 0, "observedGeneration": 1}}}

~$ kubectl get ds
NAME           DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR           AGE
my-daemonset   0         0         0       0            0           non_exisiting_label=1   30s

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-07-10 14:32:11 +00:00
patchback[bot]
46f8e4adfb [PR #731/c0666a51 backport][stable-5] kubevirt.core collection cross testing (#760)
This is a backport of PR #731 as merged into main (c0666a5).
SUMMARY

The kubevirt.core collection has dependency with this collection. We define new workflows to ensure that nothing is broken on that collection when pushing new changes on this collection.

ISSUE TYPE


Feature Pull Request

COMPONENT NAME

CI

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-07-10 13:57:49 +00:00
patchback[bot]
5761205513 helm: Accept release candidate versions for compatibility checks (#745) (#754)
This is a backport of PR #745 as merged into main (6a04f42).
SUMMARY

If the helm CLI version includes -rc.1 for example, the version checks fails due to an incomplete regex.
The error can be triggered if you use helm v3.15.0-rc.1 for example, and apply a helm chart with wait: true 
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME
helm
helm_pull
ADDITIONAL INFORMATION

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-06-18 13:05:55 +00:00
Bikouo Aubin
7b0190f8d5 Prepare release 5.0.0 (#733) 2024-06-10 15:39:42 +02:00
patchback[bot]
c47e691101 Doc: add example of using kubectl connection plugin (#741) (#744)
[PR #741/fb80d973 backport][stable-5] Doc: add example of using kubectl connection plugin

This is a backport of PR #741 as merged into main (fb80d97).
SUMMARY
Currently documentation for collection don't include any examples of using kubenrenes.core.kubectl connection plugin and it's hard to start using that plugin.
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
kubenrenes.core.kubectl connection plugin
ADDITIONAL INFORMATION
This PR was inspired by #288 and based on feedback on that PR and my own experience. Thanks @tpo for his try and @geerlingguy for his Ansible for DevOps book

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-06-06 14:34:01 +00:00
patchback[bot]
8ae6469696 Defer removal of inventory/k8s to 6.0.0 (#734) (#740)
Defer removal of inventory/k8s to 6.0.0

SUMMARY
Defer removal of inventory plugin k8s to release 6.0.0.

ISSUE TYPE

Feature Pull Request

Reviewed-by: Alina Buzachis
Reviewed-by: Mike Graves <mgraves@redhat.com>
(cherry picked from commit 0c5233a650)

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
2024-05-31 10:09:39 +02:00
patchback[bot]
1174fee5c9 Remove support for ansible-core<2.15 (#737) (#739)
Drop support for ansible-core<2.15

SUMMARY

Remove support for ansible-core<2.15

ISSUE TYPE

Feature Pull Request

Reviewed-by: Mike Graves <mgraves@redhat.com>
(cherry picked from commit 8363a4debf)

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
2024-05-31 10:06:48 +02:00
Bikouo Aubin
f22ffcab18 Prepare release 4.0.0 (#727)
* Prepare release 4.0.0

* update documentation
2024-05-28 11:37:32 +02:00
Bikouo Aubin
072a08091b Remove deprecated function from module_utils/common.py (#726)
Remove deprecated function from module_utils/common.py

SUMMARY

Remove deprecated functions and class from module_utils/common.py in order to prepare release 4.0.0

ISSUE TYPE


Feature Pull Request

COMPONENT NAME

module_utils/common.py

Reviewed-by: Alina Buzachis
2024-05-24 05:29:46 +00:00
Alina Buzachis
cbadbe32f9 Defer removal of k8s inventory plugin to version 5.0. (#723)
Defer removal of k8s inventory plugin to version 5.0.

SUMMARY

Defer removal of k8s inventory plugin to version 5.0.

ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

inventory/k8s.py
ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-22 10:13:50 +00:00
Alina Buzachis
966fa7e906 k8s - remove support for merge_type=json (#722)
k8s - remove support for merge_type=json

SUMMARY

Support for merge_type=json has been removed in version 4.0.0. Please use kubernetes.core.k8s_json_patch instead.

ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

k8s.py
ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-22 10:13:47 +00:00
Mike Graves
485eae3b10 Release 3.1.0 (#719) (#720)
Sync stable-3 to main branch (#719)

Release 3.1.0
SUMMARY
Release prep for 3.1.0
ISSUE TYPE
Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION
Reviewed-by: Alina Buzachis
Reviewed-by: Helen Bailey hebailey@redhat.com
(cherry picked from commit ef829b8)

Reviewed-by: Alina Buzachis
2024-05-16 18:43:34 +00:00
Conner Crosby
a4c1bd8541 Update deprecation version for merge_type=json (#700)
Update deprecation version for merge_type=json

SUMMARY
When looking at the parts of plugins/module_utils/common.py and plugins/module_utils/k8s/service.py during the post 3.0.0 release (see https://github.com/ansible-collections/kubernetes.core/pull/663/files#diff-9ee2d0860a5643da4e1f35136e9e7c3a41c5f2fd2952c197e7e32b941e5a301c) that affect merge_type when set to json, I don't believe merge_type=json was deprecated for (and removed from) the k8s module, and instead the deprecation version has moved to 4.0.0. Hence, the documentation update.
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
k8s module

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-15 18:02:55 +00:00
Mike Graves
8858b19121 Fix unsafe text assertion in tests (#716)
Fix unsafe text assertion in tests

SUMMARY

This fixes a problem with unsafe text in an assertion.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: GomathiselviS
Reviewed-by: Bikouo Aubin
2024-05-15 06:50:26 +00:00
Yuriy Novostavskiy
6360763098 minor: doc: use the same style of version_added across repo (#703)
minor(doc): use the same style of version_added across repo

SUMMARY
Currently is no single style of version_added, in some places it's unquoted, somewhere single quote is used, in another places it's double quoted. Moreover, some file had different styles in one single file.
The aim of this PR is to update whole repo to single style for version_added
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
kustomize
helm
helm_info
helm_plugin
helm_plugin_info
helm_pull
helm_repository
helm_template
k8s_cluster_info
k8s_cp
k8s_drain
k8s_exec
k8s_log
k8s_rollback
k8s_taint
ADDITIONAL INFORMATION
The same style is proposed as used in amazon.aws collections

Reviewed-by: Kelv Gooding
Reviewed-by: Alina Buzachis
Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-14 15:50:12 +00:00
Dennis Ochocki
ac943e9890 fixed typo in filename of 'k8s_json_patch'-action (#652)
fixed typo in filename of 'k8s_json_patch'-action 

SUMMARY

The filename/symlink of the action for the 'k8s_json_patch'-module was wrong. Renamed file from 'ks8_json_patch.py' to ' k8s_json_patch.py'

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

k8s_json_patch
ADDITIONAL INFORMATION


Because of the wrong filename things like unvaulting kubeconfig files did not worked.

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-14 15:48:01 +00:00
John Lathouwers
0408aa9328 Update kustomize.py add --enable-helm support (#592)
Update kustomize.py add --enable-helm support

Add --enable-helm support
SUMMARY
Fixes #568
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
Lookup plugin: kubernetes.core.kustomize
ADDITIONAL INFORMATION
Current and maintained arg:
lookup('kubernetes.core.kustomize', dir=item)

Additional feature args:
lookup('kubernetes.core.kustomize', dir=item, enable_helm=false)
lookup('kubernetes.core.kustomize', dir=item, enable_helm=true)

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-13 17:16:16 +00:00
Mike Graves
874fbfedd5 Merge pull request #707 from gravesm/linting-fix
Update ansible-lint GHA
2024-05-08 11:09:30 -04:00
Mike Graves
d8d9133912 Update ansible-lint GHA
There seems to be a bug in older versions of ansible-lint where pinning
to a version for the GHA still installs the main branch.
2024-05-07 12:35:35 -04:00
Alina Buzachis
86d9a3f45f Add tests/sanity/ignore-2.18.txt (#704)
Add tests/sanity/ignore-2.18.txt

SUMMARY

Add tests/sanity/ignore-2.18.txt

ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-07 15:27:13 +00:00
Yuriy Novostavskiy
fb25ff44f1 add support of kubectl_local_env_vars (#698) (#702)
add support of kubectl_local_env_vars (#698)

SUMMARY
Support of local environmental variable that may be required to be set on Ansible Controller before the connection is set and may be used for kubectl command. This PR addressed for #698
The main idea is to have the support of  additional/extra local environmental variable that may be required for kubectl itself, i.e. for authorization in case of public clouds
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
kubernetes.core.kubectl connection plugin
ADDITIONAL INFORMATION
This PR attempts to implement local env support for the kubectl connection plugin that may be useful in case of using kubectl against public cloud kubernetes environment that uses some authorization (i.e. aws cli) additionally to kubeconfig file. More detail in #698
The output that shows that the connection plugin can use local environment variable for kubectl command (with some debug that used during development but removed then):
root@ubuntu-shell:/# cat test.yaml
- hosts: localhost
  gather_facts: no
  any_errors_fatal: yes
  vars:
    ansible_connection: "kubectl"
    ansible_kubectl_namespace: "test"
    ansible_kubectl_config: "/.kube/config"
    ansible_kubectl_pod: "ubuntu"
    ansible_kubectl_container: "ubuntu"
    ansible_kubectl_local_env_vars:
      TESTVAR1: "test"
      TESTVAR2: "test"
      TESTVAR3: "test"
  environment:
    TEST_ENV1: value1
    TEST_ENV2: value2

  tasks:
  - name: test
    ansible.builtin.shell: env
    register: result
  - debug:
      var: result.stdout_lines
root@ubuntu-shell:/# ansible-playbook test.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] **************************************************************************************************************************************

TASK [test] *******************************************************************************************************************************************
changed: [localhost]

TASK [debug] ******************************************************************************************************************************************
ok: [localhost] => {
    "result.stdout_lines": [
        "KUBERNETES_PORT=tcp://10.96.0.1:443",
        "KUBERNETES_SERVICE_PORT=443",
        "HOSTNAME=ubuntu",
        "HOME=/root",
        "LC_CTYPE=C.UTF-8",
        "TEST_ENV1=value1",
        "TEST_ENV2=value2",
        "TERM=xterm",
        "KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1",
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "KUBERNETES_PORT_443_TCP_PORT=443",
        "KUBERNETES_PORT_443_TCP_PROTO=tcp",
        "KUBERNETES_SERVICE_PORT_HTTPS=443",
        "KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
        "KUBERNETES_SERVICE_HOST=10.96.0.1",
        "PWD=/"
    ]
}

PLAY RECAP ********************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

root@ubuntu-shell:/# ansible-playbook test.yaml -vvv
ansible-playbook [core 2.14.5]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
No config file found; using defaults
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: test.yaml ***********************************************************************************************************************************
1 plays in test.yaml

PLAY [localhost] **************************************************************************************************************************************

TASK [test] *******************************************************************************************************************************************
task path: /test.yaml:19
redirecting (type: connection) ansible.builtin.kubectl to kubernetes.core.kubectl
<127.0.0.1> ESTABLISH kubectl CONNECTION
<127.0.0.1> ENV: KUBERNETES_SERVICE_PORT_HTTPS=443
<127.0.0.1> ENV: KUBERNETES_SERVICE_PORT=443
<127.0.0.1> ENV: HOSTNAME=ubuntu-shell
<127.0.0.1> ENV: PWD=/
<127.0.0.1> ENV: HOME=/root
<127.0.0.1> ENV: KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
<127.0.0.1> ENV: LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
<127.0.0.1> ENV: TERM=xterm
<127.0.0.1> ENV: SHLVL=1
<127.0.0.1> ENV: KUBERNETES_PORT_443_TCP_PROTO=tcp
<127.0.0.1> ENV: KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
<127.0.0.1> ENV: KUBERNETES_SERVICE_HOST=10.96.0.1
<127.0.0.1> ENV: KUBERNETES_PORT=tcp://10.96.0.1:443
<127.0.0.1> ENV: KUBERNETES_PORT_443_TCP_PORT=443
<127.0.0.1> ENV: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
<127.0.0.1> ENV: _=/usr/local/bin/ansible-playbook
<127.0.0.1> ENV: LC_CTYPE=C.UTF-8
<127.0.0.1> ENV: TESTVAR1=test
<127.0.0.1> ENV: TESTVAR2=test
<127.0.0.1> ENV: TESTVAR3=test
<127.0.0.1> EXEC ['/usr/local/bin/kubectl', '-n', 'test', '--kubeconfig', '/.kube/config', 'exec', '-i', 'ubuntu', '-c', 'ubuntu', '--', '/bin/sh', '-c', "/bin/sh -c 'echo ~ && sleep 0'"]
<127.0.0.1> EXEC ['/usr/local/bin/kubectl', '-n', 'test', '--kubeconfig', '/.kube/config', 'exec', '-i', 'ubuntu', '-c', 'ubuntu', '--', '/bin/sh', '-c', '/bin/sh -c \'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1713785852.548581-6866-69007595335133 `" && echo ansible-tmp-1713785852.548581-6866-69007595335133="` echo /root/.ansible/tmp/ansible-tmp-1713785852.548581-6866-69007595335133 `" ) && sleep 0\'']
Using module file /usr/local/lib/python3.10/dist-packages/ansible/modules/command.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-6862s5_lr_wb/tmpxwmx0qeh TO /root/.ansible/tmp/ansible-tmp-1713785852.548581-6866-69007595335133/AnsiballZ_command.py
<127.0.0.1> EXEC ['/usr/local/bin/kubectl', '-n', 'test', '--kubeconfig', '/.kube/config', 'exec', '-i', 'ubuntu', '-c', 'ubuntu', '--', '/bin/sh', '-c', "/bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1713785852.548581-6866-69007595335133/ /root/.ansible/tmp/ansible-tmp-1713785852.548581-6866-69007595335133/AnsiballZ_command.py && sleep 0'"]
<127.0.0.1> EXEC ['/usr/local/bin/kubectl', '-n', 'test', '--kubeconfig', '/.kube/config', 'exec', '-i', 'ubuntu', '-c', 'ubuntu', '--', '/bin/sh', '-c', "/bin/sh -c 'TEST_ENV1=value1 TEST_ENV2=value2 /usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1713785852.548581-6866-69007595335133/AnsiballZ_command.py && sleep 0'"]
<127.0.0.1> EXEC ['/usr/local/bin/kubectl', '-n', 'test', '--kubeconfig', '/.kube/config', 'exec', '-i', 'ubuntu', '-c', 'ubuntu', '--', '/bin/sh', '-c', "/bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1713785852.548581-6866-69007595335133/ > /dev/null 2>&1 && sleep 0'"]
changed: [localhost] => {
    "changed": true,
    "cmd": "env",
    "delta": "0:00:00.005088",
    "end": "2024-04-22 11:37:33.655340",
    "invocation": {
        "module_args": {
            "_raw_params": "env",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true
        }
    },
    "msg": "",
    "rc": 0,
    "start": "2024-04-22 11:37:33.650252",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "KUBERNETES_PORT=tcp://10.96.0.1:443\nKUBERNETES_SERVICE_PORT=443\nHOSTNAME=ubuntu\nHOME=/root\nLC_CTYPE=C.UTF-8\nTEST_ENV1=value1\nTEST_ENV2=value2\nTERM=xterm\nKUBERNETES_PORT_443_TCP_ADDR=10.96.0.1\nPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\nKUBERNETES_PORT_443_TCP_PORT=443\nKUBERNETES_PORT_443_TCP_PROTO=tcp\nKUBERNETES_SERVICE_PORT_HTTPS=443\nKUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443\nKUBERNETES_SERVICE_HOST=10.96.0.1\nPWD=/",
    "stdout_lines": [
        "KUBERNETES_PORT=tcp://10.96.0.1:443",
        "KUBERNETES_SERVICE_PORT=443",
        "HOSTNAME=ubuntu",
        "HOME=/root",
        "LC_CTYPE=C.UTF-8",
        "TEST_ENV1=value1",
        "TEST_ENV2=value2",
        "TERM=xterm",
        "KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1",
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "KUBERNETES_PORT_443_TCP_PORT=443",
        "KUBERNETES_PORT_443_TCP_PROTO=tcp",
        "KUBERNETES_SERVICE_PORT_HTTPS=443",
        "KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
        "KUBERNETES_SERVICE_HOST=10.96.0.1",
        "PWD=/"
    ]
}

TASK [debug] ******************************************************************************************************************************************
task path: /test.yaml:22
redirecting (type: connection) ansible.builtin.kubectl to kubernetes.core.kubectl
ok: [localhost] => {
    "result.stdout_lines": [
        "KUBERNETES_PORT=tcp://10.96.0.1:443",
        "KUBERNETES_SERVICE_PORT=443",
        "HOSTNAME=ubuntu",
        "HOME=/root",
        "LC_CTYPE=C.UTF-8",
        "TEST_ENV1=value1",
        "TEST_ENV2=value2",
        "TERM=xterm",
        "KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1",
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "KUBERNETES_PORT_443_TCP_PORT=443",
        "KUBERNETES_PORT_443_TCP_PROTO=tcp",
        "KUBERNETES_SERVICE_PORT_HTTPS=443",
        "KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
        "KUBERNETES_SERVICE_HOST=10.96.0.1",
        "PWD=/"
    ]
}

PLAY RECAP ********************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

root@ubuntu-shell:/#

Reviewed-by: Bikouo Aubin
Reviewed-by: Yuriy Novostavskiy
Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-05-07 15:27:09 +00:00
Felix Matouschek
600c10dffb k8s: Display warnings to users (#701)
k8s: Display warnings to users

SUMMARY
This changes K8sService and the k8s module so warnings returned by the K8S API are displayed to the user.
Fixes kubevirt/kubevirt.core#30
Fixes kubevirt/kubevirt.core#31
ISSUE TYPE


Feature Pull Request

COMPONENT NAME


k8s module
K8sService

ADDITIONAL INFORMATION



Before:
TASK [Create VM] **********************************************************************************************************************************************
ok: [localhost]

After:
TASK [Create VM] **********************************************************************************************************************************************
[WARNING]: unknown field "spec.template.spec.disk"
[WARNING]: unknown field "spec.template.spec.domain.bogus"
ok: [localhost]

Reviewed-by: Adam Miller <admiller@redhat.com>
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Felix Matouschek <felix@matouschek.org>
2024-05-06 13:35:52 +00:00
Wout Van De Wiel
9f7c865c9c helm - expand kubeconfig path with user's home dir (#654)
helm - expand kubeconfig path with user's home dir

SUMMARY

Currently the helm module fails when providing the default kubeconfig path explicitly, while the same path is fine for the k8s module.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

helm
ADDITIONAL INFORMATION



- name: Deploy kubelet-csr-approver
  delegate_to: client
  run_once: true
  kubernetes.core.helm:
    update_repo_cache: true
    kubeconfig: "~/.kube/config"
    state: present
    name: kubelet-csr-approver
    namespace: kubelet-csr-approver
    create_namespace: true
    chart_ref: kubelet-csr-approver/kubelet-csr-approver
    chart_version: 1.0.5
    values: "{{ lookup('template', 'values.yaml.j2') | from_yaml }}"
    atomic: true

Before change:
TASK [kubernetes/kubelet_csr_approver : Deploy kubelet-csr-approver] ***
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: FileNotFoundError: [Errno 2] No such file or directory: '~/.kube/config'
fatal: [node-1 -> client(192.168.121.56)]: FAILED! => {"changed": false, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1697293347.7135417-118207-9805169252135/AnsiballZ_helm.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1697293347.7135417-118207-9805169252135/AnsiballZ_helm.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1697293347.7135417-118207-9805169252135/AnsiballZ_helm.py\", line 47, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.kubernetes.core.plugins.modules.helm', init_globals=dict(_module_fqn='ansible_collections.kubernetes.core.plugins.modules.helm', _modlib_path=modlib_path),\r\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_kubernetes.core.helm_payload_o8s36dti/ansible_kubernetes.core.helm_payload.zip/ansible_collections/kubernetes/core/plugins/modules/helm.py\", line 924, in <module>\r\n  File \"/tmp/ansible_kubernetes.core.helm_payload_o8s36dti/ansible_kubernetes.core.helm_payload.zip/ansible_collections/kubernetes/core/plugins/modules/helm.py\", line 737, in main\r\n  File \"/tmp/ansible_kubernetes.core.helm_payload_o8s36dti/ansible_kubernetes.core.helm_payload.zip/ansible_collections/kubernetes/core/plugins/modules/helm.py\", line 435, in run_repo_update\r\n  File \"/tmp/ansible_kubernetes.core.helm_payload_o8s36dti/ansible_kubernetes.core.helm_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/helm.py\", line 169, in run_helm_command\r\n  File \"/tmp/ansible_kubernetes.core.helm_payload_o8s36dti/ansible_kubernetes.core.helm_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/helm.py\", line 162, in env_update\r\n  File \"/tmp/ansible_kubernetes.core.helm_payload_o8s36dti/ansible_kubernetes.core.helm_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/helm.py\", line 120, in _prepare_helm_environment\r\nFileNotFoundError: [Errno 2] No such file or directory: '~/.kube/config'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

After change:
TASK [kubernetes/kubelet_csr_approver : Deploy kubelet-csr-approver] ***
changed: [node-1 -> client(192.168.121.56)]

Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Bikouo Aubin
2024-03-13 13:16:38 +00:00
Bikouo Aubin
23e94b60c1 helm - Add reuse-values when running helm diff (#683)
helm - Add reuse-values when running helm diff

SUMMARY

closes #680

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

helm

Reviewed-by: GomathiselviS
Reviewed-by: Alina Buzachis
2024-03-01 16:15:11 +00:00
bastienbosser
1955989278 fix(Collection's util resource discovery fails when complex subresources present #659) (#676)
* fix(Collection's util resource discovery fails when complex subresources present #659)

* fix(add changelog fragment)

* update node image

* Create discovery.yml

* Update main.yml

---------

Co-authored-by: Bastien Bosser <bastien.bosser@eviden.com>
Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
2024-02-29 14:38:45 +01:00
psmolkin
7c4ec3b982 Align helmdiff_check behavior with the deploy function (#670)
Align `helmdiff_check` behavior with the `deploy` function

SUMMARY
Align helmdiff_check behavior with the deploy function

Fixes #638
helmdiff_check respects set_values parameter
Fixes #669
helmdiff_check command line parameters sequence aligned to the deploy function

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
kubernetes.core.helm

Reviewed-by: Mike Graves <mgraves@redhat.com>
2024-02-19 17:01:23 +00:00
Alina Buzachis
8d15489ec2 Remove ignore files and entries which are not useful anymore (#667)
Remove ignore files and entries which are not useful anymore

SUMMARY

Remove ignore files and entries which are not useful anymore

ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Helen Bailey <hebailey@redhat.com>
Reviewed-by: Mike Graves <mgraves@redhat.com>
2023-12-12 16:09:14 +00:00
Bikouo Aubin
3dcdcbc85d avoid unsafe condition in integration (#665)
avoid unsafe condition in integration

SUMMARY


ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

integration tests

Reviewed-by: Helen Bailey <hebailey@redhat.com>
Reviewed-by: Alina Buzachis
2023-12-12 07:23:09 +00:00
GomathiselviS
fe9c12326d Update main branch post 3.0.0 release (#663)
Update main branch post 3.0.0 release

SUMMARY


ISSUE TYPE


Docs Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
2023-11-21 17:23:25 +00:00
86 changed files with 1926 additions and 2016 deletions

View File

@@ -2,5 +2,7 @@
profile: production profile: production
exclude_paths: exclude_paths:
- .ansible/
- tests/integration - tests/integration
- tests/unit
- tests/sanity - tests/sanity

60
.github/stale.yml vendored
View File

@@ -1,60 +0,0 @@
---
# Configuration for probot-stale - https://github.com/probot/stale
# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 90
# Number of days of inactivity before an Issue or Pull Request with the stale
# label is closed. Set to false to disable. If disabled, issues still need to be
# closed manually, but will remain marked as stale.
daysUntilClose: 30
# Only issues or pull requests with all of these labels are check if stale.
# Defaults to `[]` (disabled)
onlyLabels: []
# Issues or Pull Requests with these labels will never be considered stale. Set
# to `[]` to disable
exemptLabels:
- security
- planned
- priority/critical
- lifecycle/frozen
- verified
# Set to true to ignore issues in a project (defaults to false)
exemptProjects: false
# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones: true
# Set to true to ignore issues with an assignee (defaults to false)
exemptAssignees: false
# Label to use when marking as stale
staleLabel: lifecycle/stale
# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30
pulls:
markComment: |-
PRs go stale after 90 days of inactivity.
If there is no further activity, the PR will be closed in another 30 days.
unmarkComment: >-
This pull request is no longer stale.
closeComment: >-
This pull request has been closed due to inactivity.
issues:
markComment: |-
Issues go stale after 90 days of inactivity.
If there is no further activity, the issue will be closed in another 30 days.
unmarkComment: >-
This issue is no longer stale.
closeComment: >-
This issue has been closed due to inactivity.

View File

@@ -1,127 +0,0 @@
name: Integration tests Kubevirt
on:
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- main
- stable-*
jobs:
splitter:
continue-on-error: true
env:
kubernetes: "./kubernetes"
kubevirt: "./kubevirt"
py_version: 3.9
runs-on: ubuntu-latest
outputs:
test_targets: ${{ steps.splitter.outputs.kubevirt_targets }}
steps:
- name: Checkout kubernetes.core repository
uses: actions/checkout@v3
with:
path: ${{ env.kubernetes }}
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout the kubevirt.core collection
uses: actions/checkout@v3
with:
repository: kubevirt/kubevirt.core
path: ${{ env.kubevirt }}
- name: "Set up Python ${{ env.py_version }}"
uses: actions/setup-python@v4
with:
python-version: "${{ env.py_version }}"
- name: List targets from kubevirt.core collection
id: splitter
run: python ${{ env.kubernetes }}/tools/kubevirt_list_targets.py ${{ env.kubevirt }}
shell: bash
integration:
if: ${{ needs.splitter.outputs.test_targets != '' }}
name: "integration-kubevirt-${{ matrix.test-target }}"
runs-on: ubuntu-latest
continue-on-error: true
needs:
- splitter
env:
kubernetes: "./kubernetes"
kubevirt: "./kubevirt"
ansible_version: milestone
python_version: 3.12
strategy:
fail-fast: false
matrix:
test-target: ${{ fromJson(needs.splitter.outputs.test_targets) }}
steps:
- name: Checkout kubernetes.core repository
uses: actions/checkout@v4
with:
path: ${{ env.kubernetes }}
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout kubevirt.core repository
uses: actions/checkout@v4
with:
repository: kubevirt/kubevirt.core
path: ${{ env.kubevirt }}
ref: main
# Install ansible
- name: Install ansible-core (${{ env.ansible_version }})
run: >-
python3 -m pip install
https://github.com/ansible/ansible/archive/${{ env.ansible_version }}.tar.gz
--disable-pip-version-check
shell: bash
- name: Build and install kubevirt.core collection
id: install-kubevirt
uses: ansible-network/github_actions/.github/actions/build_install_collection@main
with:
install_python_dependencies: true
source_path: ${{ env.kubevirt }}
- name: Build and install kubernetes.core collection
id: install-kubernetes
uses: ansible-network/github_actions/.github/actions/build_install_collection@main
with:
install_python_dependencies: true
source_path: ${{ env.kubernetes }}
- name: Install kind / kubectl
uses: helm/kind-action@v1.9.0
with:
version: v0.22.0
install_only: true
- name: Deploy kubevirt
run: >-
${{ env.kubevirt }}/hack/e2e-setup.sh \
-v \
--configure-inotify-limits \
--configure-secondary-network \
--deploy-kubevirt \
--deploy-kubevirt-cdi \
--deploy-kubevirt-common-instancetypes \
--deploy-cnao \
--create-cluster \
--create-nad
env:
KIND: kind
KUBECTL: kubectl
- name: Run integration tests
uses: ansible-network/github_actions/.github/actions/ansible_test_integration@main
with:
collection_path: ${{ steps.install-kubevirt.outputs.collection_path }}
python_version: ${{ env.python_version }}
ansible_version: ${{ env.ansible_version }}
ansible_test_targets: ${{ matrix.test-target }}
env:
ANSIBLE_COLLECTIONS_PATHS: /home/runner/collections

View File

@@ -19,6 +19,5 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: run-ansible-lint
- name: Run ansible-lint uses: ansible/ansible-lint@v24.12.2
uses: ansible/ansible-lint@v24.2.3

View File

@@ -4,6 +4,101 @@ Kubernetes Collection Release Notes
.. contents:: Topics .. contents:: Topics
v5.1.0
======
Minor Changes
-------------
- Bump version of ansible-lint to minimum 24.7.0 (https://github.com/ansible-collections/kubernetes.core/pull/765).
- Parameter insecure_registry added to helm_template as equivalent of insecure-skip-tls-verify (https://github.com/ansible-collections/kubernetes.core/pull/805).
- connection/kubectl.py - Added an example of using the kubectl connection plugin to the documentation (https://github.com/ansible-collections/kubernetes.core/pull/741).
- k8s_drain - Improve error message for pod disruption budget when draining a node (https://github.com/ansible-collections/kubernetes.core/issues/797).
Bugfixes
--------
- helm - Helm version checks did not support RC versions. They now accept any version tags. (https://github.com/ansible-collections/kubernetes.core/pull/745).
- helm_pull - Apply no_log=True to pass_credentials to silence false positive warning.. (https://github.com/ansible-collections/kubernetes.core/pull/796).
- k8s_drain - Fix k8s_drain does not wait for single pod (https://github.com/ansible-collections/kubernetes.core/issues/769).
- k8s_drain - Fix k8s_drain runs into a timeout when evicting a pod which is part of a stateful set (https://github.com/ansible-collections/kubernetes.core/issues/792).
- kubeconfig option should not appear in module invocation log (https://github.com/ansible-collections/kubernetes.core/issues/782).
- kustomize - kustomize plugin fails with deprecation warnings (https://github.com/ansible-collections/kubernetes.core/issues/639).
- waiter - Fix waiting for daemonset when desired number of pods is 0. (https://github.com/ansible-collections/kubernetes.core/pull/756).
New Modules
-----------
- helm_registry_auth - Helm registry authentication module
v5.0.0
======
Release Summary
---------------
This major release drops support for ``ansible-core<2.15``.
Minor Changes
-------------
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 6.0.0 (https://github.com/ansible-collections/kubernetes.core/pull/734).
Breaking Changes / Porting Guide
--------------------------------
- Remove support for ``ansible-core<2.15`` (https://github.com/ansible-collections/kubernetes.core/pull/737).
v4.0.0
======
Release Summary
---------------
This major release brings several bug fixes. We have also removed support for ``ansible-core<2.15`` and deprecated functions and class from ``module_utils/common.py``.
Minor Changes
-------------
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 5.0 (https://github.com/ansible-collections/kubernetes.core/pull/723).
- k8s - The module and K8sService were changed so warnings returned by the K8S API are now displayed to the user.
Removed Features (previously deprecated)
----------------------------------------
- k8s - Support for ``merge_type=json`` has been removed in version 4.0.0. Please use ``kubernetes.core.k8s_json_patch`` instead (https://github.com/ansible-collections/kubernetes.core/pull/722).
- k8s_exec - the previously deprecated ``result.return_code`` return value has been removed, consider using ``result.rc`` instead (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``K8sAnsibleMixin`` class has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``configuration_digest()`` function has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``get_api_client()`` function has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``unique_string()`` function has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
Bugfixes
--------
- Resolve Collections util resource discovery fails when complex subresources present (https://github.com/ansible-collections/kubernetes.core/pull/676).
- align `helmdiff_check()` function commandline rendering with the `deploy()` function (https://github.com/ansible-collections/kubernetes.core/pull/670).
- avoid unsafe conditions in integration tests (https://github.com/ansible-collections/kubernetes.core/pull/665).
- helm - use ``reuse-values`` when running ``helm diff`` command (https://github.com/ansible-collections/kubernetes.core/issues/680).
- integrations test helm_kubeconfig - set helm version to v3.10.3 to avoid incompatability with new bitnami charts (https://github.com/ansible-collections/kubernetes.core/pull/670).
v3.3.0
======
Minor Changes
-------------
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 5.0 (https://github.com/ansible-collections/kubernetes.core/pull/723).
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 6.0.0 (https://github.com/ansible-collections/kubernetes.core/pull/734).
- k8s_drain - Improve error message for pod disruption budget when draining a node (https://github.com/ansible-collections/kubernetes.core/issues/797).
Bugfixes
--------
- helm - Helm version checks did not support RC versions. They now accept any version tags. (https://github.com/ansible-collections/kubernetes.core/pull/745).
- helm_pull - Apply no_log=True to pass_credentials to silence false positive warning.. (https://github.com/ansible-collections/kubernetes.core/pull/796).
- k8s_drain - Fix k8s_drain does not wait for single pod (https://github.com/ansible-collections/kubernetes.core/issues/769).
- k8s_drain - Fix k8s_drain runs into a timeout when evicting a pod which is part of a stateful set (https://github.com/ansible-collections/kubernetes.core/issues/792).
- kubeconfig option should not appear in module invocation log (https://github.com/ansible-collections/kubernetes.core/issues/782).
- kustomize - kustomize plugin fails with deprecation warnings (https://github.com/ansible-collections/kubernetes.core/issues/639).
- waiter - Fix waiting for daemonset when desired number of pods is 0. (https://github.com/ansible-collections/kubernetes.core/pull/756).
v3.2.0 v3.2.0
====== ======

View File

@@ -48,7 +48,7 @@ Where modules have multiple parameters we recommend running through the 4-step m
For general information on running the integration tests see the For general information on running the integration tests see the
[Integration Tests page of the Module Development Guide](https://docs.ansible.com/ansible/devel/dev_guide/testing_integration.html#testing-integration), [Integration Tests page of the Module Development Guide](https://docs.ansible.com/ansible/devel/dev_guide/testing_integration.html#testing-integration),
especially the section on configuration for cloud tests. For questions about writing tests the Ansible Kubernetes community can be found on Libera.Chat IRC as detailed below. especially the section on configuration for cloud tests.
### Updating documentation ### Updating documentation
@@ -70,11 +70,3 @@ Review the changes and create a pull request using updated files.
The `kubernetes.core` collection follows the Ansible project's The `kubernetes.core` collection follows the Ansible project's
[Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html). [Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html).
Please read and familiarize yourself with this document. Please read and familiarize yourself with this document.
### IRC
Our IRC channels may require you to register your nickname. If you receive an error when you connect, see
[Libera.Chat's Nickname Registration guide](https://libera.chat/guides/registration) for instructions.
The `#ansible-kubernetes` channel on [libera.chat](https://libera.chat/) IRC is the main and official place to discuss use and development of the `kubernetes.core` collection.
For more information about Ansible's Kubernetes integration, browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.

View File

@@ -1,5 +1,5 @@
# Also needs to be updated in galaxy.yml # Also needs to be updated in galaxy.yml
VERSION = 3.2.0 VERSION = 5.1.0
TEST_ARGS ?= "" TEST_ARGS ?= ""
PYTHON_VERSION ?= `python -c 'import platform; print(".".join(platform.python_version_tuple()[0:2]))'` PYTHON_VERSION ?= `python -c 'import platform; print(".".join(platform.python_version_tuple()[0:2]))'`

View File

@@ -1,15 +1,29 @@
# Kubernetes Collection for Ansible # Kubernetes Collection for Ansible
[![CI](https://github.com/ansible-collections/kubernetes.core/workflows/CI/badge.svg?event=push)](https://github.com/ansible-collections/kubernetes.core/actions) [![Codecov](https://img.shields.io/codecov/c/github/ansible-collections/kubernetes.core)](https://codecov.io/gh/ansible-collections/kubernetes.core)
This repository hosts the `kubernetes.core` (formerly known as `community.kubernetes`) Ansible Collection. This repository hosts the `kubernetes.core` (formerly known as `community.kubernetes`) Ansible Collection.
## Description
The collection includes a variety of Ansible content to help automate the management of applications in Kubernetes and OpenShift clusters, as well as the provisioning and maintenance of clusters themselves. The collection includes a variety of Ansible content to help automate the management of applications in Kubernetes and OpenShift clusters, as well as the provisioning and maintenance of clusters themselves.
## Communication
* Join the Ansible forum:
* [Get Help](https://forum.ansible.com/c/help/6): get help or help others.
* [Posts tagged with 'kubernetes'](https://forum.ansible.com/tag/kubernetes): subscribe to participate in collection-related conversations.
* [Social Spaces](https://forum.ansible.com/c/chat/4): gather and interact with fellow enthusiasts.
* [News & Announcements](https://forum.ansible.com/c/news/5): track project-wide announcements including social events.
* The Ansible [Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn): used to announce releases and important changes.
For more information about communication, see the [Ansible communication guide](https://docs.ansible.com/ansible/devel/community/communication.html).
## Requirements
<!--start requires_ansible--> <!--start requires_ansible-->
## Ansible version compatibility ## Ansible version compatibility
This collection has been tested against following Ansible versions: **>=2.14.0**. This collection has been tested against following Ansible versions: **>=2.15.0**.
For collections that support Ansible 2.9, please ensure you update your `network_os` to use the For collections that support Ansible 2.9, please ensure you update your `network_os` to use the
fully qualified collection name (for example, `cisco.ios.ios`). fully qualified collection name (for example, `cisco.ios.ios`).
@@ -18,17 +32,17 @@ A collection may contain metadata that identifies these versions.
PEP440 is the schema used to describe the versions of Ansible. PEP440 is the schema used to describe the versions of Ansible.
<!--end requires_ansible--> <!--end requires_ansible-->
## Python Support ### Python Support
* Collection supports 3.9+ * Collection supports 3.9+
Note: Python2 is deprecated from [1st January 2020](https://www.python.org/doc/sunset-python-2/). Please switch to Python3. Note: Python2 is deprecated from [1st January 2020](https://www.python.org/doc/sunset-python-2/). Please switch to Python3.
## Kubernetes Version Support ### Kubernetes Version Support
This collection supports Kubernetes versions >= 1.24. This collection supports Kubernetes versions >= 1.24.
## Included content ### Included content
Click on the name of a plugin or module to view that content's documentation: Click on the name of a plugin or module to view that content's documentation:
@@ -62,6 +76,7 @@ Name | Description
[kubernetes.core.helm_plugin](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_module.rst)|Manage Helm plugins [kubernetes.core.helm_plugin](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_module.rst)|Manage Helm plugins
[kubernetes.core.helm_plugin_info](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_info_module.rst)|Gather information about Helm plugins [kubernetes.core.helm_plugin_info](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_info_module.rst)|Gather information about Helm plugins
[kubernetes.core.helm_pull](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_pull_module.rst)|download a chart from a repository and (optionally) unpack it in local directory. [kubernetes.core.helm_pull](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_pull_module.rst)|download a chart from a repository and (optionally) unpack it in local directory.
[kubernetes.core.helm_registry_auth](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_registry_auth_module.rst)|Helm registry authentication module
[kubernetes.core.helm_repository](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_repository_module.rst)|Manage Helm repositories. [kubernetes.core.helm_repository](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_repository_module.rst)|Manage Helm repositories.
[kubernetes.core.helm_template](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_template_module.rst)|Render chart templates [kubernetes.core.helm_template](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_template_module.rst)|Render chart templates
[kubernetes.core.k8s](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_module.rst)|Manage Kubernetes (K8s) objects [kubernetes.core.k8s](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_module.rst)|Manage Kubernetes (K8s) objects
@@ -79,9 +94,7 @@ Name | Description
<!--end collection content--> <!--end collection content-->
## Installation and Usage ## Installation
### Installing the Collection from Ansible Galaxy
Before using the Kubernetes collection, you need to install it with the Ansible Galaxy CLI: Before using the Kubernetes collection, you need to install it with the Ansible Galaxy CLI:
@@ -93,7 +106,7 @@ You can also include it in a `requirements.yml` file and install it via `ansible
--- ---
collections: collections:
- name: kubernetes.core - name: kubernetes.core
version: 3.2.0 version: 5.1.0
``` ```
### Installing the Kubernetes Python Library ### Installing the Kubernetes Python Library
@@ -102,7 +115,7 @@ Content in this collection requires the [Kubernetes Python client](https://pypi.
pip3 install kubernetes pip3 install kubernetes
### Using modules from the Kubernetes Collection in your playbooks ## Use Cases
It's preferable to use content in this collection using their Fully Qualified Collection Namespace (FQCN), for example `kubernetes.core.k8s_info`: It's preferable to use content in this collection using their Fully Qualified Collection Namespace (FQCN), for example `kubernetes.core.k8s_info`:
@@ -189,12 +202,16 @@ defined in the playbook using `environment` keyword as above, you must set it us
Please read more about Ansible Turbo mode - [here](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/ansible_turbo_mode.rst). Please read more about Ansible Turbo mode - [here](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/ansible_turbo_mode.rst).
## Testing and Development ## Contributing to this collection
If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured [`COLLECTIONS_PATHS`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and work on it there. If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured [`COLLECTIONS_PATHS`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and work on it there.
See [Contributing to kubernetes.core](CONTRIBUTING.md). See [Contributing to kubernetes.core](CONTRIBUTING.md).
## Testing
[![Linters](https://img.shields.io/github/actions/workflow/status/ansible-collections/kubernetes.core/linters.yaml?label=linters)](https://github.com/ansible-collections/kubernetes.core/actions/workflows/linters.yaml) [![Integration tests](https://img.shields.io/github/actions/workflow/status/ansible-collections/kubernetes.core/integration-tests.yaml?label=integration%20tests)](https://github.com/ansible-collections/kubernetes.core/actions/workflows/integration-tests.yaml) [![Sanity tests](https://img.shields.io/github/actions/workflow/status/ansible-collections/kubernetes.core/sanity-tests.yaml?label=sanity%20tests)](https://github.com/ansible-collections/kubernetes.core/actions/workflows/sanity-tests.yaml) [![Unit tests](https://img.shields.io/github/actions/workflow/status/ansible-collections/kubernetes.core/unit-tests.yaml?label=unit%20tests)](https://github.com/ansible-collections/kubernetes.core/actions/workflows/unit-tests.yaml) [![Codecov](https://img.shields.io/codecov/c/github/ansible-collections/kubernetes.core)](https://app.codecov.io/gh/ansible-collections/kubernetes.core)
### Testing with `ansible-test` ### Testing with `ansible-test`
The `tests` directory contains configuration for running sanity and integration tests using [`ansible-test`](https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html). The `tests` directory contains configuration for running sanity and integration tests using [`ansible-test`](https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html).
@@ -231,9 +248,31 @@ After the version is published, verify it exists on the [Kubernetes Collection G
The process for uploading a supported release to Automation Hub is documented separately. The process for uploading a supported release to Automation Hub is documented separately.
## More Information ## Support
<!--List available communication channels. In addition to channels specific to your collection, we also recommend to use the following ones.-->
We announce releases and important changes through Ansible's [The Bullhorn newsletter](https://github.com/ansible/community/wiki/News#the-bullhorn). Be sure you are [subscribed](https://eepurl.com/gZmiEP).
We take part in the global quarterly [Ansible Contributor Summit](https://github.com/ansible/community/wiki/Contributor-Summit) virtually or in-person. Track [The Bullhorn newsletter](https://eepurl.com/gZmiEP) and join us.
For more information about communication, refer to the [Ansible Communication guide](https://docs.ansible.com/ansible/devel/community/communication.html).
For the latest supported versions, refer to the release notes below.
If you encounter issues or have questions, you can submit a support request through the following channels:
- GitHub Issues: Report bugs, request features, or ask questions by opening an issue in the [GitHub repository]((https://github.com/ansible-collections/kubernetes.core/).
## Release notes
See the [raw generated changelog](https://github.com/ansible-collections/kubernetes.core/blob/main/CHANGELOG.rst).
## Code of Conduct
We follow the [Ansible Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html) in all our interactions within this project.
If you encounter abusive behavior, please refer to the [policy violations](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html#policy-violations) section of the Code for information on how to raise a complaint.
For more information about Ansible's Kubernetes integration, join the `#ansible-kubernetes` channel on [libera.chat](https://libera.chat/) IRC, and browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.
## License ## License

View File

@@ -857,11 +857,145 @@ releases:
3.2.0: 3.2.0:
changes: changes:
minor_changes: minor_changes:
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 6.0.0 (https://github.com/ansible-collections/kubernetes.core/pull/734). - connection/kubectl.py - Added an example of using the kubectl connection plugin
- connection/kubectl.py - Added an example of using the kubectl connection plugin to the documentation (https://github.com/ansible-collections/kubernetes.core/pull/741). to the documentation (https://github.com/ansible-collections/kubernetes.core/pull/741).
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 6.0.0
(https://github.com/ansible-collections/kubernetes.core/pull/734).
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 5.0 (https://github.com/ansible-collections/kubernetes.core/pull/723).
release_summary: This release comes with documentation updates. release_summary: This release comes with documentation updates.
fragments: fragments:
- 20240530-defer-removal-and-ansible-core-support-update.yaml - 20240530-defer-removal-and-ansible-core-support-update.yaml
- 20240601-doc-example-of-using-kubectl.yaml - 20240601-doc-example-of-using-kubectl.yaml
- inventory-update_removal_date.yml
- 3.2.0.yml - 3.2.0.yml
release_date: '2024-06-14' release_date: '2024-06-14'
3.3.0:
changes:
bugfixes:
- helm - Helm version checks did not support RC versions. They now accept any
version tags. (https://github.com/ansible-collections/kubernetes.core/pull/745).
- helm_pull - Apply no_log=True to pass_credentials to silence false positive
warning. (https://github.com/ansible-collections/kubernetes.core/pull/796).
- k8s_drain - Fix k8s_drain does not wait for single pod (https://github.com/ansible-collections/kubernetes.core/issues/769).
- k8s_drain - Fix k8s_drain runs into a timeout when evicting a pod which is
part of a stateful set (https://github.com/ansible-collections/kubernetes.core/issues/792).
- kubeconfig option should not appear in module invocation log (https://github.com/ansible-collections/kubernetes.core/issues/782).
- kustomize - kustomize plugin fails with deprecation warnings (https://github.com/ansible-collections/kubernetes.core/issues/639).
- waiter - Fix waiting for daemonset when desired number of pods is 0. (https://github.com/ansible-collections/kubernetes.core/pull/756).
minor_changes:
- k8s_drain - Improve error message for pod disruption budget when draining
a node (https://github.com/ansible-collections/kubernetes.core/issues/797).
release_summary: This release comes with improvements to the error messages in the k8s_drain module and several bug fixes.
fragments:
- 20240530-ansible-core-support-update.yaml
- 20240611-helm-rc-version.yaml
- 20240620-fix-kustomize-plugin-fails-with-deprecation-warnings.yml
- 20241102-fix-ci-post-2.18-issue.yaml
- 20241213-kubeconfig-set-no_log-true.yaml
- 756-fix-daemonset-waiting.yaml
- 770-fix-k8s-drain-doesnt-wait-for-single-pod.yaml
- 793-fix-k8s-drain-runs-into-timeout.yaml
- 796-false-positive-helmull.yaml
- 798-drain-pdb-error-message.yaml
- readme_template_update.yml
release_date: '2025-01-20'
4.0.0:
changes:
bugfixes:
- Resolve Collections util resource discovery fails when complex subresources
present (https://github.com/ansible-collections/kubernetes.core/pull/676).
- align `helmdiff_check()` function commandline rendering with the `deploy()`
function (https://github.com/ansible-collections/kubernetes.core/pull/670).
- avoid unsafe conditions in integration tests (https://github.com/ansible-collections/kubernetes.core/pull/665).
- helm - use ``reuse-values`` when running ``helm diff`` command (https://github.com/ansible-collections/kubernetes.core/issues/680).
- integrations test helm_kubeconfig - set helm version to v3.10.3 to avoid incompatability
with new bitnami charts (https://github.com/ansible-collections/kubernetes.core/pull/670).
minor_changes:
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 5.0 (https://github.com/ansible-collections/kubernetes.core/pull/723).
- k8s - The module and K8sService were changed so warnings returned by the K8S
API are now displayed to the user.
release_summary: This major release brings several bug fixes. We have also removed
support for ``ansible-core<2.15`` and deprecated functions and class from
``module_utils/common.py``.
removed_features:
- k8s - Support for ``merge_type=json`` has been removed in version 4.0.0. Please
use ``kubernetes.core.k8s_json_patch`` instead (https://github.com/ansible-collections/kubernetes.core/pull/722).
- k8s_exec - the previously deprecated ``result.return_code`` return value has
been removed, consider using ``result.rc`` instead (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``K8sAnsibleMixin`` class
has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``configuration_digest()``
function has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``get_api_client()`` function
has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
- module_utils/common.py - the previously deprecated ``unique_string()`` function
has been removed (https://github.com/ansible-collections/kubernetes.core/pull/726).
fragments:
- 20231206-fix-unsafe-condition-in-integration.yml
- 20240117-fix-helm-diff-cmd-line-rendering.yml
- 20240222-Collections-util-resource-discovery-fails-when-complex-subresources-present.yml
- 20240228-fix-helm-diff-with-reuse-values.yml
- 20240423-k8s-display-warnings-to-users.yml
- 4.0.0.yaml
- inventory-update_removal_date.yml
- k8s-merge_type-removed.yml
- module_utils-common-remove-deprecated-functions-and-class.yaml
release_date: '2024-05-24'
5.0.0:
changes:
breaking_changes:
- Remove support for ``ansible-core<2.15`` (https://github.com/ansible-collections/kubernetes.core/pull/737).
minor_changes:
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 6.0.0
(https://github.com/ansible-collections/kubernetes.core/pull/734).
- connection/kubectl.py - Added an example of using the kubectl connection plugin
to the documentation (https://github.com/ansible-collections/kubernetes.core/pull/741).
release_summary: This major release drops support for ``ansible-core<2.15``.
fragments:
- 20240530-ansible-core-support-update.yaml
- 20240530-defer-removal-and-ansible-core-support-update.yaml
- 5.0.0.yml
release_date: '2024-05-31'
5.1.0:
changes:
bugfixes:
- helm - Helm version checks did not support RC versions. They now accept any
version tags. (https://github.com/ansible-collections/kubernetes.core/pull/745).
- helm_pull - Apply no_log=True to pass_credentials to silence false positive
warning. (https://github.com/ansible-collections/kubernetes.core/pull/796).
- k8s_drain - Fix k8s_drain does not wait for single pod (https://github.com/ansible-collections/kubernetes.core/issues/769).
- k8s_drain - Fix k8s_drain runs into a timeout when evicting a pod which is
part of a stateful set (https://github.com/ansible-collections/kubernetes.core/issues/792).
- kubeconfig option should not appear in module invocation log (https://github.com/ansible-collections/kubernetes.core/issues/782).
- kustomize - kustomize plugin fails with deprecation warnings (https://github.com/ansible-collections/kubernetes.core/issues/639).
- waiter - Fix waiting for daemonset when desired number of pods is 0. (https://github.com/ansible-collections/kubernetes.core/pull/756).
minor_changes:
- Bump version of ansible-lint to minimum 24.7.0 (https://github.com/ansible-collections/kubernetes.core/pull/765).
- Parameter insecure_registry added to helm_template as equivalent of insecure-skip-tls-verify
(https://github.com/ansible-collections/kubernetes.core/pull/805).
- k8s_drain - Improve error message for pod disruption budget when draining
a node (https://github.com/ansible-collections/kubernetes.core/issues/797).
release_summary: This release came with new module ``helm_registry_auth``, improvements
to the error messages in the k8s_drain module, new parameter ``insecure_registry`` for
``helm_template`` module and several bug fixes.
fragments:
- 0-readme.yml
- 20240601-doc-example-of-using-kubectl.yaml
- 20240611-helm-rc-version.yaml
- 20240620-fix-kustomize-plugin-fails-with-deprecation-warnings.yml
- 20241102-fix-ci-post-2.18-issue.yaml
- 20241103-completly-remove-obsolate-communication-channel.yaml
- 20241207-add-insecure-skip-tls-verify-to-helm-template.yaml
- 20241213-kubeconfig-set-no_log-true.yaml
- 756-fix-daemonset-waiting.yaml
- 765-bump-ansible-lint-version.yml
- 770-fix-k8s-drain-doesnt-wait-for-single-pod.yaml
- 793-fix-k8s-drain-runs-into-timeout.yaml
- 796-false-positive-helmull.yaml
- 798-drain-pdb-error-message.yaml
- readme_template_update.yml
modules:
- description: Helm registry authentication module
name: helm_registry_auth
namespace: ''
release_date: '2025-01-20'

View File

@@ -1,3 +0,0 @@
---
minor_changes:
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 6.0.0 (https://github.com/ansible-collections/kubernetes.core/pull/734).

View File

@@ -1,2 +0,0 @@
minor_changes:
- inventory/k8s.py - Defer removal of k8s inventory plugin to version 5.0 (https://github.com/ansible-collections/kubernetes.core/pull/723).

View File

@@ -443,7 +443,7 @@ Parameters
<div style="font-size: small"> <div style="font-size: small">
<span style="color: purple">boolean</span> <span style="color: purple">boolean</span>
</div> </div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.5.0</div> <div style="font-style: italic; font-size: small; color: darkgreen">added in 3.0.0</div>
</td> </td>
<td> <td>
<ul style="margin: 0; padding: 0"><b>Choices:</b> <ul style="margin: 0; padding: 0"><b>Choices:</b>
@@ -463,7 +463,7 @@ Parameters
<div style="font-size: small"> <div style="font-size: small">
<span style="color: purple">boolean</span> <span style="color: purple">boolean</span>
</div> </div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.5.0</div> <div style="font-style: italic; font-size: small; color: darkgreen">added in 3.0.0</div>
</td> </td>
<td> <td>
<ul style="margin: 0; padding: 0"><b>Choices:</b> <ul style="margin: 0; padding: 0"><b>Choices:</b>

View File

@@ -0,0 +1,332 @@
.. _kubernetes.core.helm_registry_auth_module:
**********************************
kubernetes.core.helm_registry_auth
**********************************
**Helm registry authentication module**
Version added: 5.1.0
.. contents::
:local:
:depth: 1
Synopsis
--------
- Helm registry authentication module allows you to login ``helm registry login`` and logout ``helm registry logout`` from a Helm registry.
Requirements
------------
The below requirements are needed on the host that executes this module.
- helm (https://github.com/helm/helm/releases) => 3.8.0
Parameters
----------
.. raw:: html
<table border=0 cellpadding=0 class="documentation-table">
<tr>
<th colspan="1">Parameter</th>
<th>Choices/<font color="blue">Defaults</font></th>
<th width="100%">Comments</th>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>binary_path</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">path</span>
</div>
</td>
<td>
</td>
<td>
<div>The path of a helm binary to use.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>ca_file</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">path</span>
</div>
</td>
<td>
</td>
<td>
<div>Path to the CA certificate SSL file for verify registry server certificate.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>cert_file</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">path</span>
</div>
</td>
<td>
</td>
<td>
<div>Path to the client certificate SSL file for identify registry client using this certificate file.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>host</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
/ <span style="color: red">required</span>
</div>
</td>
<td>
</td>
<td>
<div>Provide a URL for accessing the registry.</div>
<div style="font-size: small; color: darkgreen"><br/>aliases: registry_url</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>insecure</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</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>Allow connections to SSL sites without certs.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>key_file</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">path</span>
</div>
</td>
<td>
</td>
<td>
<div>Path to the client key SSL file for identify registry client using this key file.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>password</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Password for the registry.</div>
<div style="font-size: small; color: darkgreen"><br/>aliases: repo_password</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>state</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li><div style="color: blue"><b>present</b>&nbsp;&larr;</div></li>
<li>absent</li>
</ul>
</td>
<td>
<div>Desired state of the registry.</div>
<div>If set to V(present) attempt to log in to the remote registry server using the URL specified in O(host).</div>
<div>If set to V(absent) attempt to log out from the remote registry server using the URL specified in O(host).</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>username</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Username for the registry.</div>
<div style="font-size: small; color: darkgreen"><br/>aliases: repo_username</div>
</td>
</tr>
</table>
<br/>
Examples
--------
.. code-block:: yaml
- name: Login to remote registry
kubernetes.core.helm_registry_auth:
username: admin
password: "sample_password"
host: localhost:5000
- name: Logout from remote registry
kubernetes.core.helm_registry_auth:
state: absent
host: localhost:5000
Return Values
-------------
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
.. raw:: html
<table border=0 cellpadding=0 class="documentation-table">
<tr>
<th colspan="1">Key</th>
<th>Returned</th>
<th width="100%">Description</th>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
<b>command</b>
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>always</td>
<td>
<div>Full <code>helm</code> command executed</div>
<br/>
<div style="font-size: smaller"><b>Sample:</b></div>
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">/usr/local/bin/helm registry login oci-registry.domain.example --username=admin --password-stdin --insecure</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
<b>failed</b>
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</div>
</td>
<td>always</td>
<td>
<div>Indicate if the <code>helm</code> command failed</div>
<br/>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
<b>stderr</b>
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>always</td>
<td>
<div>Full <code>helm</code> command stderr, in case you want to display it or examine the event log. Please be note that helm binnary may print messages to stderr even if the command is successful.</div>
<br/>
<div style="font-size: smaller"><b>Sample:</b></div>
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">Login Succeeded\n</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
<b>stderr_lines</b>
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
<div style="font-size: small">
<span style="color: purple">list</span>
</div>
</td>
<td>always</td>
<td>
<div>Full <code>helm</code> command stderr, in case you want to display it or examine the event log</div>
<br/>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
<b>stdout</b>
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>always</td>
<td>
<div>Full <code>helm</code> command stdout, in case you want to display it or examine the event log</div>
<br/>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
<b>stout_lines</b>
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
<div style="font-size: small">
<span style="color: purple">list</span>
</div>
</td>
<td>always</td>
<td>
<div>Full <code>helm</code> command stdout, in case you want to display it or examine the event log</div>
<br/>
</td>
</tr>
</table>
<br/><br/>
Status
------
Authors
~~~~~~~
- Yuriy Novostavskiy (@yurnov)

View File

@@ -158,6 +158,26 @@ Parameters
<div>Include custom resource descriptions in rendered templates.</div> <div>Include custom resource descriptions in rendered templates.</div>
</td> </td>
</tr> </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> <tr>
<td colspan="2"> <td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div> <div class="ansibleOptionAnchor" id="parameter-"></div>

View File

@@ -423,7 +423,7 @@ Parameters
<span style="color: purple">list</span> <span style="color: purple">list</span>
/ <span style="color: purple">elements=string</span> / <span style="color: purple">elements=string</span>
</div> </div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.5.0</div> <div style="font-style: italic; font-size: small; color: darkgreen">added in 3.0.0</div>
</td> </td>
<td> <td>
</td> </td>

View File

@@ -168,7 +168,7 @@ Parameters
<span style="color: purple">list</span> <span style="color: purple">list</span>
/ <span style="color: purple">elements=string</span> / <span style="color: purple">elements=string</span>
</div> </div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.5.0</div> <div style="font-style: italic; font-size: small; color: darkgreen">added in 3.0.0</div>
</td> </td>
<td> <td>
</td> </td>

View File

@@ -121,7 +121,7 @@ Parameters
<td> <td>
<div><code>apply</code> compares the desired resource definition with the previously supplied resource definition, ignoring properties that are automatically generated</div> <div><code>apply</code> compares the desired resource definition with the previously supplied resource definition, ignoring properties that are automatically generated</div>
<div><code>apply</code> works better with Services than &#x27;force=yes&#x27;</div> <div><code>apply</code> works better with Services than &#x27;force=yes&#x27;</div>
<div>mutually exclusive with <code>merge_type</code></div> <div>Mutually exclusive with <code>merge_type</code>.</div>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -216,7 +216,7 @@ Parameters
<div style="font-size: small"> <div style="font-size: small">
<span style="color: purple">boolean</span> <span style="color: purple">boolean</span>
</div> </div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.5.0</div> <div style="font-style: italic; font-size: small; color: darkgreen">added in 3.0.0</div>
</td> </td>
<td> <td>
<ul style="margin: 0; padding: 0"><b>Choices:</b> <ul style="margin: 0; padding: 0"><b>Choices:</b>
@@ -389,7 +389,7 @@ Parameters
<span style="color: purple">list</span> <span style="color: purple">list</span>
/ <span style="color: purple">elements=string</span> / <span style="color: purple">elements=string</span>
</div> </div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.5.0</div> <div style="font-style: italic; font-size: small; color: darkgreen">added in 3.0.0</div>
</td> </td>
<td> <td>
</td> </td>
@@ -513,18 +513,17 @@ Parameters
</td> </td>
<td> <td>
<ul style="margin: 0; padding: 0"><b>Choices:</b> <ul style="margin: 0; padding: 0"><b>Choices:</b>
<li>json</li>
<li>merge</li> <li>merge</li>
<li>strategic-merge</li> <li>strategic-merge</li>
</ul> </ul>
</td> </td>
<td> <td>
<div>Whether to override the default patch merge approach with a specific type. By default, the strategic merge will typically be used.</div> <div>Whether to override the default patch merge approach with a specific type. By default, the strategic merge will typically be used.</div>
<div>For example, Custom Resource Definitions typically aren&#x27;t updatable by the usual strategic merge. You may want to use <code>merge</code> if you see &quot;strategic merge patch format is not supported&quot;</div> <div>For example, Custom Resource Definitions typically aren&#x27;t updatable by the usual strategic merge. You may want to use <code>merge</code> if you see &quot;strategic merge patch format is not supported&quot;.</div>
<div>See <a href='https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment'>https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment</a></div> <div>See <a href='https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment'>https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment</a></div>
<div>If more than one <code>merge_type</code> is given, the merge_types will be tried in order. This defaults to <code>[&#x27;strategic-merge&#x27;, &#x27;merge&#x27;]</code>, which is ideal for using the same parameters on resource kinds that combine Custom Resources and built-in resources.</div> <div>If more than one <code>merge_type</code> is given, the merge_types will be tried in order. This defaults to <code>[&#x27;strategic-merge&#x27;, &#x27;merge&#x27;]</code>, which is ideal for using the same parameters on resource kinds that combine Custom Resources and built-in resources.</div>
<div>mutually exclusive with <code>apply</code></div> <div>Mutually exclusive with <code>apply</code>.</div>
<div><em>merge_type=json</em> is deprecated and will be removed in version 4.0.0. Please use <span class='module'>kubernetes.core.k8s_json_patch</span> instead.</div> <div><em>merge_type=json</em> has been removed in version 4.0.0. Please use <span class='module'>kubernetes.core.k8s_json_patch</span> instead.</div>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@@ -25,7 +25,7 @@ tags:
- openshift - openshift
- okd - okd
- cluster - cluster
version: 3.2.0 version: 5.1.0
build_ignore: build_ignore:
- .DS_Store - .DS_Store
- "*.tar.gz" - "*.tar.gz"

View File

@@ -1,5 +1,5 @@
--- ---
requires_ansible: '>=2.14.0' requires_ansible: '>=2.15.0'
action_groups: action_groups:
helm: helm:

View File

@@ -125,18 +125,18 @@ import json
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable, Constructable from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable, Constructable
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
HAS_K8S_MODULE_HELPER,
k8s_import_exception,
)
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
get_api_client,
)
try: try:
from kubernetes.dynamic.exceptions import DynamicApiError from kubernetes.dynamic.exceptions import DynamicApiError
except ImportError:
pass HAS_K8S_MODULE_HELPER = True
k8s_import_exception = None
except ImportError as e:
HAS_K8S_MODULE_HELPER = False
k8s_import_exception = e
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
get_api_client,
)
def format_dynamic_api_exc(exc): def format_dynamic_api_exc(exc):

View File

@@ -94,7 +94,8 @@ def get_binary_from_path(name, opt_dirs=None):
def run_command(command): def run_command(command):
cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return cmd.communicate() stdout, stderr = cmd.communicate()
return cmd.returncode, stdout, stderr
class LookupModule(LookupBase): class LookupModule(LookupBase):
@@ -140,9 +141,18 @@ class LookupModule(LookupBase):
if enable_helm: if enable_helm:
command += ["--enable-helm"] command += ["--enable-helm"]
(out, err) = run_command(command) (ret, out, err) = run_command(command)
if ret != 0:
if err: if err:
raise AnsibleLookupError( raise AnsibleLookupError(
"kustomize command failed with: {0}".format(err.decode("utf-8")) "kustomize command failed. exit code: {0}, error: {1}".format(
ret, err.decode("utf-8")
)
)
else:
raise AnsibleLookupError(
"kustomize command failed with unknown error. exit code: {0}".format(
ret
)
) )
return [out.decode("utf-8")] return [out.decode("utf-8")]

View File

@@ -149,6 +149,7 @@ def k8s_apply(resource, definition, **kwargs):
force_conflicts=kwargs.get("force_conflicts"), force_conflicts=kwargs.get("force_conflicts"),
field_manager=kwargs.get("field_manager"), field_manager=kwargs.get("field_manager"),
dry_run=kwargs.get("dry_run"), dry_run=kwargs.get("dry_run"),
serialize=kwargs.get("serialize"),
) )
if not existing: if not existing:
return resource.create( return resource.create(
@@ -158,6 +159,7 @@ def k8s_apply(resource, definition, **kwargs):
return resource.get( return resource.get(
name=definition["metadata"]["name"], name=definition["metadata"]["name"],
namespace=definition["metadata"].get("namespace"), namespace=definition["metadata"].get("namespace"),
**kwargs
) )
return resource.patch( return resource.patch(
body=desired, body=desired,

View File

@@ -18,7 +18,7 @@ AUTH_PROXY_HEADERS_SPEC = dict(
) )
AUTH_ARG_SPEC = { AUTH_ARG_SPEC = {
"kubeconfig": {"type": "raw"}, "kubeconfig": {"type": "raw", "no_log": True},
"context": {}, "context": {},
"host": {}, "host": {},
"api_key": {"no_log": True}, "api_key": {"no_log": True},

File diff suppressed because it is too large Load Diff

View File

@@ -77,7 +77,6 @@ def write_temp_kubeconfig(server, validate_certs=True, ca_cert=None, kubeconfig=
class AnsibleHelmModule(object): class AnsibleHelmModule(object):
""" """
An Ansible module class for Kubernetes.core helm modules An Ansible module class for Kubernetes.core helm modules
""" """
@@ -160,11 +159,13 @@ class AnsibleHelmModule(object):
self.helm_env = self._prepare_helm_environment() self.helm_env = self._prepare_helm_environment()
return self.helm_env return self.helm_env
def run_helm_command(self, command, fails_on_error=True): def run_helm_command(self, command, fails_on_error=True, data=None):
if not HAS_YAML: if not HAS_YAML:
self.fail_json(msg=missing_required_lib("PyYAML"), exception=YAML_IMP_ERR) self.fail_json(msg=missing_required_lib("PyYAML"), exception=YAML_IMP_ERR)
rc, out, err = self.run_command(command, environ_update=self.env_update) rc, out, err = self.run_command(
command, environ_update=self.env_update, data=data
)
if fails_on_error and rc != 0: if fails_on_error and rc != 0:
self.fail_json( self.fail_json(
msg="Failure when executing Helm command. Exited {0}.\nstdout: {1}\nstderr: {2}".format( msg="Failure when executing Helm command. Exited {0}.\nstdout: {1}\nstderr: {2}".format(
@@ -184,10 +185,10 @@ class AnsibleHelmModule(object):
def get_helm_version(self): def get_helm_version(self):
command = self.get_helm_binary() + " version" command = self.get_helm_binary() + " version"
rc, out, err = self.run_command(command) rc, out, err = self.run_command(command)
m = re.match(r'version.BuildInfo{Version:"v([0-9\.]*)",', out) m = re.match(r'version.BuildInfo{Version:"v(.*?)",', out)
if m: if m:
return m.group(1) return m.group(1)
m = re.match(r'Client: &version.Version{SemVer:"v([0-9\.]*)", ', out) m = re.match(r'Client: &version.Version{SemVer:"v(.*?)", ', out)
if m: if m:
return m.group(1) return m.group(1)
return None return None

View File

@@ -16,6 +16,7 @@ HELM_AUTH_ARG_SPEC = dict(
type="raw", type="raw",
aliases=["kubeconfig_path"], aliases=["kubeconfig_path"],
fallback=(env_fallback, ["K8S_AUTH_KUBECONFIG"]), fallback=(env_fallback, ["K8S_AUTH_KUBECONFIG"]),
no_log=True,
), ),
host=dict(type="str", fallback=(env_fallback, ["K8S_AUTH_HOST"])), host=dict(type="str", fallback=(env_fallback, ["K8S_AUTH_HOST"])),
ca_cert=dict( ca_cert=dict(

View File

@@ -139,6 +139,7 @@ def perform_action(svc, definition: Dict, params: Dict) -> Dict:
result = {"changed": False, "result": {}} result = {"changed": False, "result": {}}
instance = {} instance = {}
warnings = []
resource = svc.find_resource(kind, api_version, fail=True) resource = svc.find_resource(kind, api_version, fail=True)
definition["kind"] = resource.kind definition["kind"] = resource.kind
@@ -172,7 +173,7 @@ def perform_action(svc, definition: Dict, params: Dict) -> Dict:
return result return result
if params.get("apply"): if params.get("apply"):
instance = svc.apply(resource, definition, existing) instance, warnings = svc.apply(resource, definition, existing)
result["method"] = "apply" result["method"] = "apply"
elif not existing: elif not existing:
if state == "patched": if state == "patched":
@@ -183,16 +184,19 @@ def perform_action(svc, definition: Dict, params: Dict) -> Dict:
) )
) )
return result return result
instance = svc.create(resource, definition) instance, warnings = svc.create(resource, definition)
result["method"] = "create" result["method"] = "create"
result["changed"] = True result["changed"] = True
elif params.get("force", False): elif params.get("force", False):
instance = svc.replace(resource, definition, existing) instance, warnings = svc.replace(resource, definition, existing)
result["method"] = "replace" result["method"] = "replace"
else: else:
instance = svc.update(resource, definition, existing) instance, warnings = svc.update(resource, definition, existing)
result["method"] = "update" result["method"] = "update"
if warnings:
result["warnings"] = warnings
# If needed, wait and/or create diff # If needed, wait and/or create diff
success = True success = True

View File

@@ -2,6 +2,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
import copy import copy
from json import loads
from re import compile
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
from ansible.module_utils.common.dict_transformations import dict_merge from ansible.module_utils.common.dict_transformations import dict_merge
@@ -142,18 +144,12 @@ class K8sService:
name: str, name: str,
namespace: str, namespace: str,
merge_type: str = None, merge_type: str = None,
) -> Dict: ) -> Tuple[Dict, List[str]]:
if merge_type == "json":
self.module.deprecate(
msg="json as a merge_type value is deprecated. Please use the k8s_json_patch module instead.",
version="4.0.0",
collection_name="kubernetes.core",
)
try: try:
params = dict(name=name, namespace=namespace) params = dict(name=name, namespace=namespace, serialize=False)
if merge_type: if merge_type:
params["content_type"] = "application/{0}-patch+json".format(merge_type) params["content_type"] = "application/{0}-patch+json".format(merge_type)
return self.client.patch(resource, definition, **params).to_dict() return decode_response(self.client.patch(resource, definition, **params))
except Exception as e: except Exception as e:
reason = e.body if hasattr(e, "body") else e reason = e.body if hasattr(e, "body") else e
msg = "Failed to patch object: {0}".format(reason) msg = "Failed to patch object: {0}".format(reason)
@@ -330,17 +326,19 @@ class K8sService:
result["resources"].append(hide_fields(res, hidden_fields)) result["resources"].append(hide_fields(res, hidden_fields))
return result return result
def create(self, resource: Resource, definition: Dict) -> Dict: def create(self, resource: Resource, definition: Dict) -> Tuple[Dict, List[str]]:
namespace = definition["metadata"].get("namespace") namespace = definition["metadata"].get("namespace")
name = definition["metadata"].get("name") name = definition["metadata"].get("name")
if self._client_side_dry_run: if self._client_side_dry_run:
k8s_obj = _encode_stringdata(definition) return _encode_stringdata(definition), []
else:
try: try:
k8s_obj = self.client.create( return decode_response(
resource, definition, namespace=namespace self.client.create(
).to_dict() resource, definition, namespace=namespace, serialize=False
)
)
except ConflictError: except ConflictError:
# Some resources, like ProjectRequests, can't be created multiple times, # Some resources, like ProjectRequests, can't be created multiple times,
# because the resources that they create don't match their kind # because the resources that they create don't match their kind
@@ -351,102 +349,101 @@ class K8sService:
name name
) )
) )
return dict() return dict(), []
except Exception as e: except Exception as e:
reason = e.body if hasattr(e, "body") else e reason = e.body if hasattr(e, "body") else e
msg = "Failed to create object: {0}".format(reason) msg = "Failed to create object: {0}".format(reason)
raise CoreException(msg) from e raise CoreException(msg) from e
return k8s_obj
def apply( def apply(
self, self,
resource: Resource, resource: Resource,
definition: Dict, definition: Dict,
existing: Optional[ResourceInstance] = None, existing: Optional[ResourceInstance] = None,
) -> Dict: ) -> Tuple[Dict, List[str]]:
namespace = definition["metadata"].get("namespace") namespace = definition["metadata"].get("namespace")
server_side_apply = self.module.params.get("server_side_apply") server_side_apply = self.module.params.get("server_side_apply")
if server_side_apply: if server_side_apply:
requires("kubernetes", "19.15.0", reason="to use server side apply") requires("kubernetes", "19.15.0", reason="to use server side apply")
if self._client_side_dry_run: if self._client_side_dry_run:
ignored, patch = apply_object(resource, _encode_stringdata(definition)) ignored, patch = apply_object(resource, _encode_stringdata(definition))
if existing: if existing:
k8s_obj = dict_merge(existing.to_dict(), patch) return dict_merge(existing.to_dict(), patch), []
else:
k8s_obj = patch
else: else:
return patch, []
try: try:
params = {} params = {}
if server_side_apply: if server_side_apply:
params["server_side"] = True params["server_side"] = True
params.update(server_side_apply) params.update(server_side_apply)
k8s_obj = self.client.apply( return decode_response(
resource, definition, namespace=namespace, **params self.client.apply(
).to_dict() resource, definition, namespace=namespace, serialize=False, **params
)
)
except Exception as e: except Exception as e:
reason = e.body if hasattr(e, "body") else e reason = e.body if hasattr(e, "body") else e
msg = "Failed to apply object: {0}".format(reason) msg = "Failed to apply object: {0}".format(reason)
raise CoreException(msg) from e raise CoreException(msg) from e
return k8s_obj
def replace( def replace(
self, self,
resource: Resource, resource: Resource,
definition: Dict, definition: Dict,
existing: ResourceInstance, existing: ResourceInstance,
) -> Dict: ) -> Tuple[Dict, List[str]]:
append_hash = self.module.params.get("append_hash", False) append_hash = self.module.params.get("append_hash", False)
name = definition["metadata"].get("name") name = definition["metadata"].get("name")
namespace = definition["metadata"].get("namespace") namespace = definition["metadata"].get("namespace")
if self._client_side_dry_run: if self._client_side_dry_run:
k8s_obj = _encode_stringdata(definition) return _encode_stringdata(definition), []
else:
try: try:
k8s_obj = self.client.replace( return decode_response(
self.client.replace(
resource, resource,
definition, definition,
name=name, name=name,
namespace=namespace, namespace=namespace,
append_hash=append_hash, append_hash=append_hash,
).to_dict() serialize=False,
)
)
except Exception as e: except Exception as e:
reason = e.body if hasattr(e, "body") else e reason = e.body if hasattr(e, "body") else e
msg = "Failed to replace object: {0}".format(reason) msg = "Failed to replace object: {0}".format(reason)
raise CoreException(msg) from e raise CoreException(msg) from e
return k8s_obj
def update( def update(
self, resource: Resource, definition: Dict, existing: ResourceInstance self, resource: Resource, definition: Dict, existing: ResourceInstance
) -> Dict: ) -> Tuple[Dict, List[str]]:
name = definition["metadata"].get("name") name = definition["metadata"].get("name")
namespace = definition["metadata"].get("namespace") namespace = definition["metadata"].get("namespace")
if self._client_side_dry_run: if self._client_side_dry_run:
k8s_obj = dict_merge(existing.to_dict(), _encode_stringdata(definition)) return dict_merge(existing.to_dict(), _encode_stringdata(definition)), []
else:
exception = None exception = None
for merge_type in self.module.params.get("merge_type") or [ for merge_type in self.module.params.get("merge_type") or [
"strategic-merge", "strategic-merge",
"merge", "merge",
]: ]:
try: try:
k8s_obj = self.patch_resource( return self.patch_resource(
resource, resource,
definition, definition,
name, name,
namespace, namespace,
merge_type=merge_type, merge_type=merge_type,
) )
exception = None
except CoreException as e: except CoreException as e:
exception = e exception = e
continue continue
break
if exception:
raise exception raise exception
return k8s_obj
def delete( def delete(
self, self,
@@ -543,3 +540,83 @@ def hide_field(definition: dict, hidden_field: str) -> dict:
else: else:
del definition[split[0]] del definition[split[0]]
return definition return definition
def decode_response(resp) -> Tuple[Dict, List[str]]:
"""
This function decodes unserialized responses from the Kubernetes python
client and decodes the RFC2616 14.46 warnings found in the response
headers.
"""
obj = ResourceInstance(None, loads(resp.data.decode("utf8"))).to_dict()
warnings = []
if (
resp.headers is not None
and "warning" in resp.headers
and resp.headers["warning"] is not None
):
warnings = resp.headers["warning"].split(", ")
return obj, decode_warnings(warnings)
def decode_warnings(warnings: str) -> List[str]:
"""
This function decodes RFC2616 14.46 warnings in a simplified way, where
only the warn-texts are returned in a list.
"""
p = compile('\\d{3} .+ (".+")')
decoded = []
for warning in warnings:
m = p.match(warning)
if m:
try:
parsed, unused = parse_quoted_string(m.group(1))
decoded.append(parsed)
except ValueError:
continue
return decoded
def parse_quoted_string(quoted_string: str) -> Tuple[str, str]:
"""
This function was adapted from:
https://github.com/kubernetes/apimachinery/blob/bb8822152cabfb4f34dbc26270f874ce53db50de/pkg/util/net/http.go#L609
"""
if len(quoted_string) == 0:
raise ValueError("invalid quoted string: 0-length")
if quoted_string[0] != '"':
raise ValueError("invalid quoted string: missing initial quote")
quoted_string = quoted_string[1:]
remainder = ""
escaping = False
closed_quote = False
result = []
for i, b in enumerate(quoted_string):
if b == '"':
if escaping:
result.append(b)
escaping = False
else:
closed_quote = True
remainder_start = i + 1
remainder = quoted_string[remainder_start:].strip()
break
elif b == "\\":
if escaping:
result.append(b)
escaping = False
else:
escaping = True
else:
result.append(b)
escaping = False
if not closed_quote:
raise ValueError("invalid quoted string: missing closing quote")
return "".join(result), remainder

View File

@@ -51,7 +51,7 @@ def daemonset_ready(daemonset: ResourceInstance) -> bool:
return bool( return bool(
daemonset.status daemonset.status
and daemonset.status.desiredNumberScheduled is not None and daemonset.status.desiredNumberScheduled is not None
and daemonset.status.updatedNumberScheduled and (daemonset.status.updatedNumberScheduled or 0)
== daemonset.status.desiredNumberScheduled == daemonset.status.desiredNumberScheduled
and daemonset.status.numberReady == daemonset.status.desiredNumberScheduled and daemonset.status.numberReady == daemonset.status.desiredNumberScheduled
and daemonset.status.observedGeneration == daemonset.metadata.generation and daemonset.status.observedGeneration == daemonset.metadata.generation

View File

@@ -137,14 +137,14 @@ options:
- If I(reset_values) is set to C(True), this is ignored. - If I(reset_values) is set to C(True), this is ignored.
type: bool type: bool
required: false required: false
version_added: 2.5.0 version_added: 3.0.0
reset_values: reset_values:
description: description:
- When upgrading package, reset the values to the ones built into the chart. - When upgrading package, reset the values to the ones built into the chart.
type: bool type: bool
required: false required: false
default: True default: True
version_added: 2.5.0 version_added: 3.0.0
#Helm options #Helm options
disable_hook: disable_hook:

View File

@@ -189,7 +189,7 @@ def main():
repo_password=dict( repo_password=dict(
type="str", no_log=True, aliases=["password", "chart_repo_password"] type="str", no_log=True, aliases=["password", "chart_repo_password"]
), ),
pass_credentials=dict(type="bool", default=False), pass_credentials=dict(type="bool", default=False, no_log=False),
skip_tls_certs_check=dict(type="bool", default=False), skip_tls_certs_check=dict(type="bool", default=False),
chart_devel=dict(type="bool"), chart_devel=dict(type="bool"),
untar_chart=dict(type="bool", default=False), untar_chart=dict(type="bool", default=False),

View File

@@ -0,0 +1,238 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: © Ericsson AB 2024
# 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_registry_auth
short_description: Helm registry authentication module
version_added: 5.1.0
author:
- Yuriy Novostavskiy (@yurnov)
requirements:
- "helm (https://github.com/helm/helm/releases) => 3.8.0"
description:
- Helm registry authentication module allows you to login C(helm registry login) and logout C(helm registry logout) from a Helm registry.
options:
state:
description:
- Desired state of the registry.
- If set to V(present) attempt to log in to the remote registry server using the URL specified in O(host).
- If set to V(absent) attempt to log out from the remote registry server using the URL specified in O(host).
required: false
default: present
choices: ['present', 'absent']
type: str
host:
description:
- Provide a URL for accessing the registry.
required: true
aliases: [ registry_url ]
type: str
insecure:
description:
- Allow connections to SSL sites without certs.
required: false
default: false
type: bool
username:
description:
- Username for the registry.
required: false
type: str
aliases: [ repo_username ]
password:
description:
- Password for the registry.
required: false
type: str
aliases: [ repo_password ]
key_file:
description:
- Path to the client key SSL file for identify registry client using this key file.
required: false
type: path
cert_file:
description:
- Path to the client certificate SSL file for identify registry client using this certificate file.
required: false
type: path
ca_file:
description:
- Path to the CA certificate SSL file for verify registry server certificate.
required: false
type: path
binary_path:
description:
- The path of a helm binary to use.
required: false
type: path
"""
EXAMPLES = r"""
- name: Login to remote registry
kubernetes.core.helm_registry_auth:
username: admin
password: "sample_password"
host: localhost:5000
- name: Logout from remote registry
kubernetes.core.helm_registry_auth:
state: absent
host: localhost:5000
"""
RETURN = r"""
stdout:
type: str
description: Full C(helm) command stdout, in case you want to display it or examine the event log
returned: always
stout_lines:
type: list
description: Full C(helm) command stdout, in case you want to display it or examine the event log
returned: always
stderr:
type: str
description: >-
Full C(helm) command stderr, in case you want to display it or examine the event log.
Please be note that helm binnary may print messages to stderr even if the command is successful.
returned: always
sample: 'Login Succeeded\n'
stderr_lines:
type: list
description: Full C(helm) command stderr, in case you want to display it or examine the event log
returned: always
command:
type: str
description: Full C(helm) command executed
returned: always
sample: '/usr/local/bin/helm registry login oci-registry.domain.example --username=admin --password-stdin --insecure'
failed:
type: bool
description: Indicate if the C(helm) command failed
returned: always
sample: false
"""
from ansible_collections.kubernetes.core.plugins.module_utils.helm import (
AnsibleHelmModule,
)
def arg_spec():
return dict(
binary_path=dict(type="path", required=False),
host=dict(type="str", aliases=["registry_url"], required=True),
state=dict(default="present", choices=["present", "absent"], required=False),
insecure=dict(type="bool", default=False, required=False),
username=dict(type="str", aliases=["repo_username"], required=False),
password=dict(
type="str", aliases=["repo_password"], no_log=True, required=False
),
key_file=dict(type="path", required=False),
cert_file=dict(type="path", required=False),
ca_file=dict(type="path", required=False),
)
def login(
command,
host,
insecure,
username,
password,
key_file,
cert_file,
ca_file,
):
login_command = command + " registry login " + host
if username is not None and password is not None:
login_command += " --username=" + username + " --password-stdin"
if insecure:
login_command += " --insecure"
if key_file is not None:
login_command += " --key-file=" + key_file
if cert_file is not None:
login_command += " --cert-file=" + cert_file
if ca_file is not None:
login_command += " --ca-file=" + ca_file
return login_command
def logout(command, host):
return command + " registry logout " + host
def main():
global module
module = AnsibleHelmModule(
argument_spec=arg_spec(),
required_together=[["username", "password"]],
supports_check_mode=True,
)
changed = False
host = module.params.get("host")
state = module.params.get("state")
insecure = module.params.get("insecure")
username = module.params.get("username")
password = module.params.get("password")
key_file = module.params.get("key_file")
cert_file = module.params.get("cert_file")
ca_file = module.params.get("ca_file")
helm_cmd = module.get_helm_binary()
if state == "absent":
helm_cmd = logout(helm_cmd, host)
changed = True
elif state == "present":
helm_cmd = login(
helm_cmd, host, insecure, username, password, key_file, cert_file, ca_file
)
changed = True
if module.check_mode:
module.exit_json(changed=changed, command=helm_cmd)
rc, out, err = module.run_helm_command(
helm_cmd, data=password, fails_on_error=False
)
if rc != 0:
if state == "absent" and "Error: not logged in" in err:
changed = False
else:
module.fail_json(
msg="Failure when executing Helm command. Exited {0}.\nstdout: {1}\nstderr: {2}".format(
rc, out, err
),
stderr=err,
command=helm_cmd,
)
module.exit_json(changed=changed, stdout=out, stderr=err, command=helm_cmd)
if __name__ == "__main__":
main()

View File

@@ -72,6 +72,13 @@ options:
- If the directory already exists, it will be overwritten. - If the directory already exists, it will be overwritten.
required: false required: false
type: path 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: release_name:
description: description:
- Release name to use in rendered templates. - Release name to use in rendered templates.
@@ -221,6 +228,7 @@ def template(
dependency_update=None, dependency_update=None,
disable_hook=None, disable_hook=None,
output_dir=None, output_dir=None,
insecure_registry=None,
show_only=None, show_only=None,
release_name=None, release_name=None,
release_namespace=None, release_namespace=None,
@@ -251,6 +259,9 @@ def template(
if output_dir: if output_dir:
cmd += " --output-dir=" + output_dir cmd += " --output-dir=" + output_dir
if insecure_registry:
cmd += " --insecure-skip-tls-verify"
if show_only: if show_only:
for template in show_only: for template in show_only:
cmd += " -s " + template cmd += " -s " + template
@@ -289,6 +300,7 @@ def main():
include_crds=dict(type="bool", default=False), include_crds=dict(type="bool", default=False),
release_name=dict(type="str", aliases=["name"]), release_name=dict(type="str", aliases=["name"]),
output_dir=dict(type="path"), output_dir=dict(type="path"),
insecure_registry=dict(type="bool", default=False),
release_namespace=dict(type="str"), release_namespace=dict(type="str"),
release_values=dict(type="dict", default={}, aliases=["values"]), release_values=dict(type="dict", default={}, aliases=["values"]),
show_only=dict(type="list", default=[], elements="str"), show_only=dict(type="list", default=[], elements="str"),
@@ -308,6 +320,7 @@ def main():
include_crds = module.params.get("include_crds") include_crds = module.params.get("include_crds")
release_name = module.params.get("release_name") release_name = module.params.get("release_name")
output_dir = module.params.get("output_dir") output_dir = module.params.get("output_dir")
insecure_registry = module.params.get("insecure_registry")
show_only = module.params.get("show_only") show_only = module.params.get("show_only")
release_namespace = module.params.get("release_namespace") release_namespace = module.params.get("release_namespace")
release_values = module.params.get("release_values") release_values = module.params.get("release_values")
@@ -337,6 +350,7 @@ def main():
disable_hook=disable_hook, disable_hook=disable_hook,
release_name=release_name, release_name=release_name,
output_dir=output_dir, output_dir=output_dir,
insecure_registry=insecure_registry,
release_namespace=release_namespace, release_namespace=release_namespace,
release_values=release_values, release_values=release_values,
show_only=show_only, show_only=show_only,

View File

@@ -57,15 +57,14 @@ options:
- Whether to override the default patch merge approach with a specific type. By default, the strategic - Whether to override the default patch merge approach with a specific type. By default, the strategic
merge will typically be used. merge will typically be used.
- For example, Custom Resource Definitions typically aren't updatable by the usual strategic merge. You may - For example, Custom Resource Definitions typically aren't updatable by the usual strategic merge. You may
want to use C(merge) if you see "strategic merge patch format is not supported" want to use C(merge) if you see "strategic merge patch format is not supported".
- See U(https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment) - See U(https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment)
- If more than one C(merge_type) is given, the merge_types will be tried in order. This defaults to - If more than one C(merge_type) is given, the merge_types will be tried in order. This defaults to
C(['strategic-merge', 'merge']), which is ideal for using the same parameters on resource kinds that C(['strategic-merge', 'merge']), which is ideal for using the same parameters on resource kinds that
combine Custom Resources and built-in resources. combine Custom Resources and built-in resources.
- mutually exclusive with C(apply) - Mutually exclusive with C(apply).
- I(merge_type=json) is deprecated and will be removed in version 4.0.0. Please use M(kubernetes.core.k8s_json_patch) instead. - I(merge_type=json) has been removed in version 4.0.0. Please use M(kubernetes.core.k8s_json_patch) instead.
choices: choices:
- json
- merge - merge
- strategic-merge - strategic-merge
type: list type: list
@@ -101,7 +100,7 @@ options:
- C(apply) compares the desired resource definition with the previously supplied resource definition, - C(apply) compares the desired resource definition with the previously supplied resource definition,
ignoring properties that are automatically generated ignoring properties that are automatically generated
- C(apply) works better with Services than 'force=yes' - C(apply) works better with Services than 'force=yes'
- mutually exclusive with C(merge_type) - Mutually exclusive with C(merge_type).
default: False default: False
type: bool type: bool
template: template:
@@ -182,7 +181,7 @@ options:
- This parameter can be used with C(label_selectors) to restrict the resources to be deleted. - This parameter can be used with C(label_selectors) to restrict the resources to be deleted.
type: bool type: bool
default: false default: false
version_added: 2.5.0 version_added: 3.0.0
aliases: aliases:
- all - all
hidden_fields: hidden_fields:
@@ -192,7 +191,7 @@ options:
- Only field definitions that don't reference list items are supported (so V(spec.containers[0]) would not work) - Only field definitions that don't reference list items are supported (so V(spec.containers[0]) would not work)
type: list type: list
elements: str elements: str
version_added: 2.5.0 version_added: 3.0.0
requirements: requirements:
- "python >= 3.9" - "python >= 3.9"
@@ -460,7 +459,7 @@ def argspec():
argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC)) argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC))
argument_spec.update(copy.deepcopy(WAIT_ARG_SPEC)) argument_spec.update(copy.deepcopy(WAIT_ARG_SPEC))
argument_spec["merge_type"] = dict( argument_spec["merge_type"] = dict(
type="list", elements="str", choices=["json", "merge", "strategic-merge"] type="list", elements="str", choices=["merge", "strategic-merge"]
) )
argument_spec["validate"] = dict(type="dict", default=None, options=validate_spec()) argument_spec["validate"] = dict(type="dict", default=None, options=validate_spec())
argument_spec["append_hash"] = dict(type="bool", default=False) argument_spec["append_hash"] = dict(type="bool", default=False)

View File

@@ -47,7 +47,7 @@ options:
- This option has effect only when C(state) is set to I(drain). - This option has effect only when C(state) is set to I(drain).
type: list type: list
elements: str elements: str
version_added: 2.5.0 version_added: 3.0.0
aliases: aliases:
- label_selectors - label_selectors
delete_options: delete_options:
@@ -106,6 +106,7 @@ EXAMPLES = r"""
kubernetes.core.k8s_drain: kubernetes.core.k8s_drain:
state: drain state: drain
name: foo name: foo
delete_options:
force: yes 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. - 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.
@@ -143,6 +144,7 @@ result:
""" """
import copy import copy
import json
import time import time
import traceback import traceback
from datetime import datetime from datetime import datetime
@@ -187,6 +189,17 @@ except ImportError:
HAS_EVICTION_API = False 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): def filter_pods(pods, force, ignore_daemonset, delete_emptydir_data):
k8s_kind_mirror = "kubernetes.io/config.mirror" k8s_kind_mirror = "kubernetes.io/config.mirror"
daemonSet, unmanaged, mirror, localStorage, to_delete = [], [], [], [], [] daemonSet, unmanaged, mirror, localStorage, to_delete = [], [], [], [], []
@@ -291,16 +304,19 @@ class K8sDrainAnsible(object):
return (datetime.now() - start).seconds return (datetime.now() - start).seconds
response = None response = None
pod = pods.pop() pod = None
while (_elapsed_time() < wait_timeout or wait_timeout == 0) and pods: while (_elapsed_time() < wait_timeout or wait_timeout == 0) and pods:
if not pod: if not pod:
pod = pods.pop() pod = pods[-1]
try: try:
response = self._api_instance.read_namespaced_pod( response = self._api_instance.read_namespaced_pod(
namespace=pod[0], name=pod[1] namespace=pod[0], name=pod[1]
) )
if not response: if not response or response.spec.node_name != self._module.params.get(
"name"
):
pod = None pod = None
del pods[-1]
time.sleep(wait_sleep) time.sleep(wait_sleep)
except ApiException as exc: except ApiException as exc:
if exc.reason != "Not Found": if exc.reason != "Not Found":
@@ -308,6 +324,7 @@ class K8sDrainAnsible(object):
msg="Exception raised: {0}".format(exc.reason) msg="Exception raised: {0}".format(exc.reason)
) )
pod = None pod = None
del pods[-1]
except Exception as e: except Exception as e:
self._module.fail_json(msg="Exception raised: {0}".format(to_native(e))) self._module.fail_json(msg="Exception raised: {0}".format(to_native(e)))
if not pods: if not pods:
@@ -334,7 +351,7 @@ class K8sDrainAnsible(object):
if exc.reason != "Not Found": if exc.reason != "Not Found":
self._module.fail_json( self._module.fail_json(
msg="Failed to delete pod {0}/{1} due to: {2}".format( 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: except Exception as exc:

View File

@@ -135,7 +135,7 @@ from ansible.module_utils._text import to_native
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import ( from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import (
AnsibleModule, AnsibleModule,
) )
from ansible_collections.kubernetes.core.plugins.module_utils.common import ( from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, AUTH_ARG_SPEC,
) )
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import ( from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
@@ -219,12 +219,6 @@ def execute_module(module, client):
else: else:
rc = int(err["details"]["causes"][0]["message"]) rc = int(err["details"]["causes"][0]["message"])
module.deprecate(
"The 'return_code' return key is being renamed to 'rc'. "
"Both keys are being returned for now to allow users to migrate their automation.",
version="4.0.0",
collection_name="kubernetes.core",
)
module.exit_json( module.exit_json(
# Some command might change environment, but ultimately failing at end # Some command might change environment, but ultimately failing at end
changed=True, changed=True,

View File

@@ -51,7 +51,7 @@ options:
- Only field definitions that don't reference list items are supported (so V(spec.containers[0]) would not work) - Only field definitions that don't reference list items are supported (so V(spec.containers[0]) would not work)
type: list type: list
elements: str elements: str
version_added: 2.5.0 version_added: 3.0.0
extends_documentation_fragment: extends_documentation_fragment:
- kubernetes.core.k8s_auth_options - kubernetes.core.k8s_auth_options

View File

@@ -4,4 +4,4 @@
loop_control: loop_control:
loop_var: helm_version loop_var: helm_version
with_items: with_items:
- "v3.7.0" - "v3.8.0"

View File

@@ -17,8 +17,7 @@
- name: Initial chart installation - name: Initial chart installation
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
chart_ref: redis chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-redis release_name: test-redis
release_namespace: "{{ helm_namespace }}" release_namespace: "{{ helm_namespace }}"
create_namespace: true create_namespace: true
@@ -42,8 +41,7 @@
- name: Upgrade chart using reuse_values=true - name: Upgrade chart using reuse_values=true
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
chart_ref: redis chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-redis release_name: test-redis
release_namespace: "{{ helm_namespace }}" release_namespace: "{{ helm_namespace }}"
reuse_values: true reuse_values: true

View File

@@ -73,7 +73,7 @@
assert: assert:
that: that:
- install is changed - install is changed
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - install.status.chart == chart_test+"-"+chart_test_version
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- name: Check helm_info content - name: Check helm_info content
@@ -95,7 +95,7 @@
- name: "Assert that {{ chart_test }} is installed from {{ source }} with helm_info" - name: "Assert that {{ chart_test }} is installed from {{ source }} with helm_info"
assert: assert:
that: that:
- content_info.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - content_info.status.chart == chart_test+"-"+chart_test_version
- content_info.status.status | lower == 'deployed' - content_info.status.status | lower == 'deployed'
- release_state_content_info.status.status | lower == 'deployed' - release_state_content_info.status.status | lower == 'deployed'
@@ -112,7 +112,7 @@
assert: assert:
that: that:
- install is not changed - install is not changed
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - install.status.chart == chart_test+"-"+chart_test_version
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- name: "Add vars to {{ chart_test }} from {{ source }}" - name: "Add vars to {{ chart_test }} from {{ source }}"
@@ -130,7 +130,7 @@
that: that:
- install is changed - install is changed
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - install.status.chart == chart_test+"-"+chart_test_version
- "install.status['values'].revisionHistoryLimit == 0" - "install.status['values'].revisionHistoryLimit == 0"
- name: Check idempotency after adding vars - name: Check idempotency after adding vars
@@ -148,7 +148,7 @@
that: that:
- install is not changed - install is not changed
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - install.status.chart == chart_test+"-"+chart_test_version
- "install.status['values'].revisionHistoryLimit == 0" - "install.status['values'].revisionHistoryLimit == 0"
- name: "Remove Vars to {{ chart_test }} from {{ source }}" - name: "Remove Vars to {{ chart_test }} from {{ source }}"
@@ -165,7 +165,7 @@
that: that:
- install is changed - install is changed
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - install.status.chart == chart_test+"-"+chart_test_version
- install.status['values'] == {} - install.status['values'] == {}
- name: Check idempotency after removing vars - name: Check idempotency after removing vars
@@ -182,7 +182,7 @@
that: that:
- install is not changed - install is not changed
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - install.status.chart == chart_test+"-"+chart_test_version
- install.status['values'] == {} - install.status['values'] == {}
- name: "Upgrade {{ chart_test }} from {{ source }}" - name: "Upgrade {{ chart_test }} from {{ source }}"
@@ -199,7 +199,7 @@
that: that:
- install is changed - install is changed
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version_upgrade }}" - install.status.chart == chart_test+"-"+chart_test_version_upgrade
- name: Check idempotency after upgrade - name: Check idempotency after upgrade
helm: helm:
@@ -215,7 +215,7 @@
that: that:
- install is not changed - install is not changed
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version_upgrade }}" - install.status.chart == chart_test+"-"+chart_test_version_upgrade
- name: "Remove {{ chart_test }} from {{ source }}" - name: "Remove {{ chart_test }} from {{ source }}"
helm: helm:
@@ -316,7 +316,7 @@
that: that:
- install is changed - install is changed
- install.status.status | lower == 'deployed' - install.status.status | lower == 'deployed'
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}" - install.status.chart == chart_test+"-"+chart_test_version
- "install.status['values'].revisionHistoryLimit == 0" - "install.status['values'].revisionHistoryLimit == 0"
- name: "Install {{ chart_test }} from {{ source }} with values_files (again)" - name: "Install {{ chart_test }} from {{ source }} with values_files (again)"
@@ -357,7 +357,7 @@
- result is changed - result is changed
- result is not failed - result is not failed
- result.rc == 0 - result.rc == 0
- result.command is match("{{ helm_binary }} template {{ chart_source }}") - result.command is match(helm_binary+" template "+chart_source)
- name: Check templates created - name: Check templates created
stat: stat:
@@ -374,8 +374,8 @@
chart_ref: "{{ chart_source }}" chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit) }}" chart_version: "{{ chart_source_version | default(omit) }}"
disable_hook: True disable_hook: True
release_name: "MyRelease" release_name: "myrelease"
release_namespace: "MyReleaseNamespace" release_namespace: "myreleasenamespace"
show_only: show_only:
- "templates/configmap.yaml" - "templates/configmap.yaml"
release_values: release_values:
@@ -388,7 +388,7 @@
- result is changed - result is changed
- result is not failed - result is not failed
- result.rc == 0 - 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") - result.stdout is search("ThisValue")
when: chart_source is search("test-chart") when: chart_source is search("test-chart")
# limit assertion of test result to controlled (local) chart_source # limit assertion of test result to controlled (local) chart_source

View File

@@ -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"

View File

@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ default "ansible-configmap" .Values.myConfigmapName }}
data:
myValue: {{ default "test" .Values.myValue }}
deploymentTime: {{ now }}

View File

@@ -2,3 +2,4 @@
dependencies: dependencies:
- remove_namespace - remove_namespace
- install_helm - install_helm
- setup_helm_registry

View File

@@ -2,7 +2,6 @@
- name: Test helm diff functionality - name: Test helm diff functionality
vars: vars:
test_chart_ref: "/tmp/test-chart" test_chart_ref: "/tmp/test-chart"
redis_chart_version: '17.0.5'
block: block:
@@ -24,7 +23,7 @@
name: test-chart name: test-chart
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}" chart_ref: "{{ test_chart_ref }}"
create_namespace: yes create_namespace: true
register: install register: install
- assert: - assert:
@@ -49,8 +48,8 @@
name: test-chart name: test-chart
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}" chart_ref: "{{ test_chart_ref }}"
check_mode: yes check_mode: true
diff: yes diff: true
register: diff_result register: diff_result
- name: Check if helm diff check is correct - name: Check if helm diff check is correct
@@ -79,7 +78,7 @@
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}" chart_ref: "{{ test_chart_ref }}"
check_mode: yes check_mode: yes
diff: yes diff: true
register: diff_result register: diff_result
- name: Check if no diff in check mode when no change - name: Check if no diff in check mode when no change
@@ -101,7 +100,7 @@
- name: Modify values - name: Modify values
blockinfile: blockinfile:
create: yes create: true
path: "{{ test_chart_ref }}/values.yml" path: "{{ test_chart_ref }}/values.yml"
block: | block: |
--- ---
@@ -206,52 +205,76 @@
- install is not changed - install is not changed
# Test helm diff with chart_repo_url # Test helm diff with chart_repo_url
- name: Define Redis chart values
set_fact:
redis_chart_values:
commonLabels:
phase: testing
company: RedHat
image:
tag: 6.2.6-debian-10-r135
architecture: standalone
- name: Install Redis chart
helm:
binary_path: "{{ helm_binary }}"
chart_repo_url: https://charts.bitnami.com/bitnami
chart_ref: redis
namespace: "{{ helm_namespace }}"
name: redis-chart
chart_version: "{{ redis_chart_version }}"
release_values: "{{ redis_chart_values }}"
- name: Upgrade Redis chart
helm:
binary_path: "{{ helm_binary }}"
chart_repo_url: https://charts.bitnami.com/bitnami
chart_ref: redis
namespace: "{{ helm_namespace }}"
name: redis-chart
chart_version: "{{ redis_chart_version }}"
release_values: "{{ redis_chart_values }}"
check_mode: yes
register: redis_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 - name: Uninstall helm diff
helm_plugin: helm_plugin:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
state: absent state: absent
plugin_name: diff plugin_name: diff
ignore_errors: yes ignore_errors: true
- name: Define chart variables
set_fact:
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_ref: "{{ test_chart_ref_url }}"
chart_version: 0.1.0
namespace: "{{ helm_namespace }}"
name: another-chart
release_values: "{{ test_chart_values }}"
- name: Upgrade chart
helm:
binary_path: "{{ helm_binary }}"
chart_ref: "{{ test_chart_ref_url }}"
chart_version: 0.1.0
namespace: "{{ helm_namespace }}"
name: another-chart
release_values: "{{ test_chart_values }}"
check_mode: true
register: _upgrade
- name: Assert that module raised a warning
assert:
that:
- 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) - name: Install helm diff (version=3.4.1)
helm_plugin: helm_plugin:
@@ -260,37 +283,36 @@
plugin_path: https://github.com/databus23/helm-diff plugin_path: https://github.com/databus23/helm-diff
plugin_version: 3.4.1 plugin_version: 3.4.1
- name: Upgrade Redis chart once again - name: Upgrade chart once again
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
chart_repo_url: https://charts.bitnami.com/bitnami chart_ref: "{{ test_chart_ref_url }}"
chart_ref: redis chart_version: 0.1.0
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
name: redis-chart name: another-chart
chart_version: "{{ redis_chart_version }}" release_values: "{{ test_chart_values }}"
release_values: "{{ redis_chart_values }}" check_mode: true
check_mode: yes register: _upgrade_2
register: redis_upgrade_2
- name: Assert that module raised a warning - name: Assert that module raised a warning
assert: assert:
that: that:
- redis_upgrade_2.changed - _upgrade_2.changed
- redis_upgrade_2.warnings is not defined - _upgrade_2.warnings is not defined
always: always:
- name: Remove chart directory - name: Remove chart directory
file: file:
path: "{{ test_chart_ref }}" path: "{{ test_chart_ref }}"
state: absent state: absent
ignore_errors: yes ignore_errors: true
- name: Uninstall helm diff - name: Uninstall helm diff
helm_plugin: helm_plugin:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
state: absent state: absent
plugin_name: diff plugin_name: diff
ignore_errors: yes ignore_errors: true
- name: Remove helm namespace - name: Remove helm namespace
k8s: k8s:
@@ -299,6 +321,6 @@
name: "{{ helm_namespace }}" name: "{{ helm_namespace }}"
state: absent state: absent
wait: true wait: true
ignore_errors: yes ignore_errors: true
- include_tasks: reuse_values.yml - include_tasks: reuse_values.yml

View File

@@ -18,7 +18,12 @@
- set_fact: - set_fact:
saved_kubeconfig_path: "{{ _dir.path }}/config" 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 - name: Copy default kubeconfig
copy: copy:
remote_src: true remote_src: true
@@ -59,14 +64,14 @@
- plugin_info.plugin_list != [] - plugin_info.plugin_list != []
# helm_repository, helm, helm_info # helm_repository, helm, helm_info
- name: Add test_bitnami chart repository - name: 'Add "{{ helm_repo_name }}" chart repository'
helm_repository: helm_repository:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
name: test_bitnami name: "{{ helm_repo_name }}"
kubeconfig: "{{ test_kubeconfig | default(omit) }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}"
repo_url: https://charts.bitnami.com/bitnami repo_url: "{{ helm_repo_url }}"
register: repository register: repository
- name: Assert that repository was added - name: Assert that repository was added
@@ -77,8 +82,8 @@
- name: Install chart from repository added before - name: Install chart from repository added before
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
name: rabbitmq name: "{{ helm_release_name }}"
chart_ref: test_bitnami/rabbitmq chart_ref: "{{ helm_repo_name }}/{{ helm_chart_name }}"
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
update_repo_cache: true update_repo_cache: true
kubeconfig: "{{ test_kubeconfig | default(omit) }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}"
@@ -98,7 +103,7 @@
kubeconfig: "{{ test_kubeconfig | default(omit) }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}"
name: "rabbitmq" name: "{{ helm_release_name }}"
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
register: chart_info register: chart_info
@@ -112,7 +117,7 @@
- name: Remove chart - name: Remove chart
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
name: rabbitmq name: "{{ helm_release_name }}"
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
kubeconfig: "{{ test_kubeconfig | default(omit) }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}"
@@ -131,7 +136,7 @@
kubeconfig: "{{ test_kubeconfig | default(omit) }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}"
name: "rabbitmq" name: "{{ helm_release_name }}"
namespace: "{{ helm_namespace }}" namespace: "{{ helm_namespace }}"
register: chart_info register: chart_info
@@ -143,7 +148,7 @@
- name: Remove chart repository - name: Remove chart repository
helm_repository: helm_repository:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
name: test_bitnami name: "{{ helm_repo_name }}"
kubeconfig: "{{ test_kubeconfig | default(omit) }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}"
validate_certs: "{{ test_validate_certs | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}"
ca_cert: "{{ test_ca_cert | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}"
@@ -192,6 +197,6 @@
- name: Delete helm repository - name: Delete helm repository
helm_repository: helm_repository:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
name: test_bitnami name: "{{ helm_repo_name }}"
state: absent state: absent
ignore_errors: true ignore_errors: true

View File

@@ -180,6 +180,7 @@
- '"--username ansible" in _result.command' - '"--username ansible" in _result.command'
- '"--password ***" in _result.command' - '"--password ***" in _result.command'
- '"--keyring pubring.gpg" in _result.command' - '"--keyring pubring.gpg" in _result.command'
- '"Module did not set no_log for pass_credentials" not in _result.stderr'
- name: Download chart using chart_ref - name: Download chart using chart_ref
helm_pull: helm_pull:
@@ -203,9 +204,8 @@
- name: Download chart using untar_chart - name: Download chart using untar_chart
helm_pull: helm_pull:
binary_path: "{{ helm_path }}" binary_path: "{{ helm_path }}"
chart_ref: redis chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis"
destination: "{{ destination }}" destination: "{{ destination }}"
repo_url: "https://charts.bitnami.com/bitnami"
untar_chart: true untar_chart: true
register: _result register: _result

View File

@@ -0,0 +1,2 @@
time=16
helm_registry_auth

View File

@@ -0,0 +1,9 @@
---
# Username and password for the registry
# ../files/registry.password contains username and hashed password
username: testuser
password: testpassword
wrong_password: 'WrongPassword'
registry_name: oci_registry
registry_port: 5000
test_chart: https://github.com/grafana/helm-charts/releases/download/k8s-monitoring-1.6.8/k8s-monitoring-1.6.8.tgz

View File

@@ -0,0 +1 @@
testuser:$2y$05$PmdUjSCJYdRUZlsYy8QGWuJDiwuHtWXa28YrELlN5haeHkZ1seZZG

View File

@@ -0,0 +1,3 @@
---
dependencies:
- install_helm

View File

@@ -0,0 +1,7 @@
---
- name: Test helm_registry_auth module
hosts: localhost
connection: local
gather_facts: true
roles:
- helm_registry_auth

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eux
export ANSIBLE_CALLBACKS_ENABLED=profile_tasks
export ANSIBLE_ROLES_PATH=../
ansible-playbook playbook.yaml "$@"

View File

@@ -0,0 +1,178 @@
---
- name: Run module test
# using a shell and command module to run the test as test can be non-idempotent
# and it allow to not install any additional dependencies
block:
- name: Ensure that helm is installed
ansible.builtin.shell: helm version --client --short | grep v3
register: _helm_version
failed_when: _helm_version.rc != 0
- name: Ensure that Docker demon is running
ansible.builtin.command: "docker info"
register: _docker_info
failed_when: _docker_info.rc != 0
- name: Create a tmpfile htpasswd directory
ansible.builtin.tempfile:
state: directory
suffix: .httppasswd
register: _tmpfile
- name: Copy htpasswd to the tmpfile directory
ansible.builtin.copy:
src: registry.password
dest: "{{ _tmpfile.path }}/registry.password"
- name: Setup the registry
ansible.builtin.command: >-
docker run -d --rm
-p {{ registry_port }}:5000
--name "{{ registry_name }}"
-v "{{ _tmpfile.path }}:/auth"
-e "REGISTRY_AUTH=htpasswd"
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/registry.password
registry:2
register: _setup_registry
failed_when: _setup_registry.rc != 0
- name: Ensure that the registry is running and rechable
ansible.builtin.wait_for:
host: localhost
port: "{{ registry_port }}"
- name: Test the registry with correct credentials to ensure that the registry is running
ansible.builtin.shell: >-
echo {{ password | quote }} | helm registry login localhost:{{ registry_port }}
-u {{ username }} --password-stdin
register: _login_correct
failed_when: _login_correct.rc != 0
- name: Clean up credentials to run test on clean environment
ansible.builtin.shell: >-
helm registry logout localhost:{{ registry_port }}
register: _logout
failed_when: _logout.rc != 0
- name: Create directory for helm chart
ansible.builtin.tempfile:
state: directory
suffix: ".helm"
register: _destination
- name: Pull test helm chart
ansible.builtin.uri:
url: "{{ test_chart }}"
dest: "{{ _destination.path }}/k8s-monitoring-1.6.8.tgz"
return_content: no
status_code: 200
- name: Test module helm_registry_auth with correct credentials
helm_registry_auth:
username: "{{ username }}"
password: "{{ password }}"
host: localhost:{{ registry_port }}
state: present
register: _helm_registry_auth_correct
- name: Assert that the registry is logged in
# Helm binary prints the message to stderr, refence: https://github.com/helm/helm/issues/13464
assert:
that:
- "'Login Succeeded' in _helm_registry_auth_correct.stderr"
- "'{{ password }}' not in _helm_registry_auth_correct.command"
- "'{{ password }}' not in _helm_registry_auth_correct.stdout"
- "'{{ password }}' not in _helm_registry_auth_correct.stderr"
- name: Ensure that push to the registry is working
ansible.builtin.shell: >-
helm push "{{ _destination.path }}/k8s-monitoring-1.6.8.tgz" oci://localhost:{{ registry_port }}/test/
register: _save_chart
failed_when: _save_chart.rc != 0
- name: Assert that the chart is saved
# Helm binary prints the message to stderr, refence: https://github.com/helm/helm/issues/13464
assert:
that: "'Pushed: localhost:{{ registry_port }}/test/k8s-monitoring' in _save_chart.stderr"
- name: Test logout
helm_registry_auth:
host: localhost:{{ registry_port }}
state: absent
register: _helm_registry_auth_logout
- name: Assert logout
# Helm binary prints the message to stderr
assert:
that: "'Removing login credentials' in _helm_registry_auth_logout.stderr"
- name: Test logout idempotency
helm_registry_auth:
host: localhost:{{ registry_port }}
state: absent
register: _helm_registry_auth_logout_idempotency
- name: Assert logout operation did not report change
ansible.builtin.assert:
that: _helm_registry_auth_logout_idempotency is not changed
- name: Ensure that not able to push to the registry
ansible.builtin.shell: >-
helm push "{{ _destination.path }}/k8s-monitoring-1.6.8.tgz" oci://localhost:{{ registry_port }}/test/
register: _save_chart
failed_when: _save_chart.rc == 0
- name: Read content of ~/.config/helm/registry/config.json
ansible.builtin.slurp:
src: ~/.config/helm/registry/config.json
register: _config_json
- name: Assert that auth data is remove and the chart is not saved
# Helm binary prints the message to stderr
ansible.builtin.assert:
that:
- "'push access denied' in _save_chart.stderr"
- "'authorization failed' in _save_chart.stderr"
- "_save_chart.rc != 0"
- "'localhost:{{ registry_port }}' not in _config_json.content | b64decode"
- name: Test module helm_registry_auth with wrong credentials
helm_registry_auth:
username: "{{ username }}"
password: "{{ wrong_password }}"
host: localhost:{{ registry_port }}
state: present
register: _helm_registry_auth_wrong
ignore_errors: true
- name: Read content of ~/.config/helm/registry/config.json
ansible.builtin.slurp:
src: ~/.config/helm/registry/config.json
register: _config_json
- name: Assert that the registry is not logged in and auth data is not saved
ansible.builtin.assert:
that:
- "'401 Unauthorized' in _helm_registry_auth_wrong.stderr"
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.command"
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stdout"
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stderr"
- "'localhost:{{ registry_port }}' not in _config_json.content | b64decode"
# Clean up
always:
- name: Stop and remove the registry
ansible.builtin.command: docker stop {{ registry_name }}
ignore_errors: true
- name: Remove the tmpfile
ansible.builtin.file:
state: absent
path: "{{ item }}"
force: true
loop:
- "{{ _tmpfile.path }}"
- "{{ _destination.path }}"
ignore_errors: true

View File

@@ -1,8 +1,7 @@
- name: Install helm using set_values parameters - name: Install helm using set_values parameters
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
chart_ref: mariadb chart_ref: oci://registry-1.docker.io/bitnamicharts/mariadb
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-mariadb release_name: test-mariadb
release_namespace: "{{ helm_namespace }}" release_namespace: "{{ helm_namespace }}"
create_namespace: true create_namespace: true
@@ -36,8 +35,7 @@
- name: Install helm using set_values parameters - name: Install helm using set_values parameters
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
chart_ref: apache chart_ref: oci://registry-1.docker.io/bitnamicharts/apache
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-apache release_name: test-apache
release_namespace: "{{ helm_namespace }}" release_namespace: "{{ helm_namespace }}"
create_namespace: true create_namespace: true
@@ -79,8 +77,7 @@
- name: Install helm using set_values parameters - name: Install helm using set_values parameters
helm: helm:
binary_path: "{{ helm_binary }}" binary_path: "{{ helm_binary }}"
chart_ref: minio chart_ref: oci://registry-1.docker.io/bitnamicharts/minio
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-minio release_name: test-minio
release_namespace: "{{ helm_namespace }}" release_namespace: "{{ helm_namespace }}"
create_namespace: true create_namespace: true
@@ -107,3 +104,11 @@
file: file:
state: absent state: absent
path: "{{ ymlfile.path }}" path: "{{ ymlfile.path }}"
ignore_errors: true
- name: Delete namespace
k8s:
state: absent
kind: namespace
name: "{{ helm_namespace }}"
ignore_errors: true

View File

@@ -1,4 +1,4 @@
--- ---
helm_version: v3.7.0 helm_version: v3.8.0
helm_install_path: /tmp/helm helm_install_path: /tmp/helm
helm_default_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz" helm_default_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz"

View File

@@ -182,7 +182,7 @@
- name: assert that pods are running on cordoned node - name: assert that pods are running on cordoned node
assert: assert:
that: that:
- "{{ Pod.resources | selectattr('status.phase', 'equalto', 'Running') | selectattr('spec.nodeName', 'equalto', node_to_drain) | list | length > 0 }}" - Pod.resources | selectattr('status.phase', 'equalto', 'Running') | selectattr('spec.nodeName', 'equalto', node_to_drain) | list | length > 0
- name: Uncordon node - name: Uncordon node
k8s_drain: k8s_drain:
@@ -236,7 +236,7 @@
assert: assert:
that: that:
- drain_result is changed - drain_result is changed
- '"node {{ node_to_drain }} marked unschedulable." in drain_result.result' - '"node "+node_to_drain+" marked unschedulable." in drain_result.result'
- name: assert that unmanaged pod were deleted - name: assert that unmanaged pod were deleted
k8s_info: k8s_info:
@@ -338,7 +338,7 @@
assert: assert:
that: that:
- disable_evict is changed - disable_evict is changed
- '"node {{ node_to_drain }} marked unschedulable." in disable_evict.result' - '"node "+node_to_drain+" marked unschedulable." in disable_evict.result'
- name: assert that unmanaged pod were deleted - name: assert that unmanaged pod were deleted
k8s_info: k8s_info:
@@ -401,7 +401,7 @@
assert: assert:
that: that:
- drain_pod_selector is changed - drain_pod_selector is changed
- '"node {{ node_to_drain }} marked unschedulable." in drain_pod_selector.result' - '"node "+node_to_drain+" marked unschedulable." in drain_pod_selector.result'
- name: assert that pod created before is still running - name: assert that pod created before is still running
k8s_info: k8s_info:
@@ -429,8 +429,8 @@
assert: assert:
that: that:
- drain_pod_selector_equal is changed - drain_pod_selector_equal is changed
- '"node {{ node_to_drain }} already marked unschedulable." in drain_pod_selector_equal.result' - '"node "+node_to_drain+" already marked unschedulable." in drain_pod_selector_equal.result'
- '"Deleting Pods not managed by ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet: {{ test_namespace }}/ansible-drain-pod." in drain_pod_selector_equal.warnings' - '"Deleting Pods not managed by ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet: "+test_namespace+"/ansible-drain-pod." in drain_pod_selector_equal.warnings'
- name: Uncordon node - name: Uncordon node
k8s_drain: k8s_drain:

View File

@@ -424,7 +424,7 @@
- assert: - assert:
that: that:
- result.resources[0].data.testkey == "{{ cmap_data.stdout | b64encode }}" - result.resources[0].data.testkey == (cmap_data.stdout | b64encode)
# test setting module defaults for kubernetes.core.k8s_info # test setting module defaults for kubernetes.core.k8s_info
- block: - block:

View File

@@ -69,7 +69,7 @@
- name: assert pod has been created - name: assert pod has been created
assert: assert:
that: that:
- "{{ pods.resources | length == 1 }}" - pods.resources | length == 1
- name: create pod using generate_name parameter should succeed - name: create pod using generate_name parameter should succeed
k8s: k8s:
@@ -86,7 +86,7 @@
- name: assert pod has been created - name: assert pod has been created
assert: assert:
that: that:
- "{{ pods.resources | length == 2 }}" - pods.resources | length == 2
- name: create pod using metadata.generateName parameter should succeed - name: create pod using metadata.generateName parameter should succeed
k8s: k8s:
@@ -102,7 +102,7 @@
- name: assert pod has been created - name: assert pod has been created
assert: assert:
that: that:
- "{{ pods.resources | length == 3 }}" - pods.resources | length == 3
- name: create object using metadata.generateName should support wait option - name: create object using metadata.generateName should support wait option
k8s: k8s:

View File

@@ -11,7 +11,7 @@
assert: assert:
that: that:
- fake_pod is failed - fake_pod is failed
- 'fake_pod.msg == "Pod {{ test_namespace }}/this_pod_does_exist not found."' - fake_pod.msg == "Pod "+test_namespace+"/this_pod_does_exist not found."
- name: create hello-world deployment - name: create hello-world deployment
k8s: k8s:

View File

@@ -65,7 +65,7 @@
assert: assert:
that: that:
- _result.result.status.phase == 'Running' - _result.result.status.phase == 'Running'
- _result.result.spec.nodeName == "{{ node_to_taint }}" - _result.result.spec.nodeName == node_to_taint
- name: Taint node (check_mode) - name: Taint node (check_mode)
kubernetes.core.k8s_taint: kubernetes.core.k8s_taint:
@@ -89,8 +89,8 @@
assert: assert:
that: that:
- _result.changed - _result.changed
- "{{ item['effect'] == taint_patch_1[0]['effect'] }}" - item['effect'] == taint_patch_1[0]['effect']
- "{{ item['key'] == taint_patch_1[0]['key'] }}" - item['key'] == taint_patch_1[0]['key']
loop: "{{ _result.result.spec.taints }}" loop: "{{ _result.result.spec.taints }}"
- name: Taint node (idempotency) - (check_mode) - name: Taint node (idempotency) - (check_mode)

View File

@@ -213,8 +213,8 @@
- name: check that resources creation failed - name: check that resources creation failed
assert: assert:
that: that:
- '{{ resource.results[0].resources | length == 0 }}' - resource.results.0.resources | length == 0
- '{{ resource.results[1].resources | length == 0 }}' - resource.results.1.resources | length == 0
- name: create pod without namespace (continue_on_error = true) - name: create pod without namespace (continue_on_error = true)
kubernetes.core.k8s: kubernetes.core.k8s:

View File

@@ -5,6 +5,7 @@ k8s_pod_metadata:
k8s_pod_spec: k8s_pod_spec:
serviceAccount: "{{ k8s_pod_service_account }}" serviceAccount: "{{ k8s_pod_service_account }}"
nodeSelector: "{{ k8s_pod_node_selector }}"
containers: containers:
- image: "{{ k8s_pod_image }}" - image: "{{ k8s_pod_image }}"
imagePullPolicy: Always imagePullPolicy: Always
@@ -33,6 +34,8 @@ k8s_pod_ports: []
k8s_pod_env: [] k8s_pod_env: []
k8s_pod_node_selector: {}
k8s_pod_template: k8s_pod_template:
metadata: "{{ k8s_pod_metadata }}" metadata: "{{ k8s_pod_metadata }}"
spec: "{{ k8s_pod_spec }}" spec: "{{ k8s_pod_spec }}"

View File

@@ -127,6 +127,48 @@
- ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled - ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled
- updated_ds_pods.resources[0].spec.containers[0].image.endswith(":3") - updated_ds_pods.resources[0].spec.containers[0].image.endswith(":3")
- name: Create daemonset with nodeSelector and not existing label
k8s:
definition:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: wait-daemonset-not-existing-label
namespace: "{{ wait_namespace }}"
spec:
selector:
matchLabels:
app: "{{ k8s_pod_name }}"
template: "{{ k8s_pod_template }}"
wait: yes
wait_sleep: 5
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
vars:
k8s_pod_name: wait-daemonset-not-existing-label
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:1
k8s_pod_command:
- sleep
- "600"
k8s_pod_node_selector:
nonExisitingLabel: test-not-exiting-label
register: ds_not_existing_label
- name: Get updated pods
k8s_info:
api_version: v1
kind: Pod
namespace: "{{ wait_namespace }}"
label_selectors:
- app=wait-daemonset-not-existing-label
register: updated_ds_pods_not_existing_label
- name: Check that daemonset wait worked (when desired number is 0)
assert:
that:
- ds_not_existing_label.result.status.currentNumberScheduled == ds_not_existing_label.result.status.desiredNumberScheduled
- ds_not_existing_label.result.status.desiredNumberScheduled == 0
- updated_ds_pods_not_existing_label.resources | length == 0
- name: Add a statefulset - name: Add a statefulset
k8s: k8s:
definition: definition:

View File

@@ -130,9 +130,9 @@
assert: assert:
that: that:
- result_configmap.apiVersion == 'v1' - result_configmap.apiVersion == 'v1'
- result_configmap.metadata.name == "{{ configmap_name }}" - result_configmap.metadata.name == configmap_name
- result_configmap.metadata.namespace == "{{ test_namespace[2] }}" - result_configmap.metadata.namespace == test_namespace[2]
- result_configmap.data.value == "{{ configmap_data }}" - result_configmap.data.value == configmap_data
# test lookup plugin using src parameter # test lookup plugin using src parameter
- block: - block:
@@ -159,9 +159,9 @@
assert: assert:
that: that:
- src_configmap.apiVersion == 'v1' - src_configmap.apiVersion == 'v1'
- src_configmap.metadata.name == "{{ configmap_name }}" - src_configmap.metadata.name == configmap_name
- src_configmap.metadata.namespace == "{{ test_namespace[2] }}" - src_configmap.metadata.namespace == test_namespace[2]
- src_configmap.data.value == "{{ configmap_data }}" - src_configmap.data.value == configmap_data
always: always:
- name: Delete temporary file created - name: Delete temporary file created
@@ -198,9 +198,9 @@
assert: assert:
that: that:
- configmap_no_ssl.apiVersion == 'v1' - configmap_no_ssl.apiVersion == 'v1'
- configmap_no_ssl.metadata.name == "{{ configmap_name }}" - configmap_no_ssl.metadata.name == configmap_name
- configmap_no_ssl.metadata.namespace == "{{ test_namespace[2] }}" - configmap_no_ssl.metadata.namespace == test_namespace[2]
- configmap_no_ssl.data.value == "{{ configmap_data }}" - configmap_no_ssl.data.value == configmap_data
- name: Retrieve configmap using authentication aliases (validate_certs=true) - name: Retrieve configmap using authentication aliases (validate_certs=true)
set_fact: set_fact:
@@ -210,9 +210,9 @@
assert: assert:
that: that:
- configmap_with_ssl.apiVersion == 'v1' - configmap_with_ssl.apiVersion == 'v1'
- configmap_with_ssl.metadata.name == "{{ configmap_name }}" - configmap_with_ssl.metadata.name == configmap_name
- configmap_with_ssl.metadata.namespace == "{{ test_namespace[2] }}" - configmap_with_ssl.metadata.namespace == test_namespace[2]
- configmap_with_ssl.data.value == "{{ configmap_data }}" - configmap_with_ssl.data.value == configmap_data
always: always:
- name: Delete temporary directory - name: Delete temporary directory

View File

@@ -0,0 +1 @@
disabled

View File

@@ -0,0 +1,5 @@
---
helm_binary_path: "helm"
chart_repo_url: 'localhost:6035'
chart_repo_username: testuser
chart_repo_password: 'pass123!'

View File

@@ -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

View File

@@ -0,0 +1 @@
disabled

View File

@@ -0,0 +1,5 @@
---
# user: testuser, password: pass123!
registry_credentials: testuser:$2y$05$d8tw6L1hojRFW.FjHOAnIOihJWAvFb0/Pu/30hLbQNJIYzCmlyBCi
registry_name: helm_registry
registry_port: 6035

View File

@@ -0,0 +1,3 @@
---
- name: Teardown registry
include_tasks: teardown_registry.yml

View File

@@ -0,0 +1,32 @@
---
- name: Ensure we can talk to docker daemon
ansible.builtin.shell:
cmd: docker ps
- name: Create temporary directory to store file in
tempfile:
state: directory
suffix: .helm_registry
register: _tmpfile
# notify:
# - Teardown registry
- name: Create authentication file
copy:
content: "{{ registry_credentials }}"
dest: "{{ _tmpfile.path }}/htpasswd"
- name: Remove existing registry
ansible.builtin.include_tasks: remove_docker_container.yml
- name: Create registry container
command: >-
docker run -d
-p {{ registry_port }}:5000
--restart=always
--name "{{ registry_name }}"
-v "{{ _tmpfile.path }}:/auth"
-e "REGISTRY_AUTH=htpasswd"
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd
registry:2

View File

@@ -0,0 +1,15 @@
---
- name: Inspect docker container
command: docker container inspect {{ registry_name }} -f '{{ '{{' }} .State.Running {{ '}}' }}'
register: _inspect
ignore_errors: true
- name: Remove container
when: _inspect.rc == 0
block:
- name: Stop running container
command: docker container stop {{ registry_name }}
when: _inspect.stdout == "true"
- name: Remove container
command: docker container rm {{ registry_name }}

View File

@@ -0,0 +1,9 @@
---
- name: Remove Docker container
ansible.builtin.include_tasks: remove_docker_container.yml
- name: Delete temporary directory
file:
state: absent
path: '{{ _tmpfile.path }}'
ignore_errors: true

View File

@@ -1,18 +1,9 @@
plugins/module_utils/client/discovery.py import-3.6!skip
plugins/module_utils/client/discovery.py import-3.7!skip
plugins/module_utils/client/discovery.py import-3.8!skip
plugins/module_utils/client/discovery.py import-3.9!skip plugins/module_utils/client/discovery.py import-3.9!skip
plugins/module_utils/client/discovery.py import-3.10!skip plugins/module_utils/client/discovery.py import-3.10!skip
plugins/module_utils/client/discovery.py import-3.11!skip plugins/module_utils/client/discovery.py import-3.11!skip
plugins/module_utils/client/resource.py import-3.6!skip
plugins/module_utils/client/resource.py import-3.7!skip
plugins/module_utils/client/resource.py import-3.8!skip
plugins/module_utils/client/resource.py import-3.9!skip plugins/module_utils/client/resource.py import-3.9!skip
plugins/module_utils/client/resource.py import-3.10!skip plugins/module_utils/client/resource.py import-3.10!skip
plugins/module_utils/client/resource.py import-3.11!skip plugins/module_utils/client/resource.py import-3.11!skip
plugins/module_utils/k8sdynamicclient.py import-3.6!skip
plugins/module_utils/k8sdynamicclient.py import-3.7!skip
plugins/module_utils/k8sdynamicclient.py import-3.8!skip
plugins/module_utils/k8sdynamicclient.py import-3.9!skip plugins/module_utils/k8sdynamicclient.py import-3.9!skip
plugins/module_utils/k8sdynamicclient.py import-3.10!skip plugins/module_utils/k8sdynamicclient.py import-3.10!skip
plugins/module_utils/k8sdynamicclient.py import-3.11!skip plugins/module_utils/k8sdynamicclient.py import-3.11!skip
@@ -34,3 +25,6 @@ plugins/modules/k8s_service.py validate-modules:return-syntax-error
plugins/modules/k8s_taint.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error
tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip

View File

@@ -1,18 +1,9 @@
plugins/module_utils/client/discovery.py import-3.6!skip
plugins/module_utils/client/discovery.py import-3.7!skip
plugins/module_utils/client/discovery.py import-3.8!skip
plugins/module_utils/client/discovery.py import-3.9!skip plugins/module_utils/client/discovery.py import-3.9!skip
plugins/module_utils/client/discovery.py import-3.10!skip plugins/module_utils/client/discovery.py import-3.10!skip
plugins/module_utils/client/discovery.py import-3.11!skip plugins/module_utils/client/discovery.py import-3.11!skip
plugins/module_utils/client/resource.py import-3.6!skip
plugins/module_utils/client/resource.py import-3.7!skip
plugins/module_utils/client/resource.py import-3.8!skip
plugins/module_utils/client/resource.py import-3.9!skip plugins/module_utils/client/resource.py import-3.9!skip
plugins/module_utils/client/resource.py import-3.10!skip plugins/module_utils/client/resource.py import-3.10!skip
plugins/module_utils/client/resource.py import-3.11!skip plugins/module_utils/client/resource.py import-3.11!skip
plugins/module_utils/k8sdynamicclient.py import-3.6!skip
plugins/module_utils/k8sdynamicclient.py import-3.7!skip
plugins/module_utils/k8sdynamicclient.py import-3.8!skip
plugins/module_utils/k8sdynamicclient.py import-3.9!skip plugins/module_utils/k8sdynamicclient.py import-3.9!skip
plugins/module_utils/k8sdynamicclient.py import-3.10!skip plugins/module_utils/k8sdynamicclient.py import-3.10!skip
plugins/module_utils/k8sdynamicclient.py import-3.11!skip plugins/module_utils/k8sdynamicclient.py import-3.11!skip
@@ -35,3 +26,5 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error
plugins/modules/k8s_taint.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip

View File

@@ -1,20 +1,11 @@
plugins/module_utils/client/discovery.py import-3.6!skip
plugins/module_utils/client/discovery.py import-3.7!skip
plugins/module_utils/client/discovery.py import-3.8!skip
plugins/module_utils/client/discovery.py import-3.9!skip plugins/module_utils/client/discovery.py import-3.9!skip
plugins/module_utils/client/discovery.py import-3.10!skip plugins/module_utils/client/discovery.py import-3.10!skip
plugins/module_utils/client/discovery.py import-3.11!skip plugins/module_utils/client/discovery.py import-3.11!skip
plugins/module_utils/client/discovery.py import-3.12!skip plugins/module_utils/client/discovery.py import-3.12!skip
plugins/module_utils/client/resource.py import-3.6!skip
plugins/module_utils/client/resource.py import-3.7!skip
plugins/module_utils/client/resource.py import-3.8!skip
plugins/module_utils/client/resource.py import-3.9!skip plugins/module_utils/client/resource.py import-3.9!skip
plugins/module_utils/client/resource.py import-3.10!skip plugins/module_utils/client/resource.py import-3.10!skip
plugins/module_utils/client/resource.py import-3.11!skip plugins/module_utils/client/resource.py import-3.11!skip
plugins/module_utils/client/resource.py import-3.12!skip plugins/module_utils/client/resource.py import-3.12!skip
plugins/module_utils/k8sdynamicclient.py import-3.6!skip
plugins/module_utils/k8sdynamicclient.py import-3.7!skip
plugins/module_utils/k8sdynamicclient.py import-3.8!skip
plugins/module_utils/k8sdynamicclient.py import-3.9!skip plugins/module_utils/k8sdynamicclient.py import-3.9!skip
plugins/module_utils/k8sdynamicclient.py import-3.10!skip plugins/module_utils/k8sdynamicclient.py import-3.10!skip
plugins/module_utils/k8sdynamicclient.py import-3.11!skip plugins/module_utils/k8sdynamicclient.py import-3.11!skip
@@ -38,3 +29,5 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error
plugins/modules/k8s_taint.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip

View File

@@ -29,3 +29,5 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error
plugins/modules/k8s_taint.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip

View File

@@ -1,15 +1,12 @@
plugins/module_utils/client/discovery.py import-3.9!skip
plugins/module_utils/client/discovery.py import-3.10!skip
plugins/module_utils/client/discovery.py import-3.11!skip plugins/module_utils/client/discovery.py import-3.11!skip
plugins/module_utils/client/discovery.py import-3.12!skip plugins/module_utils/client/discovery.py import-3.12!skip
plugins/module_utils/client/resource.py import-3.9!skip plugins/module_utils/client/discovery.py import-3.13!skip
plugins/module_utils/client/resource.py import-3.10!skip
plugins/module_utils/client/resource.py import-3.11!skip plugins/module_utils/client/resource.py import-3.11!skip
plugins/module_utils/client/resource.py import-3.12!skip plugins/module_utils/client/resource.py import-3.12!skip
plugins/module_utils/k8sdynamicclient.py import-3.9!skip plugins/module_utils/client/resource.py import-3.13!skip
plugins/module_utils/k8sdynamicclient.py import-3.10!skip
plugins/module_utils/k8sdynamicclient.py import-3.11!skip plugins/module_utils/k8sdynamicclient.py import-3.11!skip
plugins/module_utils/k8sdynamicclient.py import-3.12!skip plugins/module_utils/k8sdynamicclient.py import-3.12!skip
plugins/module_utils/k8sdynamicclient.py import-3.13!skip
plugins/module_utils/version.py pylint!skip plugins/module_utils/version.py pylint!skip
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc
@@ -29,3 +26,5 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error
plugins/modules/k8s_taint.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip

View File

@@ -0,0 +1,30 @@
plugins/module_utils/client/discovery.py import-3.11!skip
plugins/module_utils/client/discovery.py import-3.12!skip
plugins/module_utils/client/discovery.py import-3.13!skip
plugins/module_utils/client/resource.py import-3.11!skip
plugins/module_utils/client/resource.py import-3.12!skip
plugins/module_utils/client/resource.py import-3.13!skip
plugins/module_utils/k8sdynamicclient.py import-3.11!skip
plugins/module_utils/k8sdynamicclient.py import-3.12!skip
plugins/module_utils/k8sdynamicclient.py import-3.13!skip
plugins/module_utils/version.py pylint!skip
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc
plugins/modules/k8s_service.py validate-modules:parameter-type-not-in-doc
tests/unit/module_utils/fixtures/definitions.yml yamllint!skip
tests/unit/module_utils/fixtures/deployments.yml yamllint!skip
tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
plugins/modules/k8s.py validate-modules:return-syntax-error
plugins/modules/k8s_scale.py validate-modules:return-syntax-error
plugins/modules/k8s_service.py validate-modules:return-syntax-error
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip

View File

@@ -200,6 +200,10 @@ def test_module_get_values(_ansible_helm_module, no_values, get_all):
'version.BuildInfo{Version:"v3.10.3", GitCommit:7870ab3ed4135f136eec, GoVersion:"go1.18.9"}', 'version.BuildInfo{Version:"v3.10.3", GitCommit:7870ab3ed4135f136eec, GoVersion:"go1.18.9"}',
"3.10.3", "3.10.3",
), ),
(
'version.BuildInfo{Version:"v3.15.0-rc.1", GitCommit:"d7afa3b6b432c09a02cd07342e908ba5bed34940", GitTreeState:"clean", GoVersion:"go1.22.4"}',
"3.15.0-rc.1",
),
('Client: &version.Version{SemVer:"v3.12.3", ', "3.12.3"), ('Client: &version.Version{SemVer:"v3.12.3", ', "3.12.3"),
('Client: &version.Version{SemVer:"v3.12.3"', None), ('Client: &version.Version{SemVer:"v3.12.3"', None),
], ],
@@ -238,7 +242,7 @@ def test_module_run_helm_command(_ansible_helm_module):
assert (rc, out, err) == (0, output, error) assert (rc, out, err) == (0, output, error)
_ansible_helm_module.run_command.assert_called_once_with( _ansible_helm_module.run_command.assert_called_once_with(
command, environ_update=env_update command, environ_update=env_update, data=None
) )

View File

@@ -31,7 +31,7 @@ modified_def["metadata"]["labels"]["environment"] = "testing"
@pytest.mark.parametrize( @pytest.mark.parametrize(
"action, params, existing, instance, expected", "action, params, existing, instance_warnings, expected",
[ [
( (
"delete", "delete",
@@ -51,14 +51,26 @@ modified_def["metadata"]["labels"]["environment"] = "testing"
"apply", "apply",
{"apply": "yes"}, {"apply": "yes"},
{}, {},
definition, (definition, []),
{"changed": True, "method": "apply", "result": definition}, {"changed": True, "method": "apply", "result": definition},
), ),
(
"apply",
{"apply": "yes"},
{},
(definition, ["test warning"]),
{
"changed": True,
"method": "apply",
"result": definition,
"warnings": ["test warning"],
},
),
( (
"create", "create",
{"state": "patched"}, {"state": "patched"},
{}, {},
{}, ({}, []),
{ {
"changed": False, "changed": False,
"result": {}, "result": {},
@@ -71,42 +83,78 @@ modified_def["metadata"]["labels"]["environment"] = "testing"
"create", "create",
{}, {},
{}, {},
definition, (definition, []),
{"changed": True, "method": "create", "result": definition}, {"changed": True, "method": "create", "result": definition},
), ),
(
"create",
{},
{},
(definition, ["test warning"]),
{
"changed": True,
"method": "create",
"result": definition,
"warnings": ["test warning"],
},
),
( (
"replace", "replace",
{"force": "yes"}, {"force": "yes"},
definition, definition,
definition, (definition, []),
{"changed": False, "method": "replace", "result": definition}, {"changed": False, "method": "replace", "result": definition},
), ),
( (
"replace", "replace",
{"force": "yes"}, {"force": "yes"},
definition, definition,
modified_def, (modified_def, []),
{"changed": True, "method": "replace", "result": modified_def}, {"changed": True, "method": "replace", "result": modified_def},
), ),
(
"replace",
{"force": "yes"},
definition,
(modified_def, ["test warning"]),
{
"changed": True,
"method": "replace",
"result": modified_def,
"warnings": ["test warning"],
},
),
( (
"update", "update",
{}, {},
definition, definition,
definition, (definition, []),
{"changed": False, "method": "update", "result": definition}, {"changed": False, "method": "update", "result": definition},
), ),
( (
"update", "update",
{}, {},
definition, definition,
modified_def, (modified_def, []),
{"changed": True, "method": "update", "result": modified_def}, {"changed": True, "method": "update", "result": modified_def},
), ),
(
"update",
{},
definition,
(modified_def, ["test warning"]),
{
"changed": True,
"method": "update",
"result": modified_def,
"warnings": ["test warning"],
},
),
( (
"create", "create",
{"label_selectors": ["app=foo"]}, {"label_selectors": ["app=foo"]},
{}, {},
definition, (definition, []),
{ {
"changed": False, "changed": False,
"msg": "resource 'kind=Pod,name=foo,namespace=foo' filtered by label_selectors.", "msg": "resource 'kind=Pod,name=foo,namespace=foo' filtered by label_selectors.",
@@ -116,18 +164,18 @@ modified_def["metadata"]["labels"]["environment"] = "testing"
"create", "create",
{"label_selectors": ["app=nginx"]}, {"label_selectors": ["app=nginx"]},
{}, {},
definition, (definition, []),
{"changed": True, "method": "create", "result": definition}, {"changed": True, "method": "create", "result": definition},
), ),
], ],
) )
def test_perform_action(action, params, existing, instance, expected): def test_perform_action(action, params, existing, instance_warnings, expected):
svc = Mock() svc = Mock()
svc.find_resource.return_value = Mock( svc.find_resource.return_value = Mock(
kind=definition["kind"], group_version=definition["apiVersion"] kind=definition["kind"], group_version=definition["apiVersion"]
) )
svc.retrieve.return_value = ResourceInstance(None, existing) if existing else None svc.retrieve.return_value = ResourceInstance(None, existing) if existing else None
spec = {action + ".return_value": instance} spec = {action + ".return_value": instance_warnings}
svc.configure_mock(**spec) svc.configure_mock(**spec)
result = perform_action(svc, definition, params) result = perform_action(svc, definition, params)

View File

@@ -1,9 +1,11 @@
from json import dumps
from unittest.mock import Mock from unittest.mock import Mock
import pytest import pytest
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.service import ( from ansible_collections.kubernetes.core.plugins.module_utils.k8s.service import (
K8sService, K8sService,
diff_objects, diff_objects,
parse_quoted_string,
) )
from kubernetes.dynamic.exceptions import NotFoundError from kubernetes.dynamic.exceptions import NotFoundError
from kubernetes.dynamic.resource import Resource, ResourceInstance from kubernetes.dynamic.resource import Resource, ResourceInstance
@@ -57,6 +59,22 @@ def mock_pod_updated_resource_instance():
return ResourceInstance(None, pod_definition_updated) return ResourceInstance(None, pod_definition_updated)
@pytest.fixture(scope="module")
def mock_pod_response():
resp = Mock()
resp.data.decode.return_value = dumps(pod_definition)
resp.headers = {}
return resp
@pytest.fixture(scope="module")
def mock_pod_warnings_response():
resp = Mock()
resp.data.decode.return_value = dumps(pod_definition)
resp.headers = {"warning": '299 - "test warning 1", 299 - "test warning 2"'}
return resp
def test_diff_objects_no_diff(): def test_diff_objects_no_diff():
match, diff = diff_objects(pod_definition, pod_definition) match, diff = diff_objects(pod_definition, pod_definition)
@@ -159,16 +177,33 @@ def test_service_delete_existing_resource_check_mode(mock_pod_resource_instance)
client.delete.assert_not_called() client.delete.assert_not_called()
def test_service_create_resource(mock_pod_resource_instance): def test_service_create_resource(mock_pod_response, mock_pod_resource_instance):
spec = {"create.side_effect": [mock_pod_resource_instance]} spec = {"create.side_effect": [mock_pod_response]}
client = Mock(**spec) client = Mock(**spec)
module = Mock() module = Mock()
module.params = {} module.params = {}
module.check_mode = False module.check_mode = False
svc = K8sService(client, module) svc = K8sService(client, module)
result = svc.create(Mock(), pod_definition) result, warnings = svc.create(Mock(), pod_definition)
assert result == mock_pod_resource_instance.to_dict() assert result == mock_pod_resource_instance.to_dict()
assert not warnings
def test_service_create_resource_warnings(
mock_pod_warnings_response, mock_pod_resource_instance
):
spec = {"create.side_effect": [mock_pod_warnings_response]}
client = Mock(**spec)
module = Mock()
module.params = {}
module.check_mode = False
svc = K8sService(client, module)
result, warnings = svc.create(Mock(), pod_definition)
assert result == mock_pod_resource_instance.to_dict()
assert warnings[0] == "test warning 1"
assert warnings[1] == "test warning 2"
def test_service_create_resource_check_mode(): def test_service_create_resource_check_mode():
@@ -176,9 +211,10 @@ def test_service_create_resource_check_mode():
client.create.return_value = mock_pod_resource_instance client.create.return_value = mock_pod_resource_instance
module = Mock(params={}, check_mode=True) module = Mock(params={}, check_mode=True)
svc = K8sService(client, module) svc = K8sService(client, module)
result = svc.create(Mock(), pod_definition) result, warnings = svc.create(Mock(), pod_definition)
assert result == pod_definition assert result == pod_definition
assert not warnings
client.create.assert_not_called() client.create.assert_not_called()
@@ -224,40 +260,99 @@ def test_create_project_request():
assert results["result"] == project_definition assert results["result"] == project_definition
def test_service_apply_existing_resource(mock_pod_resource_instance): def test_service_apply_existing_resource(mock_pod_response, mock_pod_resource_instance):
spec = {"apply.side_effect": [mock_pod_resource_instance]} spec = {"apply.side_effect": [mock_pod_response]}
client = Mock(**spec) client = Mock(**spec)
module = Mock() module = Mock()
module.params = {"apply": True} module.params = {"apply": True}
module.check_mode = False module.check_mode = False
svc = K8sService(client, module) svc = K8sService(client, module)
result = svc.apply(Mock(), pod_definition_updated, mock_pod_resource_instance) result, warnings = svc.apply(
Mock(), pod_definition_updated, mock_pod_resource_instance
)
assert result == mock_pod_resource_instance.to_dict() assert result == mock_pod_resource_instance.to_dict()
assert not warnings
def test_service_replace_existing_resource(mock_pod_resource_instance): def test_service_apply_existing_resource_warnings(
spec = {"replace.side_effect": [mock_pod_resource_instance]} mock_pod_warnings_response, mock_pod_resource_instance
):
spec = {"apply.side_effect": [mock_pod_warnings_response]}
client = Mock(**spec)
module = Mock()
module.params = {"apply": True}
module.check_mode = False
svc = K8sService(client, module)
result, warnings = svc.apply(
Mock(), pod_definition_updated, mock_pod_resource_instance
)
assert result == mock_pod_resource_instance.to_dict()
assert warnings[0] == "test warning 1"
assert warnings[1] == "test warning 2"
def test_service_replace_existing_resource(
mock_pod_response, mock_pod_resource_instance
):
spec = {"replace.side_effect": [mock_pod_response]}
client = Mock(**spec) client = Mock(**spec)
module = Mock() module = Mock()
module.params = {} module.params = {}
module.check_mode = False module.check_mode = False
svc = K8sService(client, module) svc = K8sService(client, module)
result = svc.replace(Mock(), pod_definition, mock_pod_resource_instance) result, warnings = svc.replace(Mock(), pod_definition, mock_pod_resource_instance)
assert result == mock_pod_resource_instance.to_dict() assert result == mock_pod_resource_instance.to_dict()
assert not warnings
def test_service_update_existing_resource(mock_pod_resource_instance): def test_service_replace_existing_resource_warnings(
spec = {"replace.side_effect": [mock_pod_resource_instance]} mock_pod_warnings_response, mock_pod_resource_instance
):
spec = {"replace.side_effect": [mock_pod_warnings_response]}
client = Mock(**spec) client = Mock(**spec)
module = Mock() module = Mock()
module.params = {} module.params = {}
module.check_mode = False module.check_mode = False
svc = K8sService(client, module) svc = K8sService(client, module)
result = svc.replace(Mock(), pod_definition, mock_pod_resource_instance) result, warnings = svc.replace(Mock(), pod_definition, mock_pod_resource_instance)
assert result == mock_pod_resource_instance.to_dict() assert result == mock_pod_resource_instance.to_dict()
assert warnings[0] == "test warning 1"
assert warnings[1] == "test warning 2"
def test_service_update_existing_resource(
mock_pod_response, mock_pod_resource_instance
):
spec = {"replace.side_effect": [mock_pod_response]}
client = Mock(**spec)
module = Mock()
module.params = {}
module.check_mode = False
svc = K8sService(client, module)
result, warnings = svc.replace(Mock(), pod_definition, mock_pod_resource_instance)
assert result == mock_pod_resource_instance.to_dict()
assert not warnings
def test_service_update_existing_resource_warnings(
mock_pod_warnings_response, mock_pod_resource_instance
):
spec = {"replace.side_effect": [mock_pod_warnings_response]}
client = Mock(**spec)
module = Mock()
module.params = {}
module.check_mode = False
svc = K8sService(client, module)
result, warnings = svc.replace(Mock(), pod_definition, mock_pod_resource_instance)
assert result == mock_pod_resource_instance.to_dict()
assert warnings[0] == "test warning 1"
assert warnings[1] == "test warning 2"
def test_service_find(mock_pod_resource_instance): def test_service_find(mock_pod_resource_instance):
@@ -288,3 +383,24 @@ def test_service_find_error():
assert isinstance(results, dict) assert isinstance(results, dict)
assert results["api_found"] is True assert results["api_found"] is True
assert results["resources"] == [] assert results["resources"] == []
@pytest.mark.parametrize(
"quoted_string,expected_val,expected_remainder",
[
(
'"Response is stale" Tue, 15 Nov 1994 12:45:26 GMT',
"Response is stale",
"Tue, 15 Nov 1994 12:45:26 GMT",
),
(
'"unknown field \\"spec.template.spec.disk\\""',
'unknown field "spec.template.spec.disk"',
"",
),
],
)
def test_parse_quoted_string(quoted_string, expected_val, expected_remainder):
val, remainder = parse_quoted_string(quoted_string)
assert val == expected_val
assert remainder == expected_remainder

View File

@@ -51,7 +51,7 @@ class TestDependencyUpdateWithoutChartRepoUrlOption(unittest.TestCase):
with self.assertRaises(AnsibleExitJson) as result: with self.assertRaises(AnsibleExitJson) as result:
helm_template.main() helm_template.main()
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm template /tmp/path", environ_update={} "/usr/bin/helm template /tmp/path", environ_update={}, data=None
) )
assert result.exception.args[0]["command"] == "/usr/bin/helm template /tmp/path" assert result.exception.args[0]["command"] == "/usr/bin/helm template /tmp/path"
@@ -74,6 +74,7 @@ class TestDependencyUpdateWithoutChartRepoUrlOption(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm template test --repo=https://charts.com/test", "/usr/bin/helm template test --repo=https://charts.com/test",
environ_update={}, environ_update={},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -95,6 +96,7 @@ class TestDependencyUpdateWithoutChartRepoUrlOption(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm template https://charts/example.tgz --dependency-update", "/usr/bin/helm template https://charts/example.tgz --dependency-update",
environ_update={}, environ_update={},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]

View File

@@ -88,6 +88,7 @@ class TestDependencyUpdateWithoutChartRepoUrlOption(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm upgrade -i --reset-values test '/tmp/path'", "/usr/bin/helm upgrade -i --reset-values test '/tmp/path'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -118,6 +119,7 @@ class TestDependencyUpdateWithoutChartRepoUrlOption(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm upgrade -i --reset-values test '/tmp/path'", "/usr/bin/helm upgrade -i --reset-values test '/tmp/path'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -147,6 +149,7 @@ class TestDependencyUpdateWithoutChartRepoUrlOption(unittest.TestCase):
call( call(
"/usr/bin/helm upgrade -i --reset-values test '/tmp/path'", "/usr/bin/helm upgrade -i --reset-values test '/tmp/path'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
] ]
) )
@@ -181,6 +184,7 @@ class TestDependencyUpdateWithoutChartRepoUrlOption(unittest.TestCase):
call( call(
"/usr/bin/helm upgrade -i --reset-values test '/tmp/path'", "/usr/bin/helm upgrade -i --reset-values test '/tmp/path'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
] ]
) )
@@ -251,6 +255,7 @@ class TestDependencyUpdateWithChartRepoUrlOption(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm --repo=http://repo.example/charts upgrade -i --reset-values test 'chart1'", "/usr/bin/helm --repo=http://repo.example/charts upgrade -i --reset-values test 'chart1'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -280,6 +285,7 @@ class TestDependencyUpdateWithChartRepoUrlOption(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm --repo=http://repo.example/charts upgrade -i --reset-values test 'chart1'", "/usr/bin/helm --repo=http://repo.example/charts upgrade -i --reset-values test 'chart1'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -338,6 +344,7 @@ class TestDependencyUpdateWithChartRepoUrlOption(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm --repo=http://repo.example/charts install --dependency-update --replace test 'chart1'", "/usr/bin/helm --repo=http://repo.example/charts install --dependency-update --replace test 'chart1'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -405,6 +412,7 @@ class TestDependencyUpdateWithChartRefIsUrl(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm upgrade -i --reset-values test 'http://repo.example/charts/application.tgz'", "/usr/bin/helm upgrade -i --reset-values test 'http://repo.example/charts/application.tgz'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -433,6 +441,7 @@ class TestDependencyUpdateWithChartRefIsUrl(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm upgrade -i --reset-values test 'http://repo.example/charts/application.tgz'", "/usr/bin/helm upgrade -i --reset-values test 'http://repo.example/charts/application.tgz'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]
@@ -489,6 +498,7 @@ class TestDependencyUpdateWithChartRefIsUrl(unittest.TestCase):
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(
"/usr/bin/helm install --dependency-update --replace test 'http://repo.example/charts/application.tgz'", "/usr/bin/helm install --dependency-update --replace test 'http://repo.example/charts/application.tgz'",
environ_update={"HELM_NAMESPACE": "test"}, environ_update={"HELM_NAMESPACE": "test"},
data=None,
) )
assert ( assert (
result.exception.args[0]["command"] result.exception.args[0]["command"]

View File

@@ -1,22 +0,0 @@
import os
import sys
from pathlib import PosixPath
def main():
src = sys.argv[1]
path = PosixPath(src) / PosixPath("tests/integration/targets/")
def _is_disable(path):
flags = ("unsupported", "disabled", "unstable", "hidden")
aliases_path = path / PosixPath("aliases")
return (aliases_path.exists() and any((d.startswith(flags) for d in aliases_path.read_text().split("\n"))))
targets = [i.stem for i in path.glob("*") if i.is_dir() and not _is_disable(i)]
with open(os.environ.get("GITHUB_OUTPUT"), "a", encoding="utf-8") as fw:
fw.write(f"kubevirt_targets={targets}\n")
if __name__ == "__main__":
main()