Skip to content

Commit 00bbf16

Browse files
fix: kustomize plugin fails with deprecation warnings (#728) (#763)
This is a backport of PR #728 as merged into main (5bc53db). SUMMARY error judgments are based on the exit codes of command execution, where 0 represents success and non-zero represents failure. Optimize the run_command function to return a tuple like the run_command method of AnsibleModule. Fixes #639 ISSUE TYPE Bugfix Pull Request COMPONENT NAME kustomize lookup plugin ADDITIONAL INFORMATION Reviewed-by: Mike Graves <[email protected]>
1 parent 31fd405 commit 00bbf16

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- kustomize - kustomize plugin fails with deprecation warnings (https://github.com/ansible-collections/kubernetes.core/issues/639).

plugins/lookup/kustomize.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def get_binary_from_path(name, opt_dirs=None):
9494

9595
def run_command(command):
9696
cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
97-
return cmd.communicate()
97+
stdout, stderr = cmd.communicate()
98+
return cmd.returncode, stdout, stderr
9899

99100

100101
class LookupModule(LookupBase):
@@ -140,9 +141,18 @@ def run(
140141
if enable_helm:
141142
command += ["--enable-helm"]
142143

143-
(out, err) = run_command(command)
144-
if err:
145-
raise AnsibleLookupError(
146-
"kustomize command failed with: {0}".format(err.decode("utf-8"))
147-
)
144+
(ret, out, err) = run_command(command)
145+
if ret != 0:
146+
if err:
147+
raise AnsibleLookupError(
148+
"kustomize command failed. exit code: {0}, error: {1}".format(
149+
ret, err.decode("utf-8")
150+
)
151+
)
152+
else:
153+
raise AnsibleLookupError(
154+
"kustomize command failed with unknown error. exit code: {0}".format(
155+
ret
156+
)
157+
)
148158
return [out.decode("utf-8")]

0 commit comments

Comments
 (0)