Skip to content

Commit a6cfc31

Browse files
authored
Fix private cluster kubectl exit code bug (#252)
* add private cluster exitCode check * add proper output
1 parent e917b5a commit a6cfc31

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/types/privatekubectl.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export class PrivateKubectl extends Kubectl {
1010
args.unshift('kubectl')
1111
let kubectlCmd = args.join(' ')
1212
let addFileFlag = false
13-
let eo = <ExecOptions>{silent}
13+
let eo = <ExecOptions>{
14+
silent: true,
15+
failOnStdErr: false,
16+
ignoreReturnCode: true
17+
}
1418

1519
if (this.containsFilenames(kubectlCmd)) {
1620
// For private clusters, files will referenced solely by their basename
@@ -52,7 +56,25 @@ export class PrivateKubectl extends Kubectl {
5256
core.debug(
5357
`private cluster Kubectl run with invoke command: ${kubectlCmd}`
5458
)
55-
return await getExecOutput('az', privateClusterArgs, eo)
59+
60+
const runOutput = await getExecOutput(
61+
'az',
62+
[...privateClusterArgs, '-o', 'json'],
63+
eo
64+
)
65+
const runObj: {logs: string; exitCode: number} = JSON.parse(
66+
runOutput.stdout
67+
)
68+
if (!silent) core.info(runObj.logs)
69+
if (runOutput.exitCode !== 0 && runObj.exitCode !== 0) {
70+
throw Error(`failed private cluster Kubectl command: ${kubectlCmd}`)
71+
}
72+
73+
return {
74+
exitCode: runObj.exitCode,
75+
stdout: runObj.logs,
76+
stderr: ''
77+
} as ExecOutput
5678
}
5779

5880
private replaceFilnamesWithBasenames(kubectlCmd: string) {

0 commit comments

Comments
 (0)