Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix private cluster kubectl exit code bug #252

Merged
merged 3 commits into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/types/privatekubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export class PrivateKubectl extends Kubectl {
args.unshift('kubectl')
let kubectlCmd = args.join(' ')
let addFileFlag = false
let eo = <ExecOptions>{silent}
let eo = <ExecOptions>{
silent: true,
failOnStdErr: false,
ignoreReturnCode: true
}

if (this.containsFilenames(kubectlCmd)) {
// For private clusters, files will referenced solely by their basename
Expand Down Expand Up @@ -52,7 +56,25 @@ export class PrivateKubectl extends Kubectl {
core.debug(
`private cluster Kubectl run with invoke command: ${kubectlCmd}`
)
return await getExecOutput('az', privateClusterArgs, eo)

const runOutput = await getExecOutput(
'az',
[...privateClusterArgs, '-o', 'json'],
eo
)
const runObj: {logs: string; exitCode: number} = JSON.parse(
runOutput.stdout
)
if (!silent) core.info(runObj.logs)
if (runOutput.exitCode !== 0 && runObj.exitCode !== 0) {
throw Error(`failed private cluster Kubectl command: ${kubectlCmd}`)
}

return {
exitCode: runObj.exitCode,
stdout: runObj.logs,
stderr: ''
} as ExecOutput
}

private replaceFilnamesWithBasenames(kubectlCmd: string) {
Expand Down