in src/types/privatekubectl.ts [10:82]
protected async execute(args: string[], silent: boolean = false) {
args.unshift('kubectl')
let kubectlCmd = args.join(' ')
let addFileFlag = false
let eo = <ExecOptions>{
silent: true,
failOnStdErr: false,
ignoreReturnCode: true
}
if (this.containsFilenames(kubectlCmd)) {
kubectlCmd = replaceFileNamesWithShallowNamesRelativeToTemp(kubectlCmd)
addFileFlag = true
}
if (this.resourceGroup === '') {
throw Error('Resource group must be specified for private cluster')
}
if (this.name === '') {
throw Error('Cluster name must be specified for private cluster')
}
const privateClusterArgs = [
'aks',
'command',
'invoke',
'--resource-group',
this.resourceGroup,
'--name',
this.name,
'--command',
`${kubectlCmd}`
]
if (addFileFlag) {
const tempDirectory = getTempDirectory()
eo.cwd = path.join(tempDirectory, 'manifests')
privateClusterArgs.push(...['--file', '.'])
}
core.debug(
`private cluster Kubectl run with invoke command: ${kubectlCmd}`
)
const allArgs = [...privateClusterArgs, '-o', 'json']
core.debug(`full form of az command: az ${allArgs.join(' ')}`)
const runOutput = await getExecOutput('az', allArgs, eo)
core.debug(
`from kubectl private cluster command got run output ${JSON.stringify(
runOutput
)}`
)
if (runOutput.exitCode !== 0) {
throw Error(
`Call to private cluster failed. Command: '${kubectlCmd}', errormessage: ${runOutput.stderr}`
)
}
const runObj: {logs: string; exitCode: number} = JSON.parse(
runOutput.stdout
)
if (!silent) core.info(runObj.logs)
if (runObj.exitCode !== 0) {
throw Error(`failed private cluster Kubectl command: ${kubectlCmd}`)
}
return {
exitCode: runObj.exitCode,
stdout: runObj.logs,
stderr: ''
} as ExecOutput
}