Repository navigation
Expand file tree
/
Copy pathkubectl.ts
More file actions
52 lines (43 loc) · 1.63 KB
/
Copy pathkubectl.ts
File metadata and controls
52 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
@injectable()
@injectFromHierarchy()
export class KubectlInstallService extends BaseInstallService {
readonly name = 'kubectl';
/**
* Downloads the kubectl binary from dl.k8s.io, verified against its
* `.sha256`, into the versioned `bin` folder.
*/
override async install(version: string): Promise<void> {
const baseUrl = `https://dl.k8s.io/release/v${version}/bin/linux/${this.envSvc.arch}/`;
const filename = this.name;
const expectedChecksum = await this.getChecksum(
`${baseUrl}${filename}.sha256`,
);
const file = await this.http.download({
url: `${baseUrl}${filename}`,
fileName: `${filename}-v${version}-${this.envSvc.arch}`,
checksumType: 'sha256',
expectedChecksum,
});
await this.pathSvc.ensureToolPath(this.name);
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.copyFile(file, join(path, filename));
await fs.chmod(join(path, filename), this.envSvc.umask);
}
/** Links the `kubectl` binary into the global bin folder. */
override async link(version: string): Promise<void> {
const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin');
await this.shellwrapper({ srcDir: src });
}
/** Checks that `kubectl version --client` runs. */
override async test(_version: string): Promise<void> {
await this._spawn(this.name, ['version', '--client']);
}
}