k8s - patch existing resource (#90)

* patch only

* add changelogs

* Rename 89-k8s-add-parameter-patch_only.yml to 90-k8s-add-parameter-patch_only.yml

* Update 90-k8s-add-parameter-patch_only.yml

* patch_only parameter changed to state=patched

* Update 90-k8s-add-parameter-patch_only.yml

* Update plugins/modules/k8s.py

Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us>

* Update molecule/default/tasks/patched.yml

Co-authored-by: John Mazzitelli <mazz@redhat.com>

* Update molecule/default/tasks/patched.yml

Co-authored-by: John Mazzitelli <mazz@redhat.com>

* sanity issue

Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us>
Co-authored-by: John Mazzitelli <mazz@redhat.com>
This commit is contained in:
abikouo
2021-05-19 11:03:11 +02:00
committed by GitHub
parent 5856948657
commit 192cae1507
5 changed files with 178 additions and 7 deletions

View File

@@ -30,7 +30,6 @@ description:
- Supports check mode.
extends_documentation_fragment:
- kubernetes.core.k8s_state_options
- kubernetes.core.k8s_name_options
- kubernetes.core.k8s_resource_options
- kubernetes.core.k8s_auth_options
@@ -38,6 +37,21 @@ extends_documentation_fragment:
- kubernetes.core.k8s_delete_options
options:
state:
description:
- Determines if an object should be created, patched, or deleted. When set to C(present), an object will be
created, if it does not already exist. If set to C(absent), an existing object will be deleted. If set to
C(present), an existing object will be patched, if its attributes differ from those specified using
I(resource_definition) or I(src).
- C(patched) state is an existing resource that has a given patch applied. If the resource doesn't exist, silently skip it (do not raise an error).
type: str
default: present
choices: [ absent, present, patched ]
force:
description:
- If set to C(yes), and I(state) is C(present), an existing object will be replaced.
type: bool
default: no
merge_type:
description:
- Whether to override the default patch merge approach with a specific type. By default, the strategic
@@ -236,6 +250,17 @@ EXAMPLES = r'''
type: Progressing
status: Unknown
reason: DeploymentPaused
# Patch existing namespace : add label
- name: add label to existing namespace
kubernetes.core.k8s:
state: patched
kind: Namespace
name: patch_namespace
definition:
metadata:
labels:
support: patch
'''
RETURN = r'''
@@ -284,7 +309,7 @@ import copy
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, WAIT_ARG_SPEC, NAME_ARG_SPEC, COMMON_ARG_SPEC, RESOURCE_ARG_SPEC, DELETE_OPTS_ARG_SPEC)
AUTH_ARG_SPEC, WAIT_ARG_SPEC, NAME_ARG_SPEC, RESOURCE_ARG_SPEC, DELETE_OPTS_ARG_SPEC)
def validate_spec():
@@ -296,8 +321,7 @@ def validate_spec():
def argspec():
argument_spec = copy.deepcopy(COMMON_ARG_SPEC)
argument_spec.update(copy.deepcopy(NAME_ARG_SPEC))
argument_spec = copy.deepcopy(NAME_ARG_SPEC)
argument_spec.update(copy.deepcopy(RESOURCE_ARG_SPEC))
argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC))
argument_spec.update(copy.deepcopy(WAIT_ARG_SPEC))
@@ -308,6 +332,9 @@ def argspec():
argument_spec['template'] = dict(type='raw', default=None)
argument_spec['delete_options'] = dict(type='dict', default=None, options=copy.deepcopy(DELETE_OPTS_ARG_SPEC))
argument_spec['continue_on_error'] = dict(type='bool', default=False)
argument_spec['state'] = dict(default='present', choices=['present', 'absent', 'patched'])
argument_spec['force'] = dict(type='bool', default=False)
return argument_spec
@@ -319,6 +346,7 @@ def execute_module(module, k8s_ansible_mixin):
k8s_ansible_mixin.fail_json = k8s_ansible_mixin.module.fail_json
k8s_ansible_mixin.fail = k8s_ansible_mixin.module.fail_json
k8s_ansible_mixin.exit_json = k8s_ansible_mixin.module.exit_json
k8s_ansible_mixin.warn = k8s_ansible_mixin.module.warn
k8s_ansible_mixin.warnings = []
k8s_ansible_mixin.kind = k8s_ansible_mixin.params.get('kind')