Compare commits

9 Commits
2.2.1 ... 2.2.3

Author SHA1 Message Date
abikouo
0d9c4d3459 Release 2.2.3 (#340) 2022-01-19 12:15:40 +01:00
Mike Graves
3645c1c16c Add integration test to check handling of module_defaults (#296) (#333)
Add integration test to check handling of module_defaults

SUMMARY

Add integration test to make sure that module_defaults are handled correctly in tasks.
Related to #126.

ISSUE TYPE

Bugfix Pull Request

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

Co-authored-by: Mandar Kulkarni <mandar242@gmail.com>
2022-01-18 08:38:38 -05:00
Mike Graves
5fdd70cbc3 [backport/2.2] Fix k8s_drain failing when pod has local storage (#332) 2022-01-17 10:53:57 +05:30
Mike Graves
1c02fe3443 [backport/2.2] Don't wait on *List resources for info module (#331) 2022-01-17 10:43:40 +05:30
Mike Graves
eaffde63bb [backport/2.2] Fix for common non-ASCII characters in CRDs (#334)
Co-authored-by: Alessandro Rossi <4215912+kubealex@users.noreply.github.com>
2022-01-14 07:49:37 +05:30
Mike Graves
d8538ffed3 Release 2.2.2 (#305)
Release 2.2.2

Reviewed-by: Abhijeet Kasurde <None>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
2021-12-07 20:08:22 +00:00
Mike Graves
bc168a5727 Remove binary file from molecule test suite (#298) (#302)
[backport/2.2] Remove binary file from molecule test suite

SUMMARY

The binary file used to test k8s_cp is causing larger problems
downstream. There's no reason why the binary file needs to function as
all we care about is that the content of the file has not changed during
the copy process. This can be accomplished by comparing file hashes.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION


Reviewed-by: Abhijeet Kasurde 
Reviewed-by: None 
(cherry picked from commit fa65698)

Reviewed-by: None <None>
2021-12-07 08:39:20 +00:00
Mike Graves
dc5a1e6dd1 turn network-ee-sanity-tests non-voting (#284) (#303)
[backport/2.2] turn network-ee-sanity-tests non-voting

SUMMARY

turn network-ee-sanity-tests non-voting
Reviewed-by: Mike Graves mgraves@redhat.com
Reviewed-by: None 
(cherry picked from commit b0f1501)

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: None <None>
2021-12-06 18:49:59 +00:00
Mike Graves
72536fe286 Fix sanity tests (#283) (#304)
[backport/2.2] Fix sanity tests

SUMMARY

Fix sanity tests
Reviewed-by: None 
Reviewed-by: None 
(cherry picked from commit 1116056)

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: None <None>
2021-12-06 17:13:18 +00:00
15 changed files with 210 additions and 45 deletions

View File

@@ -0,0 +1,10 @@
- project:
name: github.com/ansible-collections/kubernetes.core
check:
jobs:
- network-ee-sanity-tests:
voting: false
gate:
jobs:
- network-ee-sanity-tests:
voting: false

View File

@@ -5,6 +5,29 @@ Kubernetes Collection Release Notes
.. contents:: Topics
v2.2.3
======
Bugfixes
--------
- k8s_drain - fix error caused by accessing an undefined variable when pods have local storage (https://github.com/ansible-collections/kubernetes.core/issues/292).
- k8s_info - don't wait on empty List resources (https://github.com/ansible-collections/kubernetes.core/pull/253).
- module_utils.common - change default opening mode to read-bytes to avoid bad interpretation of non ascii characters and strings, often present in 3rd party manifests.
Minor Changes
-------------
- Add integration test to check handling of module_defaults (https://github.com/ansible-collections/kubernetes.core/pull/296).
v2.2.2
======
Bugfixes
--------
- remove binary file from k8s_cp test suite (https://github.com/ansible-collections/kubernetes.core/pull/298).
v2.2.1
======

View File

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

View File

@@ -85,7 +85,7 @@ You can also include it in a `requirements.yml` file and install it via `ansible
---
collections:
- name: kubernetes.core
version: 2.2.1
version: 2.2.3
```
### Installing the Kubernetes Python Library

View File

@@ -494,3 +494,27 @@ releases:
- 0-copy_ignore_txt.yml
- _wait_for_label_selector_optional.yaml
release_date: '2021-10-18'
2.2.2:
changes:
bugfixes:
- remove binary file from k8s_cp test suite (https://github.com/ansible-collections/kubernetes.core/pull/298).
fragments:
- 298-remove-binary-file.yaml
release_date: '2021-12-07'
2.2.3:
changes:
bugfixes:
- k8s_drain - fix error caused by accessing an undefined variable when pods
have local storage (https://github.com/ansible-collections/kubernetes.core/issues/292).
- k8s_info - don't wait on empty List resources (https://github.com/ansible-collections/kubernetes.core/pull/253).
- module_utils.common - change default opening mode to read-bytes to avoid bad
interpretation of non ascii characters and strings, often present in 3rd party
manifests.
minor_changes:
- Add integration test to check handling of module_defaults
(https://github.com/ansible-collections/kubernetes.core/pull/296).
fragments:
- 253-dont-wait-on-list-resources.yaml
- 295-fix-k8s-drain-variable-declaration.yaml
- 308-fix-for-common-non-ascii-characters-in-resources.yaml
release_date: '2022-01-18'

View File

@@ -25,7 +25,7 @@ tags:
- openshift
- okd
- cluster
version: 2.2.1
version: 2.2.3
build_ignore:
- .DS_Store
- '*.tar.gz'

View File

@@ -9,7 +9,6 @@ action_groups:
k8s:
- k8s
- k8s_exec
- k8s_facts
- k8s_info
- k8s_log
- k8s_scale

View File

@@ -34,50 +34,65 @@
kubectl_path: "{{ kubectl_path }}"
# Binary file
- name: Generate random content
set_fact:
hello_arg: "{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=16') }}"
- name: Create temp binary file
tempfile:
state: file
register: binfile
- name: Generate random binary content
command: dd if=/dev/urandom of={{ binfile.path }} bs=1M count=1
- name: Copy executable into Pod
k8s_cp:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: files/hello
local_path: "{{ binfile.path }}"
state: to_pod
- name: Compare executable
kubectl_file_compare:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: "{{ role_path }}/files/hello"
kubectl_path: "{{ kubectl_path }}"
args:
- "{{ hello_arg }}"
- name: Get remote hash
kubernetes.core.k8s_exec:
namespace: "{{ copy_namespace }}"
pod: "{{ pod_with_one_container.name }}"
command: sha256sum -b /tmp/hello.exe
register: remote_hash
- name: Get local hash
command: sha256sum -b {{ binfile.path }}
register: local_hash
- assert:
that:
- remote_hash.stdout.split()[0] == local_hash.stdout.split()[0]
- name: Generate tempfile
tempfile:
state: file
register: binfile
- name: Copy executable from Pod
k8s_cp:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: /tmp/hello
local_path: "{{ binfile.path }}"
state: from_pod
- name: update executable permission
file:
path: /tmp/hello
mode: '0755'
- name: Get remote hash
kubernetes.core.k8s_exec:
namespace: "{{ copy_namespace }}"
pod: "{{ pod_with_one_container.name }}"
command: sha256sum -b /tmp/hello.exe
register: remote_hash
- name: Compare executable
kubectl_file_compare:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: /tmp/hello
kubectl_path: "{{ kubectl_path }}"
args:
- "{{ hello_arg }}"
- name: Get local hash
command: sha256sum -b {{ binfile.path }}
register: local_hash
- assert:
that:
- remote_hash.stdout.split()[0] == local_hash.stdout.split()[0]
# zip files
- name: copy zip file into remote pod

View File

@@ -421,6 +421,49 @@
that:
- result.resources[0].data.testkey == "{{ cmap_data.stdout | b64encode }}"
# test setting module defaults for kubernetes.core.k8s_info
- block:
- name: Create a namespace
kubernetes.core.k8s:
name: test-namespace-module-defaults
kind: Namespace
register: output
- name: Create a ConfigMap
kubernetes.core.k8s:
kind: ConfigMap
name: test-configmap-1
definition:
data:
key1: value1
- name: Create another ConfigMap
kubernetes.core.k8s:
kind: ConfigMap
name: test-configmap-2
definition:
data:
key2: value2
- name: Get list of all ConfigMaps in namespace specified in module_defaults
kubernetes.core.k8s_info:
kind: ConfigMap
register: configmap_info
- name: assert that the ConfigMaps are created in and info is retrieved for namespace specified in module_defaults
assert:
that:
- configmap_info.resources[1].metadata.name == "test-configmap-1"
- configmap_info.resources[1].metadata.namespace == "test-namespace-module-defaults"
- configmap_info.resources[2].metadata.name == "test-configmap-2"
- configmap_info.resources[2].metadata.namespace == "test-namespace-module-defaults"
module_defaults:
group/kubernetes.core.k8s:
namespace: test-namespace-module-defaults
when: ansible_version.full is version("2.12", ">=")
always:
- name: Delete all namespaces
k8s:
@@ -454,4 +497,8 @@
apiVersion: v1
metadata:
name: testing6
- kind: Namespace
apiVersion: v1
metadata:
name: test-namespace-module-defaults
ignore_errors: yes

View File

@@ -199,6 +199,38 @@
that:
- "{{ lookup('pipe', 'date +%s') }} - {{ start }} > 30"
- name: Create simple pod
k8s:
definition:
apiVersion: v1
kind: Pod
metadata:
name: wait-pod-1
namespace: "{{ wait_namespace }}"
spec:
containers:
- image: busybox
name: busybox
command:
- /bin/sh
- -c
- while true; do sleep 5; done
- name: Wait for multiple non-existent pods to be created
k8s_info:
kind: Pod
namespace: "{{ wait_namespace }}"
label_selectors:
- thislabel=doesnotexist
wait: yes
wait_timeout: 10
register: result
- name: Assert no pods were found
assert:
that:
- not result.resources
vars:
k8s_pod_name: pod-info-1

View File

@@ -28,6 +28,6 @@ options:
- Reads from the local file system. To read from the Ansible controller's file system, including vaulted files, use the file lookup
plugin or template lookup plugin, combined with the from_yaml filter, and pass the result to
I(resource_definition). See Examples below.
- Mutually exclusive with I(template) in case of M(k8s) module.
- Mutually exclusive with I(template) in case of M(kubernetes.core.k8s) module.
type: path
'''

View File

@@ -279,18 +279,28 @@ class K8sAnsibleMixin(object):
def _elapsed():
return (datetime.now() - start).seconds
if result is None:
while _elapsed() < wait_timeout:
try:
result = resource.get(name=name, namespace=namespace,
label_selector=','.join(label_selectors),
field_selector=','.join(field_selectors))
break
except NotFoundError:
pass
time.sleep(wait_sleep)
if result is None:
return dict(resources=[], api_found=True)
def result_empty(result):
return (
result is None
or result.kind.endswith("List")
and not result.get("items")
)
while result_empty(result) and _elapsed() < wait_timeout:
try:
result = resource.get(
name=name,
namespace=namespace,
label_selector=",".join(label_selectors),
field_selector=",".join(field_selectors),
)
except NotFoundError:
pass
if not result_empty(result):
break
time.sleep(wait_sleep)
if result_empty(result):
return dict(resources=[], api_found=True)
if isinstance(result, ResourceInstance):
satisfied_by = []
@@ -331,7 +341,7 @@ class K8sAnsibleMixin(object):
if not os.path.exists(path):
self.fail(msg="Error accessing {0}. Does the file exist?".format(path))
try:
with open(path, 'r') as f:
with open(path, "rb") as f:
result = list(yaml.safe_load_all(f))
except (IOError, yaml.YAMLError) as exc:
self.fail(msg="Error loading resource_definition: {0}".format(exc))

View File

@@ -183,6 +183,7 @@ def filter_pods(pods, force, ignore_daemonset):
# local storage
if localStorage:
pod_names = ",".join([pod[0] + "/" + pod[1] for pod in localStorage])
errors.append("cannot delete Pods with local storage: {0}.".format(pod_names))
# DaemonSet managed Pods

View File

@@ -191,6 +191,10 @@ def main():
k8s_ansible_mixin = K8sAnsibleMixin(module)
k8s_ansible_mixin.client = get_api_client(module=module)
k8s_ansible_mixin.fail_json = module.fail_json
k8s_ansible_mixin.fail = module.fail_json
k8s_ansible_mixin.exit_json = module.exit_json
k8s_ansible_mixin.warn = module.warn
execute_module(module, k8s_ansible_mixin)