@kubernetesjs/cli 0.3.5 → 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/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 +5 -5
- package/utils.js +3 -3
package/commands/get.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) {
|
|
@@ -36,7 +36,7 @@ function formatPodData(pod) {
|
|
|
36
36
|
const status = pod.status.phase;
|
|
37
37
|
const restarts = pod.status.containerStatuses?.reduce((sum, c) => sum + c.restartCount, 0) || 0;
|
|
38
38
|
const age = new Date(pod.metadata.creationTimestamp).toLocaleString();
|
|
39
|
-
console.log(
|
|
39
|
+
console.log(yanse_1.default.green(name.padEnd(50)) +
|
|
40
40
|
ready.padEnd(10) +
|
|
41
41
|
status.padEnd(15) +
|
|
42
42
|
restarts.toString().padEnd(10) +
|
|
@@ -49,7 +49,7 @@ function formatServiceData(service) {
|
|
|
49
49
|
const externalIP = service.spec.externalIPs?.join(',') || '<none>';
|
|
50
50
|
const ports = service.spec.ports?.map((p) => `${p.port}:${p.targetPort}`).join(',') || '<none>';
|
|
51
51
|
const age = new Date(service.metadata.creationTimestamp).toLocaleString();
|
|
52
|
-
console.log(
|
|
52
|
+
console.log(yanse_1.default.green(name.padEnd(30)) +
|
|
53
53
|
type.padEnd(15) +
|
|
54
54
|
clusterIP.padEnd(20) +
|
|
55
55
|
externalIP.padEnd(20) +
|
|
@@ -62,7 +62,7 @@ function formatDeploymentData(deployment) {
|
|
|
62
62
|
const upToDate = deployment.status.updatedReplicas || 0;
|
|
63
63
|
const available = deployment.status.availableReplicas || 0;
|
|
64
64
|
const age = new Date(deployment.metadata.creationTimestamp).toLocaleString();
|
|
65
|
-
console.log(
|
|
65
|
+
console.log(yanse_1.default.green(name.padEnd(30)) +
|
|
66
66
|
ready.padEnd(10) +
|
|
67
67
|
upToDate.toString().padEnd(10) +
|
|
68
68
|
available.toString().padEnd(10) +
|
|
@@ -75,8 +75,8 @@ async function getAllResources(client, namespace) {
|
|
|
75
75
|
query: { limit: 100 }
|
|
76
76
|
});
|
|
77
77
|
if (pods.items && pods.items.length > 0) {
|
|
78
|
-
console.log(
|
|
79
|
-
console.log(
|
|
78
|
+
console.log(yanse_1.default.bold('\nPODS:'));
|
|
79
|
+
console.log(yanse_1.default.bold('NAME'.padEnd(50) + 'READY'.padEnd(10) + 'STATUS'.padEnd(15) + 'RESTARTS'.padEnd(10) + 'AGE'));
|
|
80
80
|
pods.items.forEach(formatPodData);
|
|
81
81
|
}
|
|
82
82
|
const services = await client.listCoreV1NamespacedService({
|
|
@@ -84,8 +84,8 @@ async function getAllResources(client, namespace) {
|
|
|
84
84
|
query: { limit: 100 }
|
|
85
85
|
});
|
|
86
86
|
if (services.items && services.items.length > 0) {
|
|
87
|
-
console.log(
|
|
88
|
-
console.log(
|
|
87
|
+
console.log(yanse_1.default.bold('\nSERVICES:'));
|
|
88
|
+
console.log(yanse_1.default.bold('NAME'.padEnd(30) + 'TYPE'.padEnd(15) + 'CLUSTER-IP'.padEnd(20) + 'EXTERNAL-IP'.padEnd(20) + 'PORT(S)'.padEnd(20) + 'AGE'));
|
|
89
89
|
services.items.forEach(formatServiceData);
|
|
90
90
|
}
|
|
91
91
|
const deployments = await client.listAppsV1NamespacedDeployment({
|
|
@@ -93,13 +93,13 @@ async function getAllResources(client, namespace) {
|
|
|
93
93
|
query: { limit: 100 }
|
|
94
94
|
});
|
|
95
95
|
if (deployments.items && deployments.items.length > 0) {
|
|
96
|
-
console.log(
|
|
97
|
-
console.log(
|
|
96
|
+
console.log(yanse_1.default.bold('\nDEPLOYMENTS:'));
|
|
97
|
+
console.log(yanse_1.default.bold('NAME'.padEnd(30) + 'READY'.padEnd(10) + 'UP-TO-DATE'.padEnd(10) + 'AVAILABLE'.padEnd(10) + 'AGE'));
|
|
98
98
|
deployments.items.forEach(formatDeploymentData);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
catch (error) {
|
|
102
|
-
console.error(
|
|
102
|
+
console.error(yanse_1.default.red(`Error getting resources: ${error}`));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
exports.default = async (argv, prompter, _options) => {
|
|
@@ -109,7 +109,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
109
109
|
});
|
|
110
110
|
const namespace = argv.n || argv.namespace || (0, config_1.getCurrentNamespace)();
|
|
111
111
|
const resourceType = argv._?.[0] || await promptResourceType(prompter, argv);
|
|
112
|
-
console.log(
|
|
112
|
+
console.log(yanse_1.default.blue(`Getting ${resourceType} in namespace ${namespace}...`));
|
|
113
113
|
if (resourceType === 'all') {
|
|
114
114
|
await getAllResources(client, namespace);
|
|
115
115
|
return;
|
|
@@ -120,12 +120,12 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
120
120
|
path: { namespace },
|
|
121
121
|
query: { limit: 100 }
|
|
122
122
|
});
|
|
123
|
-
console.log(
|
|
123
|
+
console.log(yanse_1.default.bold('NAME'.padEnd(50) + 'READY'.padEnd(10) + 'STATUS'.padEnd(15) + 'RESTARTS'.padEnd(10) + 'AGE'));
|
|
124
124
|
if (pods.items && pods.items.length > 0) {
|
|
125
125
|
pods.items.forEach(formatPodData);
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
|
-
console.log(
|
|
128
|
+
console.log(yanse_1.default.yellow('No pods found'));
|
|
129
129
|
}
|
|
130
130
|
break;
|
|
131
131
|
case 'services':
|
|
@@ -133,12 +133,12 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
133
133
|
path: { namespace },
|
|
134
134
|
query: { limit: 100 }
|
|
135
135
|
});
|
|
136
|
-
console.log(
|
|
136
|
+
console.log(yanse_1.default.bold('NAME'.padEnd(30) + 'TYPE'.padEnd(15) + 'CLUSTER-IP'.padEnd(20) + 'EXTERNAL-IP'.padEnd(20) + 'PORT(S)'.padEnd(20) + 'AGE'));
|
|
137
137
|
if (services.items && services.items.length > 0) {
|
|
138
138
|
services.items.forEach(formatServiceData);
|
|
139
139
|
}
|
|
140
140
|
else {
|
|
141
|
-
console.log(
|
|
141
|
+
console.log(yanse_1.default.yellow('No services found'));
|
|
142
142
|
}
|
|
143
143
|
break;
|
|
144
144
|
case 'deployments':
|
|
@@ -146,19 +146,19 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
146
146
|
path: { namespace },
|
|
147
147
|
query: { limit: 100 }
|
|
148
148
|
});
|
|
149
|
-
console.log(
|
|
149
|
+
console.log(yanse_1.default.bold('NAME'.padEnd(30) + 'READY'.padEnd(10) + 'UP-TO-DATE'.padEnd(10) + 'AVAILABLE'.padEnd(10) + 'AGE'));
|
|
150
150
|
if (deployments.items && deployments.items.length > 0) {
|
|
151
151
|
deployments.items.forEach(formatDeploymentData);
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
154
|
-
console.log(
|
|
154
|
+
console.log(yanse_1.default.yellow('No deployments found'));
|
|
155
155
|
}
|
|
156
156
|
break;
|
|
157
157
|
default:
|
|
158
|
-
console.log(
|
|
158
|
+
console.log(yanse_1.default.yellow(`Resource type '${resourceType}' not implemented yet`));
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
catch (error) {
|
|
162
|
-
console.error(
|
|
162
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
163
163
|
}
|
|
164
164
|
};
|
package/commands/logs.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 promptPodName(prompter, argv, namespace, client) {
|
|
@@ -13,7 +13,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
13
13
|
query: { limit: 100 }
|
|
14
14
|
});
|
|
15
15
|
if (!pods.items || pods.items.length === 0) {
|
|
16
|
-
console.log(
|
|
16
|
+
console.log(yanse_1.default.yellow(`No pods found in namespace ${namespace}`));
|
|
17
17
|
return '';
|
|
18
18
|
}
|
|
19
19
|
const options = pods.items.map(pod => ({
|
|
@@ -32,7 +32,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
32
32
|
return podName;
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
console.error(
|
|
35
|
+
console.error(yanse_1.default.red(`Error getting pods: ${error}`));
|
|
36
36
|
return '';
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -46,7 +46,7 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
46
46
|
query: {}
|
|
47
47
|
});
|
|
48
48
|
if (!pod.spec || !pod.spec.containers || pod.spec.containers.length === 0) {
|
|
49
|
-
console.log(
|
|
49
|
+
console.log(yanse_1.default.yellow(`No containers found in pod ${podName}`));
|
|
50
50
|
return '';
|
|
51
51
|
}
|
|
52
52
|
if (pod.spec.containers.length === 1) {
|
|
@@ -68,7 +68,7 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
68
68
|
return containerName;
|
|
69
69
|
}
|
|
70
70
|
catch (error) {
|
|
71
|
-
console.error(
|
|
71
|
+
console.error(yanse_1.default.red(`Error getting containers: ${error}`));
|
|
72
72
|
return '';
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -89,7 +89,7 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
console.log(
|
|
92
|
+
console.log(yanse_1.default.blue(`Getting logs for ${containerName ? 'container ' + containerName + ' in ' : ''}pod ${podName} in namespace ${namespace}...`));
|
|
93
93
|
const logs = await client.readCoreV1NamespacedPodLog({
|
|
94
94
|
path: {
|
|
95
95
|
namespace,
|
|
@@ -105,6 +105,6 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
105
105
|
console.log(logs);
|
|
106
106
|
}
|
|
107
107
|
catch (error) {
|
|
108
|
-
console.error(
|
|
108
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
109
109
|
}
|
|
110
110
|
};
|
package/commands/port-forward.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 promptServiceName(prompter, argv, namespace, client) {
|
|
|
14
14
|
query: { limit: 100 }
|
|
15
15
|
});
|
|
16
16
|
if (!services.items || services.items.length === 0) {
|
|
17
|
-
console.log(
|
|
17
|
+
console.log(yanse_1.default.yellow(`No services found in namespace ${namespace}`));
|
|
18
18
|
return '';
|
|
19
19
|
}
|
|
20
20
|
const options = services.items.map(service => ({
|
|
@@ -33,7 +33,7 @@ async function promptServiceName(prompter, argv, namespace, client) {
|
|
|
33
33
|
return serviceName;
|
|
34
34
|
}
|
|
35
35
|
catch (error) {
|
|
36
|
-
console.error(
|
|
36
|
+
console.error(yanse_1.default.red(`Error getting services: ${error}`));
|
|
37
37
|
return '';
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -47,7 +47,7 @@ async function promptPortMapping(prompter, argv, namespace, serviceName, client)
|
|
|
47
47
|
query: {}
|
|
48
48
|
});
|
|
49
49
|
if (!service.spec || !service.spec.ports || service.spec.ports.length === 0) {
|
|
50
|
-
console.log(
|
|
50
|
+
console.log(yanse_1.default.yellow(`No ports found in service ${serviceName}`));
|
|
51
51
|
return '';
|
|
52
52
|
}
|
|
53
53
|
if (service.spec.ports.length === 1) {
|
|
@@ -75,13 +75,13 @@ async function promptPortMapping(prompter, argv, namespace, serviceName, client)
|
|
|
75
75
|
return portMapping;
|
|
76
76
|
}
|
|
77
77
|
catch (error) {
|
|
78
|
-
console.error(
|
|
78
|
+
console.error(yanse_1.default.red(`Error getting service ports: ${error}`));
|
|
79
79
|
return '';
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
async function portForward(namespace, resourceType, resourceName, portMapping) {
|
|
83
|
-
console.log(
|
|
84
|
-
console.log(
|
|
83
|
+
console.log(yanse_1.default.blue(`Forwarding ports ${portMapping} to ${resourceType}/${resourceName} in namespace ${namespace}...`));
|
|
84
|
+
console.log(yanse_1.default.yellow('Press Ctrl+C to stop port forwarding'));
|
|
85
85
|
const kubectlArgs = [
|
|
86
86
|
'port-forward',
|
|
87
87
|
'-n', namespace,
|
|
@@ -138,6 +138,6 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
138
138
|
await portForward(namespace, resourceType, resourceName, portMapping);
|
|
139
139
|
}
|
|
140
140
|
catch (error) {
|
|
141
|
-
console.error(
|
|
141
|
+
console.error(yanse_1.default.red(`Error: ${error}`));
|
|
142
142
|
}
|
|
143
143
|
};
|
package/esm/commands/apply.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import { KubernetesClient } from 'kubernetesjs';
|
|
4
4
|
import { readYamlFile } from '../config';
|
|
@@ -18,7 +18,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
18
18
|
if (!name) {
|
|
19
19
|
throw new Error('Resource must have a name');
|
|
20
20
|
}
|
|
21
|
-
console.log(
|
|
21
|
+
console.log(yanse.blue(`Applying ${kind} "${name}" in namespace ${namespace}...`));
|
|
22
22
|
try {
|
|
23
23
|
switch (kind) {
|
|
24
24
|
case 'deployment':
|
|
@@ -30,7 +30,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
30
30
|
},
|
|
31
31
|
body: resource
|
|
32
32
|
});
|
|
33
|
-
console.log(
|
|
33
|
+
console.log(yanse.green(`Deployment "${name}" created/updated successfully`));
|
|
34
34
|
break;
|
|
35
35
|
case 'service':
|
|
36
36
|
await client.createCoreV1NamespacedService({
|
|
@@ -41,7 +41,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
41
41
|
},
|
|
42
42
|
body: resource
|
|
43
43
|
});
|
|
44
|
-
console.log(
|
|
44
|
+
console.log(yanse.green(`Service "${name}" created/updated successfully`));
|
|
45
45
|
break;
|
|
46
46
|
case 'pod':
|
|
47
47
|
await client.createCoreV1NamespacedPod({
|
|
@@ -52,7 +52,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
52
52
|
},
|
|
53
53
|
body: resource
|
|
54
54
|
});
|
|
55
|
-
console.log(
|
|
55
|
+
console.log(yanse.green(`Pod "${name}" created/updated successfully`));
|
|
56
56
|
break;
|
|
57
57
|
case 'configmap':
|
|
58
58
|
await client.createCoreV1NamespacedConfigMap({
|
|
@@ -63,7 +63,7 @@ async function applyResource(client, resource, namespace) {
|
|
|
63
63
|
},
|
|
64
64
|
body: resource
|
|
65
65
|
});
|
|
66
|
-
console.log(
|
|
66
|
+
console.log(yanse.green(`ConfigMap "${name}" created/updated successfully`));
|
|
67
67
|
break;
|
|
68
68
|
case 'secret':
|
|
69
69
|
await client.createCoreV1NamespacedSecret({
|
|
@@ -74,14 +74,14 @@ async function applyResource(client, resource, namespace) {
|
|
|
74
74
|
},
|
|
75
75
|
body: resource
|
|
76
76
|
});
|
|
77
|
-
console.log(
|
|
77
|
+
console.log(yanse.green(`Secret "${name}" created/updated successfully`));
|
|
78
78
|
break;
|
|
79
79
|
default:
|
|
80
|
-
console.log(
|
|
80
|
+
console.log(yanse.yellow(`Resource kind "${kind}" not implemented yet`));
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
catch (error) {
|
|
84
|
-
console.error(
|
|
84
|
+
console.error(yanse.red(`Error applying ${kind} "${name}": ${error}`));
|
|
85
85
|
throw error;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -92,11 +92,11 @@ export default async (argv, prompter, _options) => {
|
|
|
92
92
|
});
|
|
93
93
|
const filePath = argv.f || argv._?.[0] || await promptYamlFilePath(prompter, argv);
|
|
94
94
|
if (!filePath) {
|
|
95
|
-
console.error(
|
|
95
|
+
console.error(yanse.red('No file path provided'));
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
if (!fs.existsSync(filePath)) {
|
|
99
|
-
console.error(
|
|
99
|
+
console.error(yanse.red(`File not found: ${filePath}`));
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
let resources;
|
|
@@ -113,7 +113,7 @@ export default async (argv, prompter, _options) => {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
catch (error) {
|
|
116
|
-
console.error(
|
|
116
|
+
console.error(yanse.red(`Error parsing YAML file: ${error}`));
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
for (const resource of resources) {
|
|
@@ -122,12 +122,12 @@ export default async (argv, prompter, _options) => {
|
|
|
122
122
|
await applyResource(client, resource, namespace);
|
|
123
123
|
}
|
|
124
124
|
catch (error) {
|
|
125
|
-
console.error(
|
|
125
|
+
console.error(yanse.red(`Failed to apply resource: ${error}`));
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
console.log(
|
|
128
|
+
console.log(yanse.green('Apply completed'));
|
|
129
129
|
}
|
|
130
130
|
catch (error) {
|
|
131
|
-
console.error(
|
|
131
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
132
132
|
}
|
|
133
133
|
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { KubernetesClient } from 'kubernetesjs';
|
|
3
3
|
export default async (_argv, _prompter, _options) => {
|
|
4
4
|
try {
|
|
5
5
|
const client = new KubernetesClient({
|
|
6
6
|
restEndpoint: _argv.clientUrl
|
|
7
7
|
});
|
|
8
|
-
console.log(
|
|
8
|
+
console.log(yanse.blue('Kubernetes cluster info:'));
|
|
9
9
|
const apiVersions = await client.getAPIVersions({
|
|
10
10
|
params: {},
|
|
11
11
|
query: {}
|
|
12
12
|
});
|
|
13
|
-
console.log(
|
|
13
|
+
console.log(yanse.bold('\nAPI Versions:'));
|
|
14
14
|
if (apiVersions.apiVersion) {
|
|
15
15
|
console.log(apiVersions.apiVersion);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
|
-
console.error(
|
|
19
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
20
20
|
}
|
|
21
21
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import { inferResourceType, readYamlFile } from '../config';
|
|
4
4
|
/**
|
|
@@ -14,13 +14,13 @@ export default async (argv, prompter, options, commandMap) => {
|
|
|
14
14
|
}
|
|
15
15
|
const configPath = argv.config;
|
|
16
16
|
if (!fs.existsSync(configPath)) {
|
|
17
|
-
console.error(
|
|
17
|
+
console.error(yanse.red(`Config file not found: ${configPath}`));
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
21
21
|
const resource = readYamlFile(configPath);
|
|
22
22
|
const resourceType = inferResourceType(resource);
|
|
23
|
-
console.log(
|
|
23
|
+
console.log(yanse.blue(`Detected resource type: ${resourceType}`));
|
|
24
24
|
let command;
|
|
25
25
|
command = 'apply';
|
|
26
26
|
const newArgv = {
|
|
@@ -32,12 +32,12 @@ export default async (argv, prompter, options, commandMap) => {
|
|
|
32
32
|
await commandMap[command](newArgv, prompter, options);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
console.error(
|
|
35
|
+
console.error(yanse.red(`No command found for resource type: ${resourceType}`));
|
|
36
36
|
}
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
|
-
console.error(
|
|
40
|
+
console.error(yanse.red(`Error processing config file: ${error}`));
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
43
|
};
|
package/esm/commands/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { KubernetesClient } from 'kubernetesjs';
|
|
3
3
|
import { getCurrentNamespace, setCurrentNamespace } from '../config';
|
|
4
4
|
async function promptNamespace(prompter, argv, client) {
|
|
@@ -7,7 +7,7 @@ async function promptNamespace(prompter, argv, client) {
|
|
|
7
7
|
query: {}
|
|
8
8
|
});
|
|
9
9
|
if (!namespaces.items || namespaces.items.length === 0) {
|
|
10
|
-
console.log(
|
|
10
|
+
console.log(yanse.yellow('No namespaces found'));
|
|
11
11
|
return '';
|
|
12
12
|
}
|
|
13
13
|
const options = namespaces.items.map(ns => ({
|
|
@@ -26,7 +26,7 @@ async function promptNamespace(prompter, argv, client) {
|
|
|
26
26
|
return namespace;
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
|
-
console.error(
|
|
29
|
+
console.error(yanse.red(`Error getting namespaces: ${error}`));
|
|
30
30
|
return '';
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -38,12 +38,12 @@ export default async (argv, prompter, _options) => {
|
|
|
38
38
|
const subcommand = argv._?.[0];
|
|
39
39
|
if (subcommand === 'get-context') {
|
|
40
40
|
const namespace = getCurrentNamespace();
|
|
41
|
-
console.log(
|
|
41
|
+
console.log(yanse.green(`Current namespace: ${namespace}`));
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
if (subcommand === 'set-context') {
|
|
45
45
|
if (argv.current !== true) {
|
|
46
|
-
console.error(
|
|
46
|
+
console.error(yanse.red('Missing --current flag'));
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
let namespace = argv.namespace;
|
|
@@ -54,14 +54,14 @@ export default async (argv, prompter, _options) => {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
setCurrentNamespace(namespace);
|
|
57
|
-
console.log(
|
|
57
|
+
console.log(yanse.green(`Namespace set to "${namespace}"`));
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
console.log(
|
|
60
|
+
console.log(yanse.blue('Available config commands:'));
|
|
61
61
|
console.log(' get-context Display the current context');
|
|
62
62
|
console.log(' set-context --current --namespace=<namespace> Set the current namespace');
|
|
63
63
|
}
|
|
64
64
|
catch (error) {
|
|
65
|
-
console.error(
|
|
65
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
66
66
|
}
|
|
67
67
|
};
|
package/esm/commands/delete.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import { KubernetesClient } from 'kubernetesjs';
|
|
4
4
|
import { getCurrentNamespace, readYamlFile } from '../config';
|
|
@@ -63,11 +63,11 @@ async function promptResourceSelection(prompter, argv, resourceType, namespace,
|
|
|
63
63
|
resources = secrets.items || [];
|
|
64
64
|
break;
|
|
65
65
|
default:
|
|
66
|
-
console.log(
|
|
66
|
+
console.log(yanse.yellow(`Resource type '${resourceType}' not implemented yet for selection`));
|
|
67
67
|
return [];
|
|
68
68
|
}
|
|
69
69
|
if (resources.length === 0) {
|
|
70
|
-
console.log(
|
|
70
|
+
console.log(yanse.yellow(`No ${resourceType}s found in namespace ${namespace}`));
|
|
71
71
|
return [];
|
|
72
72
|
}
|
|
73
73
|
const options = resources.map(r => ({
|
|
@@ -99,7 +99,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
99
99
|
},
|
|
100
100
|
query: {}
|
|
101
101
|
});
|
|
102
|
-
console.log(
|
|
102
|
+
console.log(yanse.green(`Pod "${resourceName}" deleted successfully`));
|
|
103
103
|
break;
|
|
104
104
|
case 'service':
|
|
105
105
|
await client.deleteCoreV1NamespacedService({
|
|
@@ -109,7 +109,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
109
109
|
},
|
|
110
110
|
query: {}
|
|
111
111
|
});
|
|
112
|
-
console.log(
|
|
112
|
+
console.log(yanse.green(`Service "${resourceName}" deleted successfully`));
|
|
113
113
|
break;
|
|
114
114
|
case 'deployment':
|
|
115
115
|
await client.deleteAppsV1NamespacedDeployment({
|
|
@@ -119,7 +119,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
119
119
|
},
|
|
120
120
|
query: {}
|
|
121
121
|
});
|
|
122
|
-
console.log(
|
|
122
|
+
console.log(yanse.green(`Deployment "${resourceName}" deleted successfully`));
|
|
123
123
|
break;
|
|
124
124
|
case 'configmap':
|
|
125
125
|
await client.deleteCoreV1NamespacedConfigMap({
|
|
@@ -129,7 +129,7 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
129
129
|
},
|
|
130
130
|
query: {}
|
|
131
131
|
});
|
|
132
|
-
console.log(
|
|
132
|
+
console.log(yanse.green(`ConfigMap "${resourceName}" deleted successfully`));
|
|
133
133
|
break;
|
|
134
134
|
case 'secret':
|
|
135
135
|
await client.deleteCoreV1NamespacedSecret({
|
|
@@ -139,14 +139,14 @@ async function deleteResource(client, resourceType, resourceName, namespace) {
|
|
|
139
139
|
},
|
|
140
140
|
query: {}
|
|
141
141
|
});
|
|
142
|
-
console.log(
|
|
142
|
+
console.log(yanse.green(`Secret "${resourceName}" deleted successfully`));
|
|
143
143
|
break;
|
|
144
144
|
default:
|
|
145
|
-
console.log(
|
|
145
|
+
console.log(yanse.yellow(`Resource type '${resourceType}' not implemented yet for deletion`));
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
catch (error) {
|
|
149
|
-
console.error(
|
|
149
|
+
console.error(yanse.red(`Error deleting ${resourceType} "${resourceName}": ${error}`));
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
async function deleteFromYaml(client, filePath, namespace) {
|
|
@@ -160,14 +160,14 @@ async function deleteFromYaml(client, filePath, namespace) {
|
|
|
160
160
|
const name = resource.metadata?.name;
|
|
161
161
|
const ns = resource.metadata?.namespace || namespace;
|
|
162
162
|
if (!name) {
|
|
163
|
-
console.error(
|
|
163
|
+
console.error(yanse.red('Resource must have a name'));
|
|
164
164
|
continue;
|
|
165
165
|
}
|
|
166
166
|
await deleteResource(client, kind, name, ns);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
catch (error) {
|
|
170
|
-
console.error(
|
|
170
|
+
console.error(yanse.red(`Error processing YAML file: ${error}`));
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
export default async (argv, prompter, _options) => {
|
|
@@ -179,7 +179,7 @@ export default async (argv, prompter, _options) => {
|
|
|
179
179
|
if (argv.f || argv.filename) {
|
|
180
180
|
const filePath = argv.f || argv.filename;
|
|
181
181
|
if (!fs.existsSync(filePath)) {
|
|
182
|
-
console.error(
|
|
182
|
+
console.error(yanse.red(`File not found: ${filePath}`));
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
185
|
await deleteFromYaml(client, filePath, namespace);
|
|
@@ -193,7 +193,7 @@ export default async (argv, prompter, _options) => {
|
|
|
193
193
|
else {
|
|
194
194
|
const selectedResources = await promptResourceSelection(prompter, argv, resourceType, namespace, client);
|
|
195
195
|
if (selectedResources.length === 0) {
|
|
196
|
-
console.log(
|
|
196
|
+
console.log(yanse.yellow('No resources selected for deletion'));
|
|
197
197
|
return;
|
|
198
198
|
}
|
|
199
199
|
const confirmQuestion = {
|
|
@@ -204,7 +204,7 @@ export default async (argv, prompter, _options) => {
|
|
|
204
204
|
};
|
|
205
205
|
const { confirmDelete } = await prompter.prompt(argv, [confirmQuestion]);
|
|
206
206
|
if (!confirmDelete) {
|
|
207
|
-
console.log(
|
|
207
|
+
console.log(yanse.yellow('Deletion cancelled'));
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
210
210
|
for (const resource of selectedResources) {
|
|
@@ -213,6 +213,6 @@ export default async (argv, prompter, _options) => {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
catch (error) {
|
|
216
|
-
console.error(
|
|
216
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
217
217
|
}
|
|
218
218
|
};
|