Add skip tls flag (#260)

This commit is contained in:
Oliver King
2022-11-23 12:59:45 -05:00
committed by GitHub
parent c875a14bde
commit 47445fb82f
6 changed files with 42 additions and 11 deletions
+17
View File
@@ -353,4 +353,21 @@ describe('Kubectl class', () => {
const result = await kubectl.getNewReplicaSet(deployment)
expect(result).toBe(name)
})
it('executes with constructor flags', async () => {
const skipTls = true
const kubectl = new Kubectl(kubectlPath, testNamespace, skipTls)
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
return {exitCode: 0, stderr: '', stdout: ''}
})
const command = 'command'
kubectl.executeCommand(command)
expect(exec.getExecOutput).toBeCalledWith(
kubectlPath,
[command, '--insecure-skip-tls-verify', '--namespace', testNamespace],
{silent: false}
)
})
})
+13 -6
View File
@@ -171,18 +171,25 @@ export class Kubectl {
}
protected async execute(args: string[], silent: boolean = false) {
if (this.ignoreSSLErrors) {
args.push('--insecure-skip-tls-verify')
}
if (this.namespace) {
args = args.concat(['--namespace', this.namespace])
}
args = args.concat(this.getExecuteFlags())
core.debug(`Kubectl run with command: ${this.kubectlPath} ${args}`)
return await getExecOutput(this.kubectlPath, args, {
silent
})
}
protected getExecuteFlags(): string[] {
const flags = []
if (this.ignoreSSLErrors) {
flags.push('--insecure-skip-tls-verify')
}
if (this.namespace) {
flags.push('--namespace', this.namespace)
}
return flags
}
}
export async function getKubectlPath() {
+2 -3
View File
@@ -8,9 +8,8 @@ import * as path from 'path'
export class PrivateKubectl extends Kubectl {
protected async execute(args: string[], silent: boolean = false) {
if (this.namespace) {
args = args.concat(['--namespace', this.namespace])
}
args = args.concat(this.getExecuteFlags())
args.unshift('kubectl')
let kubectlCmd = args.join(' ')
let addFileFlag = false