mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-12 12:32:05 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2594ac654b | ||
|
|
c11a255026 | ||
|
|
46494a18bd | ||
|
|
4ccb15d4ad | ||
|
|
58dba6bf22 |
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -75,6 +75,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python_version: ['3.7']
|
python_version: ['3.7']
|
||||||
|
ansible_version: ['==2.9.*', '==2.10.*', '']
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@@ -92,7 +93,7 @@ jobs:
|
|||||||
# The 3.3.0 release of molecule introduced a breaking change. See
|
# The 3.3.0 release of molecule introduced a breaking change. See
|
||||||
# https://github.com/ansible-community/molecule/issues/3083
|
# https://github.com/ansible-community/molecule/issues/3083
|
||||||
- name: Install molecule and kubernetes dependencies
|
- name: Install molecule and kubernetes dependencies
|
||||||
run: pip install ansible "molecule<3.3.0" yamllint kubernetes flake8 jsonpatch
|
run: pip install ansible${{ matrix.ansible_version }} "molecule<3.3.0" yamllint kubernetes flake8 jsonpatch
|
||||||
|
|
||||||
# The latest release doesn't work with Molecule currently.
|
# The latest release doesn't work with Molecule currently.
|
||||||
# See: https://github.com/ansible-community/molecule/issues/2757
|
# See: https://github.com/ansible-community/molecule/issues/2757
|
||||||
|
|||||||
@@ -5,6 +5,15 @@ Kubernetes Collection Release Notes
|
|||||||
.. contents:: Topics
|
.. contents:: Topics
|
||||||
|
|
||||||
|
|
||||||
|
v2.0.2
|
||||||
|
======
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
- Fix apply for k8s module when an array attribute from definition contains empty dict (https://github.com/ansible-collections/kubernetes.core/issues/113).
|
||||||
|
- rename the apply function to fix broken imports in Ansible 2.9 (https://github.com/ansible-collections/kubernetes.core/pull/135).
|
||||||
|
|
||||||
v2.0.1
|
v2.0.1
|
||||||
======
|
======
|
||||||
|
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
|||||||
# Also needs to be updated in galaxy.yml
|
# Also needs to be updated in galaxy.yml
|
||||||
VERSION = 2.0.1
|
VERSION = 2.0.2
|
||||||
|
|
||||||
TEST_ARGS ?= ""
|
TEST_ARGS ?= ""
|
||||||
PYTHON_VERSION ?= `python -c 'import platform; print("{0}.{1}".format(platform.python_version_tuple()[0], platform.python_version_tuple()[1]))'`
|
PYTHON_VERSION ?= `python -c 'import platform; print("{0}.{1}".format(platform.python_version_tuple()[0], platform.python_version_tuple()[1]))'`
|
||||||
|
|||||||
@@ -82,7 +82,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: 2.0.1
|
version: 2.0.2
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installing the Kubernetes Python Library
|
### Installing the Kubernetes Python Library
|
||||||
|
|||||||
@@ -403,3 +403,13 @@ releases:
|
|||||||
fragments:
|
fragments:
|
||||||
- 128-update-inventory-plugin-param.yaml
|
- 128-update-inventory-plugin-param.yaml
|
||||||
release_date: '2021-06-11'
|
release_date: '2021-06-11'
|
||||||
|
2.0.2:
|
||||||
|
changes:
|
||||||
|
bugfixes:
|
||||||
|
- Fix apply for k8s module when an array attribute from definition contains
|
||||||
|
empty dict (https://github.com/ansible-collections/kubernetes.core/issues/113).
|
||||||
|
- rename the apply function to fix broken imports in Ansible 2.9 (https://github.com/ansible-collections/kubernetes.core/pull/135).
|
||||||
|
fragments:
|
||||||
|
- 129-k8s-fix-apply-array-with-empty-dict.yml
|
||||||
|
- 135-rename-apply-function.yml
|
||||||
|
release_date: '2021-06-16'
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ tags:
|
|||||||
- openshift
|
- openshift
|
||||||
- okd
|
- okd
|
||||||
- cluster
|
- cluster
|
||||||
version: 2.0.1
|
version: 2.0.2
|
||||||
build_ignore:
|
build_ignore:
|
||||||
- .DS_Store
|
- .DS_Store
|
||||||
- '*.tar.gz'
|
- '*.tar.gz'
|
||||||
|
|||||||
@@ -836,6 +836,66 @@
|
|||||||
that:
|
that:
|
||||||
- k8s_secret is not changed
|
- k8s_secret is not changed
|
||||||
|
|
||||||
|
- name: Create network policy (egress array with empty dict)
|
||||||
|
k8s:
|
||||||
|
namespace: "{{ apply_namespace }}"
|
||||||
|
apply: true
|
||||||
|
definition:
|
||||||
|
kind: NetworkPolicy
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: apply-netpolicy
|
||||||
|
labels:
|
||||||
|
app: apply-netpolicy
|
||||||
|
annotations:
|
||||||
|
{}
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
app: apply-netpolicy
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
ingress:
|
||||||
|
- ports:
|
||||||
|
- port: 9093
|
||||||
|
protocol: TCP
|
||||||
|
egress:
|
||||||
|
- {}
|
||||||
|
|
||||||
|
- name: Apply network policy
|
||||||
|
k8s:
|
||||||
|
namespace: "{{ apply_namespace }}"
|
||||||
|
definition:
|
||||||
|
kind: NetworkPolicy
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: apply-netpolicy
|
||||||
|
labels:
|
||||||
|
app: apply-netpolicy
|
||||||
|
annotations:
|
||||||
|
{}
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
app: apply-netpolicy
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
ingress:
|
||||||
|
- ports:
|
||||||
|
- port: 9093
|
||||||
|
protocol: TCP
|
||||||
|
egress:
|
||||||
|
- {}
|
||||||
|
apply: true
|
||||||
|
register: k8s_networkpolicy
|
||||||
|
|
||||||
|
- name: Check that nothing changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- k8s_networkpolicy is not changed
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Remove namespace
|
- name: Remove namespace
|
||||||
k8s:
|
k8s:
|
||||||
|
|||||||
@@ -219,7 +219,7 @@
|
|||||||
|
|
||||||
### https://github.com/ansible-collections/community.kubernetes/issues/111
|
### https://github.com/ansible-collections/community.kubernetes/issues/111
|
||||||
- set_fact:
|
- set_fact:
|
||||||
api_groups: "{{ lookup('k8s', cluster_info='api_groups') }}"
|
api_groups: "{{ lookup('kubernetes.core.k8s', cluster_info='api_groups') }}"
|
||||||
|
|
||||||
- debug:
|
- debug:
|
||||||
var: api_groups
|
var: api_groups
|
||||||
|
|||||||
@@ -236,8 +236,8 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- resource is successful
|
- resource is successful
|
||||||
- resource.result.results | selectattr('changed') | length == 1
|
- resource.result.results | selectattr('changed') | list | length == 1
|
||||||
- resource.result.results | selectattr('error', 'defined') | length == 1
|
- resource.result.results | selectattr('error', 'defined') | list | length == 1
|
||||||
|
|
||||||
- name: Remove Pod (Cleanup)
|
- name: Remove Pod (Cleanup)
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
|
|||||||
1
plugins/action/helm.py
Symbolic link
1
plugins/action/helm.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/helm_info.py
Symbolic link
1
plugins/action/helm_info.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/helm_plugin.py
Symbolic link
1
plugins/action/helm_plugin.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/helm_plugin_info.py
Symbolic link
1
plugins/action/helm_plugin_info.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/helm_repository.py
Symbolic link
1
plugins/action/helm_repository.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/k8s.py
Symbolic link
1
plugins/action/k8s.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/k8s_cluster_info.py
Symbolic link
1
plugins/action/k8s_cluster_info.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/k8s_exec.py
Symbolic link
1
plugins/action/k8s_exec.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/k8s_log.py
Symbolic link
1
plugins/action/k8s_log.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/k8s_rollback.py
Symbolic link
1
plugins/action/k8s_rollback.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/k8s_scale.py
Symbolic link
1
plugins/action/k8s_scale.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/k8s_service.py
Symbolic link
1
plugins/action/k8s_service.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
1
plugins/action/ks8_json_patch.py
Symbolic link
1
plugins/action/ks8_json_patch.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
k8s_info.py
|
||||||
@@ -18,10 +18,8 @@ __metaclass__ = type
|
|||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import json
|
import json
|
||||||
import sys
|
|
||||||
|
|
||||||
from ansible.module_utils.common.dict_transformations import dict_merge
|
from ansible.module_utils.common.dict_transformations import dict_merge
|
||||||
from ansible.module_utils.six import PY3
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import ApplyException
|
from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import ApplyException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -29,8 +27,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if PY3:
|
|
||||||
unicode = str
|
|
||||||
|
|
||||||
LAST_APPLIED_CONFIG_ANNOTATION = 'kubectl.kubernetes.io/last-applied-configuration'
|
LAST_APPLIED_CONFIG_ANNOTATION = 'kubectl.kubernetes.io/last-applied-configuration'
|
||||||
|
|
||||||
@@ -79,34 +75,6 @@ STRATEGIC_MERGE_PATCH_KEYS.update(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info.major >= 3:
|
|
||||||
json_loads_byteified = json.loads
|
|
||||||
else:
|
|
||||||
# https://stackoverflow.com/a/33571117
|
|
||||||
def json_loads_byteified(json_text):
|
|
||||||
return _byteify(
|
|
||||||
json.loads(json_text, object_hook=_byteify),
|
|
||||||
ignore_dicts=True
|
|
||||||
)
|
|
||||||
|
|
||||||
def _byteify(data, ignore_dicts=False):
|
|
||||||
# if this is a unicode string, return its string representation
|
|
||||||
if isinstance(data, unicode): # noqa: F821
|
|
||||||
return data.encode('utf-8')
|
|
||||||
# if this is a list of values, return list of byteified values
|
|
||||||
if isinstance(data, list):
|
|
||||||
return [_byteify(item, ignore_dicts=True) for item in data]
|
|
||||||
# if this is a dictionary, return dictionary of byteified keys and values
|
|
||||||
# but only if we haven't already byteified it
|
|
||||||
if isinstance(data, dict) and not ignore_dicts:
|
|
||||||
return {
|
|
||||||
_byteify(key, ignore_dicts=True): _byteify(value, ignore_dicts=True)
|
|
||||||
for key, value in data.items()
|
|
||||||
}
|
|
||||||
# if it's anything else, return it in its original form
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def annotate(desired):
|
def annotate(desired):
|
||||||
return dict(
|
return dict(
|
||||||
metadata=dict(
|
metadata=dict(
|
||||||
@@ -123,7 +91,7 @@ def apply_patch(actual, desired):
|
|||||||
if last_applied:
|
if last_applied:
|
||||||
# ensure that last_applied doesn't come back as a dict of unicode key/value pairs
|
# ensure that last_applied doesn't come back as a dict of unicode key/value pairs
|
||||||
# json.loads can be used if we stop supporting python 2
|
# json.loads can be used if we stop supporting python 2
|
||||||
last_applied = json_loads_byteified(last_applied)
|
last_applied = json.loads(last_applied)
|
||||||
patch = merge(dict_merge(last_applied, annotate(last_applied)),
|
patch = merge(dict_merge(last_applied, annotate(last_applied)),
|
||||||
dict_merge(desired, annotate(desired)), actual)
|
dict_merge(desired, annotate(desired)), actual)
|
||||||
if patch:
|
if patch:
|
||||||
@@ -142,7 +110,7 @@ def apply_object(resource, definition):
|
|||||||
return apply_patch(actual.to_dict(), definition)
|
return apply_patch(actual.to_dict(), definition)
|
||||||
|
|
||||||
|
|
||||||
def apply(resource, definition):
|
def k8s_apply(resource, definition):
|
||||||
existing, desired = apply_object(resource, definition)
|
existing, desired = apply_object(resource, definition)
|
||||||
if not existing:
|
if not existing:
|
||||||
return resource.create(body=desired, namespace=definition['metadata'].get('namespace'))
|
return resource.create(body=desired, namespace=definition['metadata'].get('namespace'))
|
||||||
@@ -284,7 +252,7 @@ def get_delta(last_applied, actual, desired, position=None):
|
|||||||
elif isinstance(desired_value, list):
|
elif isinstance(desired_value, list):
|
||||||
p = list_merge(last_applied.get(k, []), actual_value, desired_value, this_position)
|
p = list_merge(last_applied.get(k, []), actual_value, desired_value, this_position)
|
||||||
if p:
|
if p:
|
||||||
patch[k] = [item for item in p if item]
|
patch[k] = [item for item in p if item is not None]
|
||||||
elif actual_value != desired_value:
|
elif actual_value != desired_value:
|
||||||
patch[k] = desired_value
|
patch[k] = desired_value
|
||||||
return patch
|
return patch
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ __metaclass__ = type
|
|||||||
|
|
||||||
from kubernetes.dynamic import DynamicClient
|
from kubernetes.dynamic import DynamicClient
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.apply import apply
|
from ansible_collections.kubernetes.core.plugins.module_utils.apply import k8s_apply
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import ApplyException
|
from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import ApplyException
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ class K8SDynamicClient(DynamicClient):
|
|||||||
if resource.namespaced:
|
if resource.namespaced:
|
||||||
body['metadata']['namespace'] = super().ensure_namespace(resource, namespace, body)
|
body['metadata']['namespace'] = super().ensure_namespace(resource, namespace, body)
|
||||||
try:
|
try:
|
||||||
return apply(resource, body)
|
return k8s_apply(resource, body)
|
||||||
except ApplyException as e:
|
except ApplyException as e:
|
||||||
raise ValueError("Could not apply strategic merge to %s/%s: %s" %
|
raise ValueError("Could not apply strategic merge to %s/%s: %s" %
|
||||||
(body['kind'], body['metadata']['name'], e))
|
(body['kind'], body['metadata']['name'], e))
|
||||||
|
|||||||
Reference in New Issue
Block a user