generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support diff mode for k8s module * Update and rename 145-k8s-add-support-diff-mode.yml to 146-k8s-add-support-diff-mode.yml * Update 146-k8s-add-support-diff-mode.yml * Update changelogs/fragments/146-k8s-add-support-diff-mode.yml Co-authored-by: Mike Graves <mgraves@redhat.com> * update k8s_scale and k8s_json_patch * diff for k8s_scale and k8s_json_patch Co-authored-by: Mike Graves <mgraves@redhat.com>
- Loading branch information
Showing
9 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- k8s - Fixes a bug where diff was always returned when using apply or modifying an existing object, even when diff=no was specified. The module no longer returns diff unless requested and will now honor diff=no (https://github.com/ansible-collections/kubernetes.core/pull/146). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
--- | ||
- set_fact: | ||
diff_namespace: "diff" | ||
diff_configmap: "diff-configmap" | ||
|
||
- block: | ||
- name: Ensure namespace | ||
k8s: | ||
kind: Namespace | ||
name: '{{ diff_namespace }}' | ||
|
||
# Using option 'apply' set to 'yes' | ||
- name: Create Pod using apply and diff set to yes | ||
k8s: | ||
namespace: '{{ diff_namespace }}' | ||
apply: yes | ||
template: "pod_diff.j2" | ||
diff: yes | ||
vars: | ||
pod_name: "pod-apply" | ||
pod_image: "busybox:1.32.0" | ||
register: result | ||
|
||
- name: check that result has diff attribute | ||
assert: | ||
that: | ||
- result is changed | ||
- result.diff is defined | ||
|
||
- name: Update pod definition using apply and diff set to no | ||
k8s: | ||
namespace: '{{ diff_namespace }}' | ||
apply: yes | ||
template: "pod_diff.j2" | ||
diff: no | ||
vars: | ||
pod_name: "pod-apply" | ||
pod_image: "busybox:1.33.0" | ||
register: result | ||
|
||
- name: check that output has no diff attribute | ||
assert: | ||
that: | ||
- result is changed | ||
- result.diff is not defined | ||
|
||
# Using option 'state=patched' | ||
- name: Create Pod using state=present and diff set to yes | ||
k8s: | ||
namespace: '{{ diff_namespace }}' | ||
state: present | ||
template: "pod_diff.j2" | ||
vars: | ||
pod_name: "pod-patch" | ||
pod_image: "busybox:1.32.0" | ||
register: result | ||
|
||
- name: Update pod definition using state=patched | ||
k8s: | ||
namespace: '{{ diff_namespace }}' | ||
state: patched | ||
template: "pod_diff.j2" | ||
diff: no | ||
vars: | ||
pod_name: "pod-patch" | ||
pod_image: "busybox:1.33.0" | ||
pod_label: "patching" | ||
register: result | ||
|
||
- name: check that output has no diff attribute | ||
assert: | ||
that: | ||
- result is changed | ||
- result.diff is not defined | ||
|
||
- name: Update pod definition using state=patched and diff=yes | ||
k8s: | ||
namespace: '{{ diff_namespace }}' | ||
state: patched | ||
template: "pod_diff.j2" | ||
diff: yes | ||
vars: | ||
pod_name: "pod-patch" | ||
pod_image: "busybox:1.33.0" | ||
pod_label: "running" | ||
register: result | ||
|
||
- name: check that output has no diff attribute | ||
assert: | ||
that: | ||
- result is changed | ||
- result.diff is defined | ||
|
||
# check diff mode using force=yes | ||
- name: Create a ConfigMap | ||
k8s: | ||
kind: ConfigMap | ||
name: '{{ diff_configmap }}' | ||
namespace: '{{ diff_namespace }}' | ||
definition: | ||
data: | ||
key: "initial value" | ||
diff: yes | ||
register: result | ||
|
||
- name: check that output has no diff attribute | ||
assert: | ||
that: | ||
- result is changed | ||
- result.diff is not defined | ||
|
||
- name: Update ConfigMap using force and diff=no | ||
k8s: | ||
kind: ConfigMap | ||
name: '{{ diff_configmap }}' | ||
namespace: '{{ diff_namespace }}' | ||
force: yes | ||
definition: | ||
data: | ||
key: "update value with diff=no" | ||
diff: no | ||
register: result | ||
|
||
- name: check that output has no diff attribute | ||
assert: | ||
that: | ||
- result is changed | ||
- result.diff is not defined | ||
|
||
- name: Update ConfigMap using force and diff=yes | ||
k8s: | ||
kind: ConfigMap | ||
name: '{{ diff_configmap }}' | ||
namespace: '{{ diff_namespace }}' | ||
force: yes | ||
definition: | ||
data: | ||
key: "update value with diff=yes" | ||
diff: yes | ||
register: result | ||
|
||
- name: check that output has diff attribute | ||
assert: | ||
that: | ||
- result is changed | ||
- result.diff is defined | ||
|
||
always: | ||
- name: Ensure namespace is deleted | ||
k8s: | ||
state: absent | ||
kind: Namespace | ||
name: '{{ diff_namespace }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: {{ pod_name }} | ||
labels: | ||
ansible: {{ pod_label | default('demo') }} | ||
spec: | ||
containers: | ||
- name: c0 | ||
image: {{ pod_image }} | ||
command: | ||
- /bin/sh | ||
- -c | ||
- while true;do date;sleep 5; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters