|
1 | 1 | import { exec } from 'child-process-promise'; |
2 | | -import { chmodSync, writeFileSync, existsSync } from 'fs'; |
| 2 | +import { chmodSync, writeFileSync, existsSync, unlinkSync } from 'fs'; |
3 | 3 | import { platform } from 'os'; |
4 | 4 | import { resolve } from 'path'; |
5 | 5 | import * as needle from 'needle'; |
6 | 6 | import * as sleep from 'sleep-promise'; |
7 | 7 |
|
8 | | -export async function downloadKubectl(): Promise<void> { |
| 8 | +/** |
| 9 | + * @param version For example: "v1.18.0" |
| 10 | + */ |
| 11 | +export async function downloadKubectl(version: string): Promise<void> { |
9 | 12 | const kubectlPath = resolve(process.cwd(), 'kubectl'); |
10 | 13 | if (existsSync(kubectlPath)) { |
11 | | - return; |
| 14 | + if (version === 'latest') { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + // Always start clean when requesting a specific version. |
| 19 | + unlinkSync(kubectlPath); |
12 | 20 | } |
13 | 21 |
|
14 | | - console.log('Downloading kubectl...'); |
| 22 | + console.log(`Downloading kubectl ${version}...`); |
15 | 23 |
|
16 | 24 | // eslint-disable-next-line @typescript-eslint/camelcase |
17 | 25 | const requestOptions = { follow_max: 2 }; |
18 | | - const k8sRelease = await getLatestStableK8sRelease(); |
| 26 | + const k8sRelease = version === 'latest' ? await getLatestStableK8sRelease() : version; |
19 | 27 | const osDistro = platform(); |
20 | 28 | const bodyData = null; |
21 | 29 | await needle('get', 'https://storage.googleapis.com/kubernetes-release/release/' + |
|
0 commit comments