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.
pull/51657/head
Will Thames 6 years ago committed by René Moser
parent 48642dd1d7
commit 7d181802fb

@ -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

Loading…
Cancel
Save