mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-02 14:29:10 -07: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:
parent
48642dd1d7
commit
7d181802fb
1 changed files with 5 additions and 2 deletions
|
@ -156,15 +156,18 @@ class KubernetesRawModule(KubernetesAnsibleModule):
|
||||||
})
|
})
|
||||||
|
|
||||||
def validate(self, resource):
|
def validate(self, resource):
|
||||||
|
def _prepend_resource_info(resource, msg):
|
||||||
|
return "%s %s: %s" % (resource['kind'], resource['metadata']['name'], msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
warnings, errors = self.client.validate(resource, self.params['validate'].get('version'), self.params['validate'].get('strict'))
|
warnings, errors = self.client.validate(resource, self.params['validate'].get('version'), self.params['validate'].get('strict'))
|
||||||
except KubernetesValidateMissing:
|
except KubernetesValidateMissing:
|
||||||
self.fail_json(msg="kubernetes-validate python library is required to validate resources")
|
self.fail_json(msg="kubernetes-validate python library is required to validate resources")
|
||||||
|
|
||||||
if errors and self.params['validate']['fail_on_error']:
|
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:
|
else:
|
||||||
return warnings + errors
|
return [_prepend_resource_info(resource, msg) for msg in warnings + errors]
|
||||||
|
|
||||||
def set_defaults(self, resource, definition):
|
def set_defaults(self, resource, definition):
|
||||||
definition['kind'] = resource.kind
|
definition['kind'] = resource.kind
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue