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
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
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
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>
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>
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>
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>
* Cleanup gha
* test by removing matrix excludes
* Rename sanity tests
* trigger integration tests
* Fix ansible-lint workflow
* Fix concurrency
* Add ansible-lint config
* Add ansible-lint config
* Fix integration and lint issues
* integration wf
* fix yamllint issues
* fix yamllint issues
* update readme and add ignore-2.16.txt
* fix ansible-doc
* Add version
* Use /dev/random to generate random data
The GHA environment has difficultly generating entropy. Trying to read
from /dev/urandom just blocks forever. We don't care if the random data
is cryptographically secure; it's just garbage data for the test. Read
from /dev/random, instead. This is only used during the k8s_copy test
target.
This also removes the custom test module that was being used to generate
the files. It's not worth maintaining this for two task that can be
replaced with some simple command/shell tasks.
* Fix saniry errors
* test github_action fix
* Address review comments
* Remove default types
* review comments
* isort fixes
* remove tags
* Add setuptools to venv
* Test gh changes
* update changelog
* update ignore-2.16
* Fix indentation in inventory plugin example
* Update .github/workflows/integration-tests.yaml
* Update integration-tests.yaml
---------
Co-authored-by: Mike Graves <mgraves@redhat.com>
Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
Provide a mechanism to hide fields from output
SUMMARY
The k8s and k8s_info modules can be a little noisy in verbose mode, and most of that is due to managedFields.
If we can provide a mechanism to hide managedFields, the output is a lot more useful.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
k8s, k8s_info
ADDITIONAL INFORMATION
Before
ANSIBLE_COLLECTIONS_PATH=../../.. ansible -m k8s_info -a 'kind=ConfigMap name=hide-fields-cm namespace=hide-fields' localhost
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
"api_found": true,
"changed": false,
"resources": [
{
"apiVersion": "v1",
"data": {
"another": "value",
"hello": "world"
},
"kind": "ConfigMap",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"another\":\"value\",\"hello\":\"world\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"hide-fields-cm\",\"namespace\":\"hide-fields\"}}\n"
},
"creationTimestamp": "2023-06-13T01:47:47Z",
"managedFields": [
{
"apiVersion": "v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:data": {
".": {},
"f:another": {},
"f:hello": {}
},
"f:metadata": {
"f:annotations": {
".": {},
"f:kubectl.kubernetes.io/last-applied-configuration": {}
}
}
},
"manager": "kubectl-client-side-apply",
"operation": "Update",
"time": "2023-06-13T01:47:47Z"
}
],
"name": "hide-fields-cm",
"namespace": "hide-fields",
"resourceVersion": "2557394",
"uid": "f233da63-6374-4079-9825-3562c0ed123c"
}
}
]
}
After
ANSIBLE_COLLECTIONS_PATH=../../.. ansible -m k8s_info -a 'kind=ConfigMap name=hide-fields-cm namespace=hide-fields hidden_fields=metadata.managedFields' localhost
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
"api_found": true,
"changed": false,
"resources": [
{
"apiVersion": "v1",
"data": {
"another": "value",
"hello": "world"
},
"kind": "ConfigMap",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"another\":\"value\",\"hello\":\"world\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"hide-fields-cm\",\"namespace\":\"hide-fields\"}}\n"
},
"creationTimestamp": "2023-06-13T01:47:47Z",
"name": "hide-fields-cm",
"namespace": "hide-fields",
"resourceVersion": "2557394",
"uid": "f233da63-6374-4079-9825-3562c0ed123c"
}
}
]
}
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Will Thames
use post_renderer when checking 'changed' status for a helm release
SUMMARY
helmdiff_check needs to use --post-renderer if configured in order to detect changes correctly
idempotency still seems to work
ISSUE TYPE
Bugfix Pull Request (50%)
Feature Pull Request (50%)
COMPONENT NAME
kubernetes.core.helm
ADDITIONAL INFORMATION
- /snap/bin/helm diff upgrade myrelease some/chart --version=1.2.3 --reset-values -f=/tmp/tmpnn0rr50h.yml
+ /snap/bin/helm diff upgrade myrelease some/chart --version=1.2.3 --reset-values --post-renderer=/tmp/somescript.sh -f=/tmp/tmpnn0rr50h.yml
Reviewed-by: Mike Graves <mgraves@redhat.com>
fix post_renderer arguments breaking the helm deploy_command
SUMMARY
The post_renderer setting is broken and resets the deploy_command instead of appending an argument. Diff should be self explanatory.
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
kubernetes.core.helm
ADDITIONAL INFORMATION
Reviewed-by: Mike Graves <mgraves@redhat.com>
make name optional to delete all resources for the specified resource type
SUMMARY
closes#504
k8s module should allow deleting all namespace resources for the specified resource type.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
k8s
ADDITIONAL INFORMATION
Delete all Pods from namespace test
- k8s:
namespace: test
kind: Pod
api_version: v1
delete_all: true
state: absent
Reviewed-by: Gonéri Le Bouder <goneri@lebouder.net>
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Bikouo Aubin
[helm] add the ability for the module to uninstall pending-install releases
SUMMARY
closes#319
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
helm
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Bikouo Aubin
helm - add reuse_values and reset_values support
SUMMARY
closes#394
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
helm
ADDITIONAL INFORMATION
Reviewed-by: Mike Graves <mgraves@redhat.com>
Pass right amount of args to ResourceTimeout
SUMMARY
Pass right amount of args to ResourceTimeout
Fixes#583
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
k8s_scale
ADDITIONAL INFORMATION
ResourceTimeout constuructor does not accept variable argument length.
The passed result dict seems not to be used currently. One could also pass result["result"] or not pass result at all.
Reviewed-by: Mike Graves <mgraves@redhat.com>
helm - add support for -set options when running helm install
SUMMARY
helm support setting options -set, -set-string, -set-file and -set-json when running helm install
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
helm
ADDITIONAL INFORMATION
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Bikouo Aubin <None>
Reviewed-by: Mike Graves <mgraves@redhat.com>
Helm - Fix issue with alternative kubeconfig
SUMMARY
closes#538
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
helm modules
Reviewed-by: Mike Graves <mgraves@redhat.com>
k8s_log - fix issue when required name is not provided, add all_containers support
SUMMARY
Fixes issue when the required name is not provided, closes#514
all support for all_containers option
ISSUE TYPE
Bugfix Pull Request
Feature Pull Request
COMPONENT NAME
k8s_log
ADDITIONAL INFORMATION
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Jill R <None>
Added possibility to get all values by helm_info module
SUMMARY
Parameter get_all_values has been added, which is passed to function get_values. Default is False. Parameter is not required.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
helm_info
ADDITIONAL INFORMATION
Unfortunately, helm_info module lacks functionality of getting all the values of a helm release, including the default ones. This restricts upgrade and config migration capabilities. Parameter get_all_values has been added. This parameter, if set, adds -a parameter to helm get values call. The parameter is not required and defaults to False, so backwards compability is complied.
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Bikouo Aubin <None>
[helm] Add the force_update arg
Depends-On: ansible/ansible-zuul-jobs#1648
Depends-On: #522
SUMMARY
Sometimes a Helm repo needs to be updated with a new URL. The helm repo add command allows for this with the --force-update flag:
--force-update replace (overwrite) the repo if it already exists
ISSUE TYPE
Feature Pull Request - Closes#491
COMPONENT NAME
kubernetes.core.helm_repository
ADDITIONAL INFORMATION
Reviewed-by: Mor Cohen <morcohen1201@gmail.com>
Reviewed-by: Mike Graves <mgraves@redhat.com>
Add example usage of from_yaml_all
Depends-On: #513
SUMMARY
Sometimes one might want to use a single YAML file that contains multiple Kubernetes definitions. This PR updates the documentation to provide a simple example of how to accomplish that.
ISSUE TYPE
Docs Pull Request
COMPONENT NAME
k8s
ADDITIONAL INFORMATION
I have not tested this solution against other modules, simply because I did not have use-case for those.
Reviewed-by: Mike Graves <mgraves@redhat.com>
k8s_log - fix module traceback when resource not found
Depends-on: #495
SUMMARY
closes#479
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
k8s_log
Reviewed-by: Mike Graves <mgraves@redhat.com>
feat: add new tail_lines parameter to k8s_log module (#488)
SUMMARY
Add new tail_lines parameter to k8s_log module to limit the number of lines to be retrieved from the end of the logs.
Closes#488.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
kubernetes.core.k8s_log
ADDITIONAL INFORMATION
Thanks for useful collection 😃
This is the first time to send PR to this collection, so please let me know if I'm on the wrong way.
The version_added is set to 2.4.0, but I'm not aware of the roadmap for this collection, so I'd like to know this is the right version to specify.
Changelog and simple integration test is also added.
It seems that the end of log_lines always contains an empty element, so if tail_lines is set to 5, the length of log_lines will be 6, as noted in the comment in the test. I've considered that truncating the trailing empty element, but decided not to for the following reasons.
It is inconsistent and unnatural to remove trailing empty elements only when tail_lines is specified.
Removing trailing empty elements always with or without tail_lines is a destructive change and should not be done because it would break backward compatibility.
Example tasks in playbook:
tasks:
- name: create a job that has 10 lines of log
kubernetes.core.k8s:
state: present
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
wait_condition:
type: Complete
status: 'True'
definition:
apiVersion: batch/v1
kind: Job
metadata:
name: multiline-log
namespace: test
spec:
template:
spec:
containers:
- name: busybox
image: busybox
command: ['sh']
args: ['-c', 'for i in $(seq 0 9); do echo $i; done']
restartPolicy: Never
backoffLimit: 4
- name: retrieve all logs from the job
kubernetes.core.k8s_log:
api_version: batch/v1
kind: Job
namespace: test
name: multiline-log
register: full_log
- name: retrieve last 5 lines of log from the job
kubernetes.core.k8s_log:
api_version: batch/v1
kind: Job
namespace: test
name: multiline-log
tail_lines: 5
register: tailed_log
- ansible.builtin.debug:
var: full_log.log_lines
- ansible.builtin.debug:
var: tailed_log.log_lines
Example output:
TASK [create a job that has 10 lines of log] *****************************************************************************************
ok: [localhost]
TASK [retrieve all logs from the job] ************************************************************************************************
ok: [localhost]
TASK [retrieve last 5 lines of log from the job] *************************************************************************************
ok: [localhost]
TASK [ansible.builtin.debug] *********************************************************************************************************
ok: [localhost] =>
full_log.log_lines:
- '0'
- '1'
- '2'
- '3'
- '4'
- '5'
- '6'
- '7'
- '8'
- '9'
- ''
TASK [ansible.builtin.debug] *********************************************************************************************************
ok: [localhost] =>
tailed_log.log_lines:
- '5'
- '6'
- '7'
- '8'
- '9'
- ''
PLAY RECAP ***************************************************************************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Reviewed-by: Bikouo Aubin <None>
Reviewed-by: Mike Graves <mgraves@redhat.com>
Migrate k8s_taint to refactored code
Depends-on: #476
SUMMARY
This changes the k8s_taint module to use the newly refactored code.
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Reviewed-by: Alina Buzachis <None>
Ensure CoreExceptions are handled gracefully
SUMMARY
CoreExceptions, when raised, should have a reasonably helpful and
actionable message associated with them. This adds a final check in
module execution to gracefully fail from these exceptions. A new
fail_from_exception method is added both to simplify exiting the module,
and to ensure that any chained exceptions are available when using -vvv.
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Joseph Torcasso <None>
Port changes from main to refactored branch
Depends-on: ansible/ansible-zuul-jobs#1563
SUMMARY
This PR contains several commits that complete the rebase of the 2.x-refactor branch onto main. Most of the changes here had to be manually backported after rebasing as the original changes were to code that will be deprecated. In addition, rather than trying to manually sort out conflicts and changes to the sanity ignores, I rewrote the refresh_ignore_files script to fully automate the management of ignore files. Previously, these files were both manually edited and auto-generated. This should no longer be the case, and these files should never be manually edited going forward.
For the purposes of reviewing and history, I kept all changes in separate commits tied to the original commit being backported.
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Reviewed-by: Jill R <None>
This primarily moves the diff and wait logic from the various service
methods to perform_action to eliminate code duplication. I also moved
the diff_objects function out of the service object and moved most of
the find_resource logic to a new resource client method. We ended up
with several modules creating a service object just to use one of these
methods, so it seemed to make sense to make these more accessible.
Refactor k8s_cluster_info to use new module_utils code
SUMMARY
Refactor k8s_cluster_info to use new module_utils code
ISSUE TYPE
COMPONENT NAME
k8s_cluster_info
ADDITIONAL INFORMATION
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
Refactor k8s_service to use new module_utils code
SUMMARY
Refactor k8s_service to use new module_utils code
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
k8s_service
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
Update k8s_rollback to use refactored module_utils
SUMMARY
Update k8s_rollback to use refactored module_utils
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
k8s_rollback
Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: None <None>
Migrate json_patch to use new refactored code
SUMMARY
Migrate json_patch to use new refactored code
ISSUE TYPE
COMPONENT NAME
k8s_json_patch
ADDITIONAL INFORMATION
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
Helm template add name and disable hook
SUMMARY
This PR adds "disable_hook" and "name" (NAME of the release) as optional arguments to the helm_template module.
It contains the rest of my planned work towards #313.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
plugins/modules/helm_template.py
changelogs/fragments/313-helm-template-add-support-for-name-and-disablehook.yml
tests/unit/modules/test_helm_template.py
integration/targets/helm/tasks/tests_chart.yml
ADDITIONAL INFORMATION
The PR contains unit tests and an integration test for the new parameters added in this and the previous PR.
I limited the execution of the integration test to the local test chart, because the testing of the "show_only" parameter requires a known chart structure. As I think I do not have to test the workings of "helm template ..." itself, I hope this is sufficient.
Please adjust / comment as necessary.
Reviewed-by: Mike Graves <mgraves@redhat.com>