@kubernetesjs/cli 0.3.4 → 0.3.6
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/README.md +8 -9
- package/commands/apply.js +15 -15
- package/commands/cluster-info.js +4 -4
- package/commands/config-handler.js +5 -5
- package/commands/config.js +8 -8
- package/commands/delete.js +16 -16
- package/commands/describe.js +39 -39
- package/commands/exec.js +7 -7
- package/commands/get.js +20 -20
- package/commands/logs.js +7 -7
- package/commands/port-forward.js +8 -8
- package/esm/commands/apply.js +15 -15
- package/esm/commands/cluster-info.js +4 -4
- package/esm/commands/config-handler.js +5 -5
- package/esm/commands/config.js +8 -8
- package/esm/commands/delete.js +16 -16
- package/esm/commands/describe.js +39 -39
- package/esm/commands/exec.js +7 -7
- package/esm/commands/get.js +20 -20
- package/esm/commands/logs.js +7 -7
- package/esm/commands/port-forward.js +8 -8
- package/esm/utils.js +3 -3
- package/package.json +17 -16
- package/utils.js +3 -3
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# @kubernetesjs/cli
|
|
2
2
|
|
|
3
3
|
<p align="center" width="100%">
|
|
4
|
-
<img src="https://
|
|
4
|
+
<img src="https://raw.githubusercontent.com/constructive-io/.github/refs/heads/main/assets/logo.svg" alt="constructive" width="80"><br />
|
|
5
5
|
<br/>
|
|
6
6
|
TypeScript CLI for Kubernetes
|
|
7
7
|
<br />
|
|
8
|
-
<a href="https://github.com/
|
|
9
|
-
<img height="20" src="https://github.com/
|
|
8
|
+
<a href="https://github.com/constructive-io/kubernetesjs/actions/workflows/ci.yml">
|
|
9
|
+
<img height="20" src="https://github.com/constructive-io/kubernetesjs/actions/workflows/ci.yml/badge.svg"/>
|
|
10
10
|
</a>
|
|
11
|
-
<a href="https://github.com/
|
|
11
|
+
<a href="https://github.com/constructive-io/kubernetesjs/blob/main/LICENSE">
|
|
12
12
|
<img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
13
13
|
</a>
|
|
14
14
|
</p>
|
|
@@ -152,17 +152,16 @@ yarn build:dev
|
|
|
152
152
|
|
|
153
153
|
Checkout these related projects:
|
|
154
154
|
|
|
155
|
-
* [`schema-typescript`](https://github.com/
|
|
155
|
+
* [`schema-typescript`](https://github.com/constructive-io/dev-utils/tree/main/packages/schema-typescript)
|
|
156
156
|
Provides robust tools for handling JSON schemas and converting them to TypeScript interfaces with ease and efficiency.
|
|
157
|
-
* [`@schema-typescript/cli`](https://github.com/
|
|
157
|
+
* [`@schema-typescript/cli`](https://github.com/constructive-io/dev-utils/tree/main/packages/cli)
|
|
158
158
|
CLI is the command line utility for `schema-typescript`.
|
|
159
|
-
* [`schema-sdk`](https://github.com/
|
|
159
|
+
* [`schema-sdk`](https://github.com/constructive-io/dev-utils/tree/main/packages/schema-sdk)
|
|
160
160
|
Provides robust tools for handling OpenAPI schemas and converting them to TypeScript clients with ease and efficiency.
|
|
161
|
-
* [`starship`](https://github.com/hyperweb-io/starship) Unified Testing and Development for the Interchain.
|
|
162
161
|
|
|
163
162
|
## Credits
|
|
164
163
|
|
|
165
|
-
|
|
164
|
+
**🛠Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
166
165
|
|
|
167
166
|
## Disclaimer
|
|
168
167
|
|
package/commands/apply.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const
|
|
39
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const kubernetesjs_1 = require("kubernetesjs");
|
|
42
42
|
const config_1 = require("../config");
|
|
@@ -56,7 +56,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
56
56
|
if (!name) {
|
|
57
57
|
throw new Error('Resource must have a name');
|
|
58
58
|
}
|
|
59
|
-
console.log(
|
|
59
|
+
console.log(yanse_1.default.blue(`Applying ${kind} "${name}" in namespace ${namespace}...`));
|
|
60
60
|
try {
|
|
61
61
|
switch (kind) {
|
|
62
62
|
case 'deployment':
|
|
@@ -68,7 +68,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
68
68
|
},
|
|
69
69
|
body: resource
|
|
70
70
|
});
|
|
71
|
-
console.log(
|
|
71
|
+
console.log(yanse_1.default.green(`Deployment "${name}" created/updated successfully`));
|
|
72
72
|
break;
|
|
73
73
|
case 'service':
|
|
74
74
|
await client.createCoreV1NamespacedService({
|
|
@@ -79,7 +79,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
79
79
|
},
|
|
80
80
|
body: resource
|
|
81
81
|
});
|
|
82
|
-
console.log(
|
|
82
|
+
console.log(yanse_1.default.green(`Service "${name}" created/updated successfully`));
|
|
83
83
|
break;
|
|
84
84
|
case 'pod':
|
|
85
85
|
await client.createCoreV1NamespacedPod({
|
|
@@ -90,7 +90,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
90
90
|
},
|
|
91
91
|
body: resource
|
|
92
92
|
});
|
|
93
|
-
console.log(
|
|
93
|
+
console.log(yanse_1.default.green(`Pod "${name}" created/updated successfully`));
|
|
94
94
|
break;
|
|
95
95
|
case 'configmap':
|
|
96
96
|
await client.createCoreV1NamespacedConfigMap({
|
|
@@ -101,7 +101,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
101
101
|
},
|
|
102
102
|
body: resource
|
|
103
103
|
});
|
|
104
|
-
console.log(
|
|
104
|
+
console.log(yanse_1.default.green(`ConfigMap "${name}" created/updated successfully`));
|
|
105
105
|
break;
|
|
106
106
|
case 'secret':
|
|
107
107
|
await client.createCoreV1NamespacedSecret({
|
|
@@ -112,14 +112,14 @@ async function applyResource(client, resource, namespace) {
|
|
|
112
112
|
},
|
|
113
113
|
body: resource
|
|
114
114
|
});
|
|
115
|
-
console.log(
|
|
115
|
+
console.log(yanse_1.default.green(`Secret "${name}" created/updated successfully`));
|
|
116
116
|
break;
|
|
117
117
|
default:
|
|
118
|
-
console.log(
|
|
118
|
+
console.log(yanse_1.default.yellow(`Resource kind "${kind}" not implemented yet`));
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
catch (error) {
|
|
122
|
-
console.error(
|
|
122
|
+
console.error(yanse_1.default.red(`Error applying ${kind} "${name}": ${error}`));
|
|
123
123
|
throw error;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -130,11 +130,11 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
130
130
|
});
|
|
131
131
|
const filePath = argv.f || argv._?.[0] || await promptYamlFilePath(prompter, argv);
|
|
132
132
|
if (!filePath) {
|
|
133
|
-
console.error(
|
|
133
|
+
console.error(yanse_1.default.red('No file path provided'));
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
136
|
if (!fs.existsSync(filePath)) {
|
|
137
|
-
console.error(
|
|
137
|
+
console.error(yanse_1.default.red(`File not found: ${filePath}`));
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
140
|
let resources;
|
|
@@ -151,7 +151,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
catch (error) {
|
|
154
|
-
console.error(
|
|
154
|
+
console.error(yanse_1.default.red(`Error parsing YAML file: ${error}`));
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
for (const resource of resources) {
|
|
@@ -160,12 +160,12 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
160
160
|
await applyResource(client, resource, namespace);
|
|
161
161
|
}
|
|
162
162
|
catch (error) {
|
|
163
|
-
console.error(
|
|
163
|
+
console.error(yanse_1.default.red(`Failed to apply resource: ${error}`));
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
console.log(
|
|
166
|
+
console.log(yanse_1.default.green('Apply completed'));
|
|
167
167
|
}
|
|
168
168
|
catch (error) {
|
|
169
|
-
console.error(
|
|
169
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
170
170
|
}
|
|
171
171
|
};
|
package/commands/cluster-info.js
CHANGED
|
@@ -3,24 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
7
7
|
const kubernetesjs_1 = require("kubernetesjs");
|
|
8
8
|
exports.default = async (_argv, _prompter, _options) => {
|
|
9
9
|
try {
|
|
10
10
|
const client = new kubernetesjs_1.KubernetesClient({
|
|
11
11
|
restEndpoint: _argv.clientUrl
|
|
12
12
|
});
|
|
13
|
-
console.log(
|
|
13
|
+
console.log(yanse_1.default.blue('Kubernetes cluster info:'));
|
|
14
14
|
const apiVersions = await client.getAPIVersions({
|
|
15
15
|
params: {},
|
|
16
16
|
query: {}
|
|
17
17
|
});
|
|
18
|
-
console.log(
|
|
18
|
+
console.log(yanse_1.default.bold('\nAPI Versions:'));
|
|
19
19
|
if (apiVersions.apiVersion) {
|
|
20
20
|
console.log(apiVersions.apiVersion);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
|
-
console.error(
|
|
24
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
25
25
|
}
|
|
26
26
|
};
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const
|
|
39
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const config_1 = require("../config");
|
|
42
42
|
/**
|
|
@@ -52,13 +52,13 @@ exports.default = async (argv, prompter, options, commandMap) => {
|
|
|
52
52
|
}
|
|
53
53
|
const configPath = argv.config;
|
|
54
54
|
if (!fs.existsSync(configPath)) {
|
|
55
|
-
console.error(
|
|
55
|
+
console.error(yanse_1.default.red(`Config file not found: ${configPath}`));
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
try {
|
|
59
59
|
const resource = (0, config_1.readYamlFile)(configPath);
|
|
60
60
|
const resourceType = (0, config_1.inferResourceType)(resource);
|
|
61
|
-
console.log(
|
|
61
|
+
console.log(yanse_1.default.blue(`Detected resource type: ${resourceType}`));
|
|
62
62
|
let command;
|
|
63
63
|
command = 'apply';
|
|
64
64
|
const newArgv = {
|
|
@@ -70,12 +70,12 @@ exports.default = async (argv, prompter, options, commandMap) => {
|
|
|
70
70
|
await commandMap[command](newArgv, prompter, options);
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
|
-
console.error(
|
|
73
|
+
console.error(yanse_1.default.red(`No command found for resource type: ${resourceType}`));
|
|
74
74
|
}
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
77
|
catch (error) {
|
|
78
|
-
console.error(
|
|
78
|
+
console.error(yanse_1.default.red(`Error processing config file: ${error}`));
|
|
79
79
|
return true;
|
|
80
80
|
}
|
|
81
81
|
};
|
package/commands/config.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
7
7
|
const kubernetesjs_1 = require("kubernetesjs");
|
|
8
8
|
const config_1 = require("../config");
|
|
9
9
|
async function promptNamespace(prompter, argv, client) {
|
|
@@ -12,7 +12,7 @@ async function promptNamespace(prompter, argv, client) {
|
|
|
12
12
|
query: {}
|
|
13
13
|
});
|
|
14
14
|
if (!namespaces.items || namespaces.items.length === 0) {
|
|
15
|
-
console.log(
|
|
15
|
+
console.log(yanse_1.default.yellow('No namespaces found'));
|
|
16
16
|
return '';
|
|
17
17
|
}
|
|
18
18
|
const options = namespaces.items.map(ns => ({
|
|
@@ -31,7 +31,7 @@ async function promptNamespace(prompter, argv, client) {
|
|
|
31
31
|
return namespace;
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
console.error(
|
|
34
|
+
console.error(yanse_1.default.red(`Error getting namespaces: ${error}`));
|
|
35
35
|
return '';
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -43,12 +43,12 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
43
43
|
const subcommand = argv._?.[0];
|
|
44
44
|
if (subcommand === 'get-context') {
|
|
45
45
|
const namespace = (0, config_1.getCurrentNamespace)();
|
|
46
|
-
console.log(
|
|
46
|
+
console.log(yanse_1.default.green(`Current namespace: ${namespace}`));
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
if (subcommand === 'set-context') {
|
|
50
50
|
if (argv.current !== true) {
|
|
51
|
-
console.error(
|
|
51
|
+
console.error(yanse_1.default.red('Missing --current flag'));
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
let namespace = argv.namespace;
|
|
@@ -59,14 +59,14 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
(0, config_1.setCurrentNamespace)(namespace);
|
|
62
|
-
console.log(
|
|
62
|
+
console.log(yanse_1.default.green(`Namespace set to "${namespace}"`));
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
console.log(
|
|
65
|
+
console.log(yanse_1.default.blue('Available config commands:'));
|
|
66
66
|
console.log(' get-context Display the current context');
|
|
67
67
|
console.log(' set-context --current --namespace=<namespace> Set the current namespace');
|
|
68
68
|
}
|
|
69
69
|
catch (error) {
|
|
70
|
-
console.error(
|
|
70
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
71
71
|
}
|
|
72
72
|
};
|
package/commands/delete.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const
|
|
39
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const kubernetesjs_1 = require("kubernetesjs");
|
|
42
42
|
const config_1 = require("../config");
|
|
@@ -101,11 +101,11 @@ async function promptResourceSelection(prompter, argv, resourceType, namespace,
|
|
|
101
101
|
resources = secrets.items || [];
|
|
102
102
|
break;
|
|
103
103
|
default:
|
|
104
|
-
console.log(
|
|
104
|
+
console.log(yanse_1.default.yellow(`Resource type '${resourceType}' not implemented yet for selection`));
|
|
105
105
|
return [];
|
|
106
106
|
}
|
|
107
107
|
if (resources.length === 0) {
|
|
108
|
-
console.log(
|
|
108
|
+
console.log(yanse_1.default.yellow(`No ${resourceType}s found in namespace ${namespace}`));
|
|
109
109
|
return [];
|
|
110
110
|
}
|
|
111
111
|
const options = resources.map(r => ({
|
|
@@ -137,7 +137,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
137
137
|
},
|
|
138
138
|
query: {}
|
|
139
139
|
});
|
|
140
|
-
console.log(
|
|
140
|
+
console.log(yanse_1.default.green(`Pod "${resourceName}" deleted successfully`));
|
|
141
141
|
break;
|
|
142
142
|
case 'service':
|
|
143
143
|
await client.deleteCoreV1NamespacedService({
|
|
@@ -147,7 +147,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
147
147
|
},
|
|
148
148
|
query: {}
|
|
149
149
|
});
|
|
150
|
-
console.log(
|
|
150
|
+
console.log(yanse_1.default.green(`Service "${resourceName}" deleted successfully`));
|
|
151
151
|
break;
|
|
152
152
|
case 'deployment':
|
|
153
153
|
await client.deleteAppsV1NamespacedDeployment({
|
|
@@ -157,7 +157,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
157
157
|
},
|
|
158
158
|
query: {}
|
|
159
159
|
});
|
|
160
|
-
console.log(
|
|
160
|
+
console.log(yanse_1.default.green(`Deployment "${resourceName}" deleted successfully`));
|
|
161
161
|
break;
|
|
162
162
|
case 'configmap':
|
|
163
163
|
await client.deleteCoreV1NamespacedConfigMap({
|
|
@@ -167,7 +167,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
167
167
|
},
|
|
168
168
|
query: {}
|
|
169
169
|
});
|
|
170
|
-
console.log(
|
|
170
|
+
console.log(yanse_1.default.green(`ConfigMap "${resourceName}" deleted successfully`));
|
|
171
171
|
break;
|
|
172
172
|
case 'secret':
|
|
173
173
|
await client.deleteCoreV1NamespacedSecret({
|
|
@@ -177,14 +177,14 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
177
177
|
},
|
|
178
178
|
query: {}
|
|
179
179
|
});
|
|
180
|
-
console.log(
|
|
180
|
+
console.log(yanse_1.default.green(`Secret "${resourceName}" deleted successfully`));
|
|
181
181
|
break;
|
|
182
182
|
default:
|
|
183
|
-
console.log(
|
|
183
|
+
console.log(yanse_1.default.yellow(`Resource type '${resourceType}' not implemented yet for deletion`));
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
catch (error) {
|
|
187
|
-
console.error(
|
|
187
|
+
console.error(yanse_1.default.red(`Error deleting ${resourceType} "${resourceName}": ${error}`));
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
async function deleteFromYaml(client, filePath, namespace) {
|
|
@@ -198,14 +198,14 @@ async function deleteFromYaml(client, filePath, namespace) {
|
|
|
198
198
|
const name = resource.metadata?.name;
|
|
199
199
|
const ns = resource.metadata?.namespace || namespace;
|
|
200
200
|
if (!name) {
|
|
201
|
-
console.error(
|
|
201
|
+
console.error(yanse_1.default.red('Resource must have a name'));
|
|
202
202
|
continue;
|
|
203
203
|
}
|
|
204
204
|
await deleteResource(client, kind, name, ns);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
catch (error) {
|
|
208
|
-
console.error(
|
|
208
|
+
console.error(yanse_1.default.red(`Error processing YAML file: ${error}`));
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
exports.default = async (argv, prompter, _options) => {
|
|
@@ -217,7 +217,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
217
217
|
if (argv.f || argv.filename) {
|
|
218
218
|
const filePath = argv.f || argv.filename;
|
|
219
219
|
if (!fs.existsSync(filePath)) {
|
|
220
|
-
console.error(
|
|
220
|
+
console.error(yanse_1.default.red(`File not found: ${filePath}`));
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
223
|
await deleteFromYaml(client, filePath, namespace);
|
|
@@ -231,7 +231,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
231
231
|
else {
|
|
232
232
|
const selectedResources = await promptResourceSelection(prompter, argv, resourceType, namespace, client);
|
|
233
233
|
if (selectedResources.length === 0) {
|
|
234
|
-
console.log(
|
|
234
|
+
console.log(yanse_1.default.yellow('No resources selected for deletion'));
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
237
237
|
const confirmQuestion = {
|
|
@@ -242,7 +242,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
242
242
|
};
|
|
243
243
|
const { confirmDelete } = await prompter.prompt(argv, [confirmQuestion]);
|
|
244
244
|
if (!confirmDelete) {
|
|
245
|
-
console.log(
|
|
245
|
+
console.log(yanse_1.default.yellow('Deletion cancelled'));
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
248
|
for (const resource of selectedResources) {
|
|
@@ -251,6 +251,6 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
catch (error) {
|
|
254
|
-
console.error(
|
|
254
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
255
255
|
}
|
|
256
256
|
};
|
package/commands/describe.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
7
7
|
const kubernetesjs_1 = require("kubernetesjs");
|
|
8
8
|
const config_1 = require("../config");
|
|
9
9
|
async function promptResourceType(prompter, argv) {
|
|
@@ -54,11 +54,11 @@ async function promptResourceName(prompter, argv, resourceType, namespace, clien
|
|
|
54
54
|
resources = deployments.items || [];
|
|
55
55
|
break;
|
|
56
56
|
default:
|
|
57
|
-
console.log(
|
|
57
|
+
console.log(yanse_1.default.yellow(`Resource type '${resourceType}' not implemented yet for selection`));
|
|
58
58
|
return '';
|
|
59
59
|
}
|
|
60
60
|
if (resources.length === 0) {
|
|
61
|
-
console.log(
|
|
61
|
+
console.log(yanse_1.default.yellow(`No ${resourceType}s found in namespace ${namespace}`));
|
|
62
62
|
return '';
|
|
63
63
|
}
|
|
64
64
|
const options = resources.map(r => ({
|
|
@@ -77,23 +77,23 @@ async function promptResourceName(prompter, argv, resourceType, namespace, clien
|
|
|
77
77
|
return resourceName;
|
|
78
78
|
}
|
|
79
79
|
function describePod(pod) {
|
|
80
|
-
console.log(
|
|
81
|
-
console.log(
|
|
82
|
-
console.log(
|
|
83
|
-
console.log(
|
|
84
|
-
console.log(
|
|
85
|
-
console.log(
|
|
80
|
+
console.log(yanse_1.default.bold(`Name: ${pod.metadata.name}`));
|
|
81
|
+
console.log(yanse_1.default.bold(`Namespace: ${pod.metadata.namespace}`));
|
|
82
|
+
console.log(yanse_1.default.bold(`Priority: ${pod.spec.priority || 0}`));
|
|
83
|
+
console.log(yanse_1.default.bold(`Node: ${pod.spec.nodeName || '<none>'}`));
|
|
84
|
+
console.log(yanse_1.default.bold(`Start Time: ${pod.status.startTime || '<unknown>'}`));
|
|
85
|
+
console.log(yanse_1.default.bold('\nLabels:'));
|
|
86
86
|
if (pod.metadata.labels) {
|
|
87
87
|
Object.entries(pod.metadata.labels).forEach(([key, value]) => {
|
|
88
88
|
console.log(` ${key}=${value}`);
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
console.log(
|
|
92
|
-
console.log(
|
|
93
|
-
console.log(
|
|
91
|
+
console.log(yanse_1.default.bold('\nStatus: ' + pod.status.phase));
|
|
92
|
+
console.log(yanse_1.default.bold('IP: ' + pod.status.podIP));
|
|
93
|
+
console.log(yanse_1.default.bold('\nContainers:'));
|
|
94
94
|
if (pod.spec.containers) {
|
|
95
95
|
pod.spec.containers.forEach((container) => {
|
|
96
|
-
console.log(
|
|
96
|
+
console.log(yanse_1.default.bold(` ${container.name}:`));
|
|
97
97
|
console.log(` Image: ${container.image}`);
|
|
98
98
|
console.log(` Ports: ${container.ports?.map((p) => p.containerPort).join(', ') || '<none>'}`);
|
|
99
99
|
const status = pod.status.containerStatuses?.find((s) => s.name === container.name);
|
|
@@ -114,39 +114,39 @@ function describePod(pod) {
|
|
|
114
114
|
console.log('');
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
console.log(
|
|
117
|
+
console.log(yanse_1.default.bold('Events:'));
|
|
118
118
|
console.log(' <Events not available in this implementation>');
|
|
119
119
|
}
|
|
120
120
|
function describeService(service) {
|
|
121
|
-
console.log(
|
|
122
|
-
console.log(
|
|
123
|
-
console.log(
|
|
124
|
-
console.log(
|
|
125
|
-
console.log(
|
|
126
|
-
console.log(
|
|
121
|
+
console.log(yanse_1.default.bold(`Name: ${service.metadata.name}`));
|
|
122
|
+
console.log(yanse_1.default.bold(`Namespace: ${service.metadata.namespace}`));
|
|
123
|
+
console.log(yanse_1.default.bold(`Labels: ${JSON.stringify(service.metadata.labels || {})}`));
|
|
124
|
+
console.log(yanse_1.default.bold(`Selector: ${JSON.stringify(service.spec.selector || {})}`));
|
|
125
|
+
console.log(yanse_1.default.bold(`Type: ${service.spec.type}`));
|
|
126
|
+
console.log(yanse_1.default.bold(`IP: ${service.spec.clusterIP}`));
|
|
127
127
|
if (service.spec.ports) {
|
|
128
|
-
console.log(
|
|
128
|
+
console.log(yanse_1.default.bold('\nPorts:'));
|
|
129
129
|
service.spec.ports.forEach((port) => {
|
|
130
130
|
console.log(` ${port.name || '<unnamed>'}: ${port.port}/${port.protocol} -> ${port.targetPort}`);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
-
console.log(
|
|
134
|
-
console.log(
|
|
133
|
+
console.log(yanse_1.default.bold('\nSession Affinity: ' + (service.spec.sessionAffinity || 'None')));
|
|
134
|
+
console.log(yanse_1.default.bold('\nEvents:'));
|
|
135
135
|
console.log(' <Events not available in this implementation>');
|
|
136
136
|
}
|
|
137
137
|
function describeDeployment(deployment) {
|
|
138
|
-
console.log(
|
|
139
|
-
console.log(
|
|
140
|
-
console.log(
|
|
141
|
-
console.log(
|
|
142
|
-
console.log(
|
|
143
|
-
console.log(
|
|
144
|
-
console.log(
|
|
145
|
-
console.log(
|
|
138
|
+
console.log(yanse_1.default.bold(`Name: ${deployment.metadata.name}`));
|
|
139
|
+
console.log(yanse_1.default.bold(`Namespace: ${deployment.metadata.namespace}`));
|
|
140
|
+
console.log(yanse_1.default.bold(`CreationTimestamp: ${deployment.metadata.creationTimestamp}`));
|
|
141
|
+
console.log(yanse_1.default.bold(`Labels: ${JSON.stringify(deployment.metadata.labels || {})}`));
|
|
142
|
+
console.log(yanse_1.default.bold(`Annotations: ${JSON.stringify(deployment.metadata.annotations || {})}`));
|
|
143
|
+
console.log(yanse_1.default.bold(`Selector: ${JSON.stringify(deployment.spec.selector.matchLabels || {})}`));
|
|
144
|
+
console.log(yanse_1.default.bold(`Replicas: ${deployment.status.replicas || 0} desired | ${deployment.status.updatedReplicas || 0} updated | ${deployment.status.readyReplicas || 0} ready | ${deployment.status.availableReplicas || 0} available`));
|
|
145
|
+
console.log(yanse_1.default.bold(`StrategyType: ${deployment.spec.strategy.type}`));
|
|
146
146
|
if (deployment.spec.template && deployment.spec.template.spec.containers) {
|
|
147
|
-
console.log(
|
|
147
|
+
console.log(yanse_1.default.bold('\nContainers:'));
|
|
148
148
|
deployment.spec.template.spec.containers.forEach((container) => {
|
|
149
|
-
console.log(
|
|
149
|
+
console.log(yanse_1.default.bold(` ${container.name}:`));
|
|
150
150
|
console.log(` Image: ${container.image}`);
|
|
151
151
|
console.log(` Ports: ${container.ports?.map((p) => p.containerPort).join(', ') || '<none>'}`);
|
|
152
152
|
console.log(` Environment: ${container.env?.map((e) => `${e.name}=${e.value}`).join(', ') || '<none>'}`);
|
|
@@ -154,13 +154,13 @@ function describeDeployment(deployment) {
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
if (deployment.status.conditions) {
|
|
157
|
-
console.log(
|
|
158
|
-
console.log(
|
|
157
|
+
console.log(yanse_1.default.bold('\nConditions:'));
|
|
158
|
+
console.log(yanse_1.default.bold(' Type Status Reason'));
|
|
159
159
|
deployment.status.conditions.forEach((condition) => {
|
|
160
160
|
console.log(` ${condition.type.padEnd(15)}${condition.status.padEnd(8)}${condition.reason || ''}`);
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
-
console.log(
|
|
163
|
+
console.log(yanse_1.default.bold('\nEvents:'));
|
|
164
164
|
console.log(' <Events not available in this implementation>');
|
|
165
165
|
}
|
|
166
166
|
exports.default = async (argv, prompter, _options) => {
|
|
@@ -174,7 +174,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
174
174
|
if (!resourceName) {
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
|
-
console.log(
|
|
177
|
+
console.log(yanse_1.default.blue(`Describing ${resourceType} ${resourceName} in namespace ${namespace}...`));
|
|
178
178
|
switch (resourceType) {
|
|
179
179
|
case 'pod':
|
|
180
180
|
const pod = await client.readCoreV1NamespacedPod({
|
|
@@ -207,10 +207,10 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
207
207
|
describeDeployment(deployment);
|
|
208
208
|
break;
|
|
209
209
|
default:
|
|
210
|
-
console.log(
|
|
210
|
+
console.log(yanse_1.default.yellow(`Resource type '${resourceType}' not implemented yet`));
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
catch (error) {
|
|
214
|
-
console.error(
|
|
214
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
215
215
|
}
|
|
216
216
|
};
|
package/commands/exec.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const kubernetesjs_1 = require("kubernetesjs");
|
|
9
9
|
const config_1 = require("../config");
|
|
@@ -14,7 +14,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
14
14
|
query: { limit: 100 }
|
|
15
15
|
});
|
|
16
16
|
if (!pods.items || pods.items.length === 0) {
|
|
17
|
-
console.log(
|
|
17
|
+
console.log(yanse_1.default.yellow(`No pods found in namespace ${namespace}`));
|
|
18
18
|
return '';
|
|
19
19
|
}
|
|
20
20
|
const options = pods.items.map(pod => ({
|
|
@@ -33,7 +33,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
33
33
|
return podName;
|
|
34
34
|
}
|
|
35
35
|
catch (error) {
|
|
36
|
-
console.error(
|
|
36
|
+
console.error(yanse_1.default.red(`Error getting pods: ${error}`));
|
|
37
37
|
return '';
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -47,7 +47,7 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
47
47
|
query: {}
|
|
48
48
|
});
|
|
49
49
|
if (!pod.spec || !pod.spec.containers || pod.spec.containers.length === 0) {
|
|
50
|
-
console.log(
|
|
50
|
+
console.log(yanse_1.default.yellow(`No containers found in pod ${podName}`));
|
|
51
51
|
return '';
|
|
52
52
|
}
|
|
53
53
|
if (pod.spec.containers.length === 1) {
|
|
@@ -69,12 +69,12 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
69
69
|
return containerName;
|
|
70
70
|
}
|
|
71
71
|
catch (error) {
|
|
72
|
-
console.error(
|
|
72
|
+
console.error(yanse_1.default.red(`Error getting containers: ${error}`));
|
|
73
73
|
return '';
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
async function execInPod(namespace, podName, containerName, command) {
|
|
77
|
-
console.log(
|
|
77
|
+
console.log(yanse_1.default.blue(`Executing command in ${containerName ? 'container ' + containerName + ' of ' : ''}pod ${podName} in namespace ${namespace}...`));
|
|
78
78
|
const kubectlArgs = [
|
|
79
79
|
'exec',
|
|
80
80
|
'-it',
|
|
@@ -140,6 +140,6 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
140
140
|
await execInPod(namespace, podName, containerName, command);
|
|
141
141
|
}
|
|
142
142
|
catch (error) {
|
|
143
|
-
console.error(
|
|
143
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
144
144
|
}
|
|
145
145
|
};
|