1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Improve kubernetes validation warnings (#51683)

Warnings get printed at the end of loops, which means that if you're
running validation against a bunch of resources, the warning message
gets printed after a number of potentially unrelated resources.

Adding extra info about the resource failing validation will help
find the validation issues.
This commit is contained in:
Will Thames 2019-02-06 17:09:41 +10:00 committed by René Moser
parent 48642dd1d7
commit 7d181802fb

View file

@ -156,15 +156,18 @@ class KubernetesRawModule(KubernetesAnsibleModule):
})
def validate(self, resource):
def _prepend_resource_info(resource, msg):
return "%s %s: %s" % (resource['kind'], resource['metadata']['name'], msg)
try:
warnings, errors = self.client.validate(resource, self.params['validate'].get('version'), self.params['validate'].get('strict'))
except KubernetesValidateMissing:
self.fail_json(msg="kubernetes-validate python library is required to validate resources")
if errors and self.params['validate']['fail_on_error']:
self.fail_json(msg="\n".join(errors))
self.fail_json(msg="\n".join([_prepend_resource_info(resource, error) for error in errors]))
else:
return warnings + errors
return [_prepend_resource_info(resource, msg) for msg in warnings + errors]
def set_defaults(self, resource, definition):
definition['kind'] = resource.kind