mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-06 21:12:37 +00:00
Add support for dry run (#245)
Add support for dry run SUMMARY Kubernetes server-side dry run will be used when the kubernetes client version is >=18.20.0. For older versions of the client, the existing client side speculative change implementation will be used. The effect of this change should be mostly transparent to the end user and is reflected in the fact the tests have not changed but should still pass. With this change, there are a few edge cases that will be improved. One example of these edge cases is to use check mode on an existing Service resource. With dry run this will correctly report no changes, while the older client side implementation will erroneously report changes to the port spec. ISSUE TYPE Feature Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Gonéri Le Bouder <goneri@lebouder.net> Reviewed-by: Mike Graves <mgraves@redhat.com> Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None> Reviewed-by: None <None>
This commit is contained in:
@@ -24,7 +24,7 @@ from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import
|
||||
|
||||
|
||||
class K8SDynamicClient(DynamicClient):
|
||||
def apply(self, resource, body=None, name=None, namespace=None):
|
||||
def apply(self, resource, body=None, name=None, namespace=None, **kwargs):
|
||||
body = super().serialize_body(body)
|
||||
body['metadata'] = body.get('metadata', dict())
|
||||
name = name or body['metadata'].get('name')
|
||||
@@ -33,7 +33,7 @@ class K8SDynamicClient(DynamicClient):
|
||||
if resource.namespaced:
|
||||
body['metadata']['namespace'] = super().ensure_namespace(resource, namespace, body)
|
||||
try:
|
||||
return k8s_apply(resource, body)
|
||||
return k8s_apply(resource, body, **kwargs)
|
||||
except ApplyException as e:
|
||||
raise ValueError("Could not apply strategic merge to %s/%s: %s" %
|
||||
(body['kind'], body['metadata']['name'], e))
|
||||
|
||||
Reference in New Issue
Block a user