Skip to content

Commit

Permalink
ensure json path works
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <[email protected]>
  • Loading branch information
Lawouach committed Oct 2, 2023
1 parent e1886bb commit 6add238
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## [Unreleased][]

[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.30.1...HEAD
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.30.2...HEAD

## [0.30.2][] - 2023-10-02

[0.30.2]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.30.1...0.30.2

### Fixed

* Patching Custom Resources required the appropriate header to be set as per
https://github.com/kubernetes-client/python/issues/1216#issuecomment-1229132922

## [0.30.1][] - 2023-09-28

Expand Down
2 changes: 1 addition & 1 deletion chaosk8s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from logzero import logger

__all__ = ["create_k8s_api_client", "discover", "__version__"]
__version__ = "0.30.1"
__version__ = "0.30.2"


def get_config_path() -> str:
Expand Down
12 changes: 10 additions & 2 deletions chaosk8s/crd/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,19 @@ def patch_custom_object(
updated version to apply. Force will re-acquire conflicting fields
owned by others.
The resource, or resource_as_yaml_file, must be a JSON Patch document.
Read more about custom resources here:
https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/
""" # noqa: E501
api = client.CustomObjectsApi(create_k8s_api_client(secrets))
body = load_body(resource, resource_as_yaml_file)

try:
# https://github.com/kubernetes-client/python/issues/1216
api.api_client.set_default_header("Content-Type", "application/json-patch+json")
r = api.patch_namespaced_custom_object(
group, version, ns, plural, name, body, force=force, _preload_content=False
group, version, ns, plural, name, body, _preload_content=False
)
return json.loads(r.data)
except ApiException as x:
Expand Down Expand Up @@ -264,15 +268,19 @@ def patch_cluster_custom_object(
updated version to apply. Force will re-acquire conflicting fields
owned by others.
The resource, or resource_as_yaml_file, must be a JSON Patch document.
Read more about custom resources here:
https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/
""" # noqa: E501
api = client.CustomObjectsApi(create_k8s_api_client(secrets))
body = load_body(resource, resource_as_yaml_file)

try:
# https://github.com/kubernetes-client/python/issues/1216
api.api_client.set_default_header("Content-Type", "application/json-patch+json")
r = api.patch_cluster_custom_object(
group, version, plural, name, body, force=force, _preload_content=False
group, version, plural, name, body, _preload_content=False
)
return json.loads(r.data)
except ApiException as x:
Expand Down
1 change: 0 additions & 1 deletion tests/test_crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ def test_patching_cro(cl, client, has_conf):
"crontabs",
"my-new-cron-object",
resource,
force=False,
_preload_content=False,
)

Expand Down

0 comments on commit 6add238

Please sign in to comment.