Skip to content

Commit 47445fb

Browse files
authored
Add skip tls flag (#260)
1 parent c875a14 commit 47445fb

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ Following are the key capabilities of this action:
117117
<td>annotate-namespace</br></br>(Optional)</td>
118118
<td>Acceptable values: true/false</br>Default value: true</br>Switch whether to annotate the namespace resources object or not</td>
119119
</tr>
120+
<tr>
121+
<td>skip-tls-verify</br></br>(Optional)</td>
122+
<td>Acceptable values: true/false</br>Default value: false</br>True if the insecure-skip-tls-verify option should be used</td>
123+
</tr>
120124
</table>
121125

122126
## Usage Examples

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ inputs:
7373
name:
7474
description: 'Resource group name - Only required if using private cluster'
7575
required: false
76+
skip-tls-verify:
77+
description: True if the insecure-skip-tls-verify option should be used. Input should be 'true' or 'false'.
78+
default: false
7679

7780
branding:
7881
color: 'green'

src/run.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ export async function run() {
3535
core.getInput('private-cluster').toLowerCase() === 'true'
3636
const resourceGroup = core.getInput('resource-group') || ''
3737
const resourceName = core.getInput('name') || ''
38+
const skipTlsVerify = core.getBooleanInput('skip-tls-verify')
3839

3940
const kubectl = isPrivateCluster
4041
? new PrivateKubectl(
4142
kubectlPath,
4243
namespace,
43-
true,
44+
skipTlsVerify,
4445
resourceGroup,
4546
resourceName
4647
)
47-
: new Kubectl(kubectlPath, namespace, true)
48+
: new Kubectl(kubectlPath, namespace, skipTlsVerify)
4849

4950
// run action
5051
switch (action) {

src/types/kubectl.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,21 @@ describe('Kubectl class', () => {
353353
const result = await kubectl.getNewReplicaSet(deployment)
354354
expect(result).toBe(name)
355355
})
356+
357+
it('executes with constructor flags', async () => {
358+
const skipTls = true
359+
const kubectl = new Kubectl(kubectlPath, testNamespace, skipTls)
360+
361+
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
362+
return {exitCode: 0, stderr: '', stdout: ''}
363+
})
364+
365+
const command = 'command'
366+
kubectl.executeCommand(command)
367+
expect(exec.getExecOutput).toBeCalledWith(
368+
kubectlPath,
369+
[command, '--insecure-skip-tls-verify', '--namespace', testNamespace],
370+
{silent: false}
371+
)
372+
})
356373
})

src/types/kubectl.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,25 @@ export class Kubectl {
171171
}
172172

173173
protected async execute(args: string[], silent: boolean = false) {
174-
if (this.ignoreSSLErrors) {
175-
args.push('--insecure-skip-tls-verify')
176-
}
177-
if (this.namespace) {
178-
args = args.concat(['--namespace', this.namespace])
179-
}
174+
args = args.concat(this.getExecuteFlags())
180175
core.debug(`Kubectl run with command: ${this.kubectlPath} ${args}`)
181176

182177
return await getExecOutput(this.kubectlPath, args, {
183178
silent
184179
})
185180
}
181+
182+
protected getExecuteFlags(): string[] {
183+
const flags = []
184+
if (this.ignoreSSLErrors) {
185+
flags.push('--insecure-skip-tls-verify')
186+
}
187+
if (this.namespace) {
188+
flags.push('--namespace', this.namespace)
189+
}
190+
191+
return flags
192+
}
186193
}
187194

188195
export async function getKubectlPath() {

src/types/privatekubectl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import * as path from 'path'
88

99
export class PrivateKubectl extends Kubectl {
1010
protected async execute(args: string[], silent: boolean = false) {
11-
if (this.namespace) {
12-
args = args.concat(['--namespace', this.namespace])
13-
}
11+
args = args.concat(this.getExecuteFlags())
12+
1413
args.unshift('kubectl')
1514
let kubectlCmd = args.join(' ')
1615
let addFileFlag = false

0 commit comments

Comments
 (0)