@kubernetesjs/cli 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +54 -55
- package/commands/apply.d.ts +4 -0
- package/commands/apply.js +171 -0
- package/commands/cluster-info.d.ts +4 -0
- package/commands/cluster-info.js +26 -0
- package/commands/config-handler.d.ts +11 -0
- package/commands/config-handler.js +81 -0
- package/commands/config.d.ts +4 -0
- package/commands/config.js +72 -0
- package/commands/delete.d.ts +4 -0
- package/commands/delete.js +256 -0
- package/commands/deploy.d.ts +6 -0
- package/commands/deploy.js +209 -0
- package/commands/describe.d.ts +4 -0
- package/commands/describe.js +216 -0
- package/commands/exec.d.ts +4 -0
- package/commands/exec.js +145 -0
- package/commands/get.d.ts +4 -0
- package/commands/get.js +164 -0
- package/commands/logs.d.ts +4 -0
- package/commands/logs.js +110 -0
- package/commands/port-forward.d.ts +4 -0
- package/commands/port-forward.js +143 -0
- package/commands.d.ts +3 -0
- package/commands.js +93 -0
- package/config.d.ts +22 -0
- package/config.js +113 -0
- package/esm/commands/apply.js +133 -0
- package/esm/commands/cluster-info.js +21 -0
- package/esm/commands/config-handler.js +43 -0
- package/esm/commands/config.js +67 -0
- package/esm/commands/delete.js +218 -0
- package/esm/commands/deploy.js +207 -0
- package/esm/commands/describe.js +211 -0
- package/esm/commands/exec.js +140 -0
- package/esm/commands/get.js +159 -0
- package/esm/commands/logs.js +105 -0
- package/esm/commands/port-forward.js +138 -0
- package/esm/commands.js +86 -0
- package/esm/config.js +74 -0
- package/esm/index.js +19 -0
- package/esm/package.js +26 -0
- package/esm/utils.js +49 -0
- package/index.d.ts +3 -0
- package/index.js +22 -0
- package/package.d.ts +1 -0
- package/package.js +29 -0
- package/package.json +37 -61
- package/utils.d.ts +11 -0
- package/utils.js +58 -0
- package/main/client.js +0 -156
- package/main/index.js +0 -2598
- package/module/client.js +0 -129
- package/module/index.js +0 -2594
- package/src/client.ts +0 -156
- package/src/index.ts +0 -14187
- package/types/client.d.ts +0 -31
- package/types/index.d.ts +0 -11331
package/package.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readAndParsePackageJson = readAndParsePackageJson;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
// need to search due to the dist/ folder and src/, etc.
|
|
7
|
+
function findPackageJson(currentDir) {
|
|
8
|
+
const filePath = (0, path_1.join)(currentDir, 'package.json');
|
|
9
|
+
// Check if package.json exists in the current directory
|
|
10
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
11
|
+
return filePath;
|
|
12
|
+
}
|
|
13
|
+
// Get the parent directory
|
|
14
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
|
15
|
+
// If reached the root directory, package.json is not found
|
|
16
|
+
if (parentDir === currentDir) {
|
|
17
|
+
throw new Error('package.json not found in any parent directory');
|
|
18
|
+
}
|
|
19
|
+
// Recursively look in the parent directory
|
|
20
|
+
return findPackageJson(parentDir);
|
|
21
|
+
}
|
|
22
|
+
function readAndParsePackageJson() {
|
|
23
|
+
// Start searching from the current directory
|
|
24
|
+
const pkgPath = findPackageJson(__dirname);
|
|
25
|
+
// Read and parse the package.json
|
|
26
|
+
const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
|
|
27
|
+
const pkg = JSON.parse(str);
|
|
28
|
+
return pkg;
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,73 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubernetesjs/cli",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Fully Typed Kubernetes",
|
|
3
|
+
"version": "0.1.0",
|
|
5
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
|
-
"
|
|
5
|
+
"description": "KubernetesJS CLI",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/hyperweb-io/kubernetes",
|
|
7
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
8
|
-
"main": "main/index.js",
|
|
9
|
-
"module": "module/index.js",
|
|
10
|
-
"typings": "types/index.d.ts",
|
|
11
|
-
"directories": {
|
|
12
|
-
"lib": "src",
|
|
13
|
-
"test": "__tests__"
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"types",
|
|
17
|
-
"module",
|
|
18
|
-
"src",
|
|
19
|
-
"main"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build:main": "yarn tsc -p tsconfig.json --outDir main --module commonjs",
|
|
23
|
-
"build:module": "yarn tsc -p tsconfig.json --outDir module --module es2022",
|
|
24
|
-
"build": "npm run build:module && npm run build:main",
|
|
25
|
-
"clean": "rimraf ./types && rimraf ./main && rimraf ./module",
|
|
26
|
-
"prepare": "npm run clean && npm run build",
|
|
27
|
-
"lint": "eslint .",
|
|
28
|
-
"format": "eslint . --fix",
|
|
29
|
-
"test": "jest",
|
|
30
|
-
"test:watch": "jest --watch",
|
|
31
|
-
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
|
|
32
|
-
},
|
|
33
|
-
"jest": {
|
|
34
|
-
"preset": "ts-jest",
|
|
35
|
-
"testEnvironment": "node",
|
|
36
|
-
"transform": {
|
|
37
|
-
"^.+\\.ts?$": "ts-jest"
|
|
38
|
-
},
|
|
39
|
-
"transformIgnorePatterns": [
|
|
40
|
-
"<rootDir>/node_modules/"
|
|
41
|
-
],
|
|
42
|
-
"testPathIgnorePatterns": [
|
|
43
|
-
"main/",
|
|
44
|
-
"module/",
|
|
45
|
-
"types/"
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
11
|
"publishConfig": {
|
|
49
|
-
"access": "public"
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
50
14
|
},
|
|
51
15
|
"repository": {
|
|
52
16
|
"type": "git",
|
|
53
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/hyperweb-io/kubernetes"
|
|
54
18
|
},
|
|
55
|
-
"keywords": [],
|
|
56
19
|
"bugs": {
|
|
57
|
-
"url": "https://github.com/
|
|
20
|
+
"url": "https://github.com/hyperweb-io/kubernetes/issues"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"k8s": "index.js",
|
|
24
|
+
"kubernetes": "index.js"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
|
|
28
|
+
"clean": "rimraf dist/**",
|
|
29
|
+
"prepare": "npm run build",
|
|
30
|
+
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
|
|
31
|
+
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
|
|
32
|
+
"lint": "eslint . --fix",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"test:watch": "jest --watch",
|
|
35
|
+
"dev": "ts-node src/index.ts"
|
|
58
36
|
},
|
|
59
37
|
"devDependencies": {
|
|
60
|
-
"@types/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
}
|
|
38
|
+
"@types/js-yaml": "^4.0.9"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"chalk": "^4.1.0",
|
|
42
|
+
"deepmerge": "^4.3.1",
|
|
43
|
+
"inquirerer": "^2.0.8",
|
|
44
|
+
"js-yaml": "^4.1.0",
|
|
45
|
+
"kubernetesjs": "^0.5.1",
|
|
46
|
+
"minimist": "^1.2.8"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "26b897ec6d8fbb4c1b940e699ea22ce87bd463e7"
|
|
49
|
+
}
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ParsedArgs } from 'minimist';
|
|
2
|
+
export declare const extractFirst: (argv: Partial<ParsedArgs>) => {
|
|
3
|
+
first: string;
|
|
4
|
+
newArgv: {
|
|
5
|
+
_: string[];
|
|
6
|
+
"--"?: string[] | undefined;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare function displayVersion(): void;
|
|
10
|
+
export declare const usageText = "\n Usage: k8s <command> [options]\n \n Commands:\n get [resource] List resources (pods, services, deployments, etc.)\n describe [resource] Show detailed information about a specific resource\n logs [pod] Display logs from a container in a pod\n exec [pod] -- [cmd] Execute a command in a container\n apply -f [file] Apply a configuration to a resource by file name\n delete [resource] Delete resources\n port-forward [svc] Forward one or more local ports to a pod\n cluster-info Display cluster information\n config Modify kubeconfig files\n deploy Deploy a container to Kubernetes\n version, -v Display the version of the CLI\n \n Configuration File:\n --config <path> Specify the path to a YAML configuration file.\n Command-line options will override settings from this file if both are provided.\n \n Namespace:\n -n, --namespace Specify the namespace to use. Default is from local config or \"default\".\n \n Additional Options:\n -c, --clientUrl <url> Specify the Kubernetes API endpoint URL.\n Default is http://127.0.0.1:8001 (kubectl proxy)\n \n Additional Help:\n $ k8s help Display this help information.\n ";
|
|
11
|
+
export declare function displayUsage(): void;
|
package/utils.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.usageText = exports.extractFirst = void 0;
|
|
7
|
+
exports.displayVersion = displayVersion;
|
|
8
|
+
exports.displayUsage = displayUsage;
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const package_1 = require("./package");
|
|
11
|
+
const extractFirst = (argv) => {
|
|
12
|
+
const first = argv._?.[0];
|
|
13
|
+
const newArgv = {
|
|
14
|
+
...argv,
|
|
15
|
+
_: argv._?.slice(1) ?? []
|
|
16
|
+
};
|
|
17
|
+
return { first, newArgv };
|
|
18
|
+
};
|
|
19
|
+
exports.extractFirst = extractFirst;
|
|
20
|
+
// Function to display the version information
|
|
21
|
+
function displayVersion() {
|
|
22
|
+
const pkg = (0, package_1.readAndParsePackageJson)();
|
|
23
|
+
console.log(chalk_1.default.green(`Name: ${pkg.name}`));
|
|
24
|
+
console.log(chalk_1.default.blue(`Version: ${pkg.version}`));
|
|
25
|
+
}
|
|
26
|
+
exports.usageText = `
|
|
27
|
+
Usage: k8s <command> [options]
|
|
28
|
+
|
|
29
|
+
Commands:
|
|
30
|
+
get [resource] List resources (pods, services, deployments, etc.)
|
|
31
|
+
describe [resource] Show detailed information about a specific resource
|
|
32
|
+
logs [pod] Display logs from a container in a pod
|
|
33
|
+
exec [pod] -- [cmd] Execute a command in a container
|
|
34
|
+
apply -f [file] Apply a configuration to a resource by file name
|
|
35
|
+
delete [resource] Delete resources
|
|
36
|
+
port-forward [svc] Forward one or more local ports to a pod
|
|
37
|
+
cluster-info Display cluster information
|
|
38
|
+
config Modify kubeconfig files
|
|
39
|
+
deploy Deploy a container to Kubernetes
|
|
40
|
+
version, -v Display the version of the CLI
|
|
41
|
+
|
|
42
|
+
Configuration File:
|
|
43
|
+
--config <path> Specify the path to a YAML configuration file.
|
|
44
|
+
Command-line options will override settings from this file if both are provided.
|
|
45
|
+
|
|
46
|
+
Namespace:
|
|
47
|
+
-n, --namespace Specify the namespace to use. Default is from local config or "default".
|
|
48
|
+
|
|
49
|
+
Additional Options:
|
|
50
|
+
-c, --clientUrl <url> Specify the Kubernetes API endpoint URL.
|
|
51
|
+
Default is http://127.0.0.1:8001 (kubectl proxy)
|
|
52
|
+
|
|
53
|
+
Additional Help:
|
|
54
|
+
$ k8s help Display this help information.
|
|
55
|
+
`;
|
|
56
|
+
function displayUsage() {
|
|
57
|
+
console.log(exports.usageText);
|
|
58
|
+
}
|
package/main/client.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.APIClient = void 0;
|
|
27
|
-
const http = __importStar(require("http"));
|
|
28
|
-
const querystring = __importStar(require("querystring"));
|
|
29
|
-
const url_1 = require("url");
|
|
30
|
-
class APIClient {
|
|
31
|
-
hostname;
|
|
32
|
-
port = 8001; // Default Kubernetes proxy port
|
|
33
|
-
defaultTimeout = 10000; // 10 seconds
|
|
34
|
-
constructor(options) {
|
|
35
|
-
const url = new URL(options.restEndpoint);
|
|
36
|
-
this.hostname = url.hostname;
|
|
37
|
-
this.port = url.port ? parseInt(url.port) : this.port;
|
|
38
|
-
}
|
|
39
|
-
get(endpoint, query, opts = {}) {
|
|
40
|
-
const queryString = query ? `?${querystring.stringify(query)}` : '';
|
|
41
|
-
const fullPath = endpoint + queryString;
|
|
42
|
-
return this.request({
|
|
43
|
-
path: fullPath,
|
|
44
|
-
method: 'GET',
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
headers: opts.headers,
|
|
47
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
post(endpoint, params, opts = {}) {
|
|
51
|
-
const headers = opts.isFormData ? {
|
|
52
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
53
|
-
...opts.headers
|
|
54
|
-
} : {
|
|
55
|
-
'Content-Type': 'application/json',
|
|
56
|
-
...opts.headers
|
|
57
|
-
};
|
|
58
|
-
const body = opts.isFormData ? new url_1.URLSearchParams(params).toString() : JSON.stringify(params);
|
|
59
|
-
headers['Content-Length'] = Buffer.byteLength(body).toString();
|
|
60
|
-
return this.request({
|
|
61
|
-
path: endpoint,
|
|
62
|
-
method: 'POST',
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
headers,
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
params: body,
|
|
67
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
patch(endpoint, params, opts = {}) {
|
|
71
|
-
const headers = opts.isFormData ? {
|
|
72
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
73
|
-
...opts.headers
|
|
74
|
-
} : {
|
|
75
|
-
'Content-Type': 'application/json',
|
|
76
|
-
...opts.headers
|
|
77
|
-
};
|
|
78
|
-
const body = opts.isFormData ? new url_1.URLSearchParams(params).toString() : JSON.stringify(params);
|
|
79
|
-
headers['Content-Length'] = Buffer.byteLength(body).toString();
|
|
80
|
-
return this.request({
|
|
81
|
-
path: endpoint,
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
method: 'PATCH',
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
headers,
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
params: body,
|
|
88
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
put(endpoint, params, opts = {}) {
|
|
92
|
-
const stringParams = JSON.stringify(params);
|
|
93
|
-
const defaultHeaders = {
|
|
94
|
-
'Content-Type': 'application/json',
|
|
95
|
-
'Content-Length': Buffer.byteLength(stringParams).toString(),
|
|
96
|
-
...opts.headers
|
|
97
|
-
};
|
|
98
|
-
return this.request({
|
|
99
|
-
path: endpoint,
|
|
100
|
-
method: 'PUT',
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
headers: defaultHeaders,
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
params: stringParams,
|
|
105
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
delete(endpoint, opts = {}) {
|
|
109
|
-
return this.request({
|
|
110
|
-
path: endpoint,
|
|
111
|
-
method: 'DELETE',
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
headers: opts.headers,
|
|
114
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
request(options) {
|
|
118
|
-
return new Promise((resolve, reject) => {
|
|
119
|
-
const requestOptions = {
|
|
120
|
-
hostname: this.hostname,
|
|
121
|
-
port: this.port,
|
|
122
|
-
path: options.path,
|
|
123
|
-
method: options.method,
|
|
124
|
-
headers: options.headers,
|
|
125
|
-
};
|
|
126
|
-
const req = http.request(requestOptions, res => {
|
|
127
|
-
let data = '';
|
|
128
|
-
res.on('data', chunk => {
|
|
129
|
-
data += chunk;
|
|
130
|
-
});
|
|
131
|
-
res.on('end', () => {
|
|
132
|
-
try {
|
|
133
|
-
const parsedData = JSON.parse(data);
|
|
134
|
-
resolve(parsedData);
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
reject(error);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
req.on('error', error => {
|
|
142
|
-
reject(error);
|
|
143
|
-
});
|
|
144
|
-
// @ts-ignore
|
|
145
|
-
req.setTimeout(options.timeout, () => {
|
|
146
|
-
req.abort();
|
|
147
|
-
reject(new Error('Request timeout'));
|
|
148
|
-
});
|
|
149
|
-
if (options.params && (options.method === 'POST' || options.method === 'PUT')) {
|
|
150
|
-
req.write(options.params);
|
|
151
|
-
}
|
|
152
|
-
req.end();
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.APIClient = APIClient;
|