diff --git a/changelogs/fragments/20240620-fix-kustomize-plugin-fails-with-deprecation-warnings.yml b/changelogs/fragments/20240620-fix-kustomize-plugin-fails-with-deprecation-warnings.yml new file mode 100644 index 0000000000..2cb7bb60b8 --- /dev/null +++ b/changelogs/fragments/20240620-fix-kustomize-plugin-fails-with-deprecation-warnings.yml @@ -0,0 +1,2 @@ +bugfixes: + - kustomize - kustomize plugin fails with deprecation warnings (https://github.com/ansible-collections/kubernetes.core/issues/639). diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 88a039e676..c4e8473780 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -94,7 +94,8 @@ def get_binary_from_path(name, opt_dirs=None): def run_command(command): cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - return cmd.communicate() + stdout, stderr = cmd.communicate() + return cmd.returncode, stdout, stderr class LookupModule(LookupBase): @@ -140,9 +141,18 @@ def run( if enable_helm: command += ["--enable-helm"] - (out, err) = run_command(command) - if err: - raise AnsibleLookupError( - "kustomize command failed with: {0}".format(err.decode("utf-8")) - ) + (ret, out, err) = run_command(command) + if ret != 0: + if err: + raise AnsibleLookupError( + "kustomize command failed. exit code: {0}, error: {1}".format( + ret, err.decode("utf-8") + ) + ) + else: + raise AnsibleLookupError( + "kustomize command failed with unknown error. exit code: {0}".format( + ret + ) + ) return [out.decode("utf-8")]