Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split JSON patch out into a new module #99

Merged
merged 11 commits into from
May 24, 2021

Conversation

gravesm
Copy link
Member

@gravesm gravesm commented May 10, 2021

SUMMARY

JSON patch in the k8s module has likely never worked. Furthermore,
having resource_definition double as the parameter for patch operations
makes fixing this in k8s difficult. This is due, in part, to the fact
that a single patch consists of a list of operations that should be
processed as a whole, while resource_definition supports a list of
resources that should be processed separately. The merge_type parameter
allows more than one merge strategy to be specified, but there is no
case where a JSON patch could work for JSON merge or strategic merge,
nor the other way around.

This commit moves JSON patch functionality out into a separate module.
Check mode support is provided through the third party jsonpatch
library.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

k8s_json_patch

ADDITIONAL INFORMATION

@codecov
Copy link

codecov bot commented May 10, 2021

Codecov Report

Merging #99 (4ef21ac) into main (0bbc9ca) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #99   +/-   ##
=======================================
  Coverage   24.02%   24.02%           
=======================================
  Files           1        1           
  Lines         154      154           
  Branches       29       29           
=======================================
  Hits           37       37           
  Misses        112      112           
  Partials        5        5           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0bbc9ca...4ef21ac. Read the comment docs.

@gravesm gravesm requested review from abikouo and Akasurde May 10, 2021 18:52
Comment on lines 2 to 4
minor_changes:
- k8s_json_patch - split JSON patch functionality out into a separate module (https://github.com/ansible-collections/kubernetes.core/pull/99).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
minor_changes:
- k8s_json_patch - split JSON patch functionality out into a separate module (https://github.com/ansible-collections/kubernetes.core/pull/99).
major_changes:
- k8s - the JSON patch functionality has been removed. This feature never worked.
- k8s_json_patch - split JSON patch functionality out into a separate module (https://github.com/ansible-collections/kubernetes.core/pull/99).

If this truly never worked and this won't change any interfaces/behaviour for existing playbooks that might be trying to use this it doesn't really need to be deprecated, but let's still leave a clear paper trail for users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have gone ahead and just deprecated merge_type=json. While it never worked, it usually failed silently.

Copy link
Member

@Akasurde Akasurde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM. Feel free to merge after resolving the comments.

plugins/modules/k8s_json_patch.py Outdated Show resolved Hide resolved
plugins/modules/k8s_json_patch.py Outdated Show resolved Hide resolved
plugins/modules/k8s_json_patch.py Outdated Show resolved Hide resolved
plugins/modules/k8s_json_patch.py Outdated Show resolved Hide resolved
plugins/modules/k8s_json_patch.py Show resolved Hide resolved
@abikouo
Copy link
Contributor

abikouo commented May 11, 2021

I am thinking about having a k8s_patch module instead dealing with all related patch stuffs like the kubectl patch command. However for the definition used for strategic merge can also be used to create an object for now, but we should remove this feature to have a module k8s_patch patching only existing objects and k8s used to create them.

@gravesm
Copy link
Member Author

gravesm commented May 11, 2021

@abikouo I'm unclear what you are suggesting. Are you saying you disagree with this module as a whole and you don't think we should add it? As I commented here, I think removing all the patch functionality from the k8s module is going to be pretty controversial.

@fabianvf
Copy link
Contributor

nice! lgtm, and I think it makes sense to have json-patch be its own module with state=patched in the main module. json-patch is just so different it would be kind of awkward even in a shared patch module

gravesm and others added 10 commits May 19, 2021 11:22
JSON patch in the k8s module has likely never worked. Furthermore,
having resource_definition double as the parameter for patch operations
makes fixing this in k8s difficult. This is due, in part, to the fact
that a single patch consists of a list of operations that should be
processed as a whole, while resource_definition supports a list of
resources that should be processed separately. The merge_type parameter
allows more than one merge strategy to be specified, but there is no
case where a JSON patch could work for JSON merge or strategic merge,
nor the other way around.

This commit moves JSON patch functionality out into a separate module.
Check mode support is provided through the third party jsonpatch
library.
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
@gravesm gravesm force-pushed the json-patch-module branch from 29c0c27 to 2433d6d Compare May 19, 2021 15:26
Copy link
Contributor

@fabianvf fabianvf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #99 (comment)

One thing to note is that the other modules do return result [0][1]. If result isn't appropriate we should probably change the return value in the other modules as well for 3.0, and it would be nice if it matched what was output here (so probably not patched_output). As a user I think it would be nicer if there was a consistent return value key I could check, rather than having to check/remember what the output key for the same type of information is for each module separately. Perhaps k8s_object or something like that would make sense.

0: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_module.rst#return-values
1: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_scale_module.rst#return-values

- while true; do echo $(date); sleep 10; done
wait: yes

- name: Add a label and replace the image in checkmode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a case that tests the remove action and verifies it's idempotent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure if we can test idempotency for remove ops. The path won't exist the second time around and kubernetes will return an error.

@gravesm
Copy link
Member Author

gravesm commented May 20, 2021

@fabianvf false alarm. result is not a reserved keyword. Reverting back to result.

@Akasurde Akasurde self-requested a review May 21, 2021 06:25
@Akasurde
Copy link
Member

LGTM

@Akasurde Akasurde merged commit 5b5777d into ansible-collections:main May 24, 2021
@gravesm gravesm deleted the json-patch-module branch May 24, 2021 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants