@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/esm/commands/describe.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { KubernetesClient } from 'kubernetesjs';
|
|
3
3
|
import { getCurrentNamespace } from '../config';
|
|
4
4
|
async function promptResourceType(prompter, argv) {
|
|
@@ -49,11 +49,11 @@ async function promptResourceName(prompter, argv, resourceType, namespace, clien
|
|
|
49
49
|
resources = deployments.items || [];
|
|
50
50
|
break;
|
|
51
51
|
default:
|
|
52
|
-
console.log(
|
|
52
|
+
console.log(yanse.yellow(`Resource type '${resourceType}' not implemented yet for selection`));
|
|
53
53
|
return '';
|
|
54
54
|
}
|
|
55
55
|
if (resources.length === 0) {
|
|
56
|
-
console.log(
|
|
56
|
+
console.log(yanse.yellow(`No ${resourceType}s found in namespace ${namespace}`));
|
|
57
57
|
return '';
|
|
58
58
|
}
|
|
59
59
|
const options = resources.map(r => ({
|
|
@@ -72,23 +72,23 @@ async function promptResourceName(prompter, argv, resourceType, namespace, clien
|
|
|
72
72
|
return resourceName;
|
|
73
73
|
}
|
|
74
74
|
function describePod(pod) {
|
|
75
|
-
console.log(
|
|
76
|
-
console.log(
|
|
77
|
-
console.log(
|
|
78
|
-
console.log(
|
|
79
|
-
console.log(
|
|
80
|
-
console.log(
|
|
75
|
+
console.log(yanse.bold(`Name: ${pod.metadata.name}`));
|
|
76
|
+
console.log(yanse.bold(`Namespace: ${pod.metadata.namespace}`));
|
|
77
|
+
console.log(yanse.bold(`Priority: ${pod.spec.priority || 0}`));
|
|
78
|
+
console.log(yanse.bold(`Node: ${pod.spec.nodeName || '<none>'}`));
|
|
79
|
+
console.log(yanse.bold(`Start Time: ${pod.status.startTime || '<unknown>'}`));
|
|
80
|
+
console.log(yanse.bold('\nLabels:'));
|
|
81
81
|
if (pod.metadata.labels) {
|
|
82
82
|
Object.entries(pod.metadata.labels).forEach(([key, value]) => {
|
|
83
83
|
console.log(` ${key}=${value}`);
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
console.log(
|
|
87
|
-
console.log(
|
|
88
|
-
console.log(
|
|
86
|
+
console.log(yanse.bold('\nStatus: ' + pod.status.phase));
|
|
87
|
+
console.log(yanse.bold('IP: ' + pod.status.podIP));
|
|
88
|
+
console.log(yanse.bold('\nContainers:'));
|
|
89
89
|
if (pod.spec.containers) {
|
|
90
90
|
pod.spec.containers.forEach((container) => {
|
|
91
|
-
console.log(
|
|
91
|
+
console.log(yanse.bold(` ${container.name}:`));
|
|
92
92
|
console.log(` Image: ${container.image}`);
|
|
93
93
|
console.log(` Ports: ${container.ports?.map((p) => p.containerPort).join(', ') || '<none>'}`);
|
|
94
94
|
const status = pod.status.containerStatuses?.find((s) => s.name === container.name);
|
|
@@ -109,39 +109,39 @@ function describePod(pod) {
|
|
|
109
109
|
console.log('');
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
console.log(
|
|
112
|
+
console.log(yanse.bold('Events:'));
|
|
113
113
|
console.log(' <Events not available in this implementation>');
|
|
114
114
|
}
|
|
115
115
|
function describeService(service) {
|
|
116
|
-
console.log(
|
|
117
|
-
console.log(
|
|
118
|
-
console.log(
|
|
119
|
-
console.log(
|
|
120
|
-
console.log(
|
|
121
|
-
console.log(
|
|
116
|
+
console.log(yanse.bold(`Name: ${service.metadata.name}`));
|
|
117
|
+
console.log(yanse.bold(`Namespace: ${service.metadata.namespace}`));
|
|
118
|
+
console.log(yanse.bold(`Labels: ${JSON.stringify(service.metadata.labels || {})}`));
|
|
119
|
+
console.log(yanse.bold(`Selector: ${JSON.stringify(service.spec.selector || {})}`));
|
|
120
|
+
console.log(yanse.bold(`Type: ${service.spec.type}`));
|
|
121
|
+
console.log(yanse.bold(`IP: ${service.spec.clusterIP}`));
|
|
122
122
|
if (service.spec.ports) {
|
|
123
|
-
console.log(
|
|
123
|
+
console.log(yanse.bold('\nPorts:'));
|
|
124
124
|
service.spec.ports.forEach((port) => {
|
|
125
125
|
console.log(` ${port.name || '<unnamed>'}: ${port.port}/${port.protocol} -> ${port.targetPort}`);
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
console.log(
|
|
129
|
-
console.log(
|
|
128
|
+
console.log(yanse.bold('\nSession Affinity: ' + (service.spec.sessionAffinity || 'None')));
|
|
129
|
+
console.log(yanse.bold('\nEvents:'));
|
|
130
130
|
console.log(' <Events not available in this implementation>');
|
|
131
131
|
}
|
|
132
132
|
function describeDeployment(deployment) {
|
|
133
|
-
console.log(
|
|
134
|
-
console.log(
|
|
135
|
-
console.log(
|
|
136
|
-
console.log(
|
|
137
|
-
console.log(
|
|
138
|
-
console.log(
|
|
139
|
-
console.log(
|
|
140
|
-
console.log(
|
|
133
|
+
console.log(yanse.bold(`Name: ${deployment.metadata.name}`));
|
|
134
|
+
console.log(yanse.bold(`Namespace: ${deployment.metadata.namespace}`));
|
|
135
|
+
console.log(yanse.bold(`CreationTimestamp: ${deployment.metadata.creationTimestamp}`));
|
|
136
|
+
console.log(yanse.bold(`Labels: ${JSON.stringify(deployment.metadata.labels || {})}`));
|
|
137
|
+
console.log(yanse.bold(`Annotations: ${JSON.stringify(deployment.metadata.annotations || {})}`));
|
|
138
|
+
console.log(yanse.bold(`Selector: ${JSON.stringify(deployment.spec.selector.matchLabels || {})}`));
|
|
139
|
+
console.log(yanse.bold(`Replicas: ${deployment.status.replicas || 0} desired | ${deployment.status.updatedReplicas || 0} updated | ${deployment.status.readyReplicas || 0} ready | ${deployment.status.availableReplicas || 0} available`));
|
|
140
|
+
console.log(yanse.bold(`StrategyType: ${deployment.spec.strategy.type}`));
|
|
141
141
|
if (deployment.spec.template && deployment.spec.template.spec.containers) {
|
|
142
|
-
console.log(
|
|
142
|
+
console.log(yanse.bold('\nContainers:'));
|
|
143
143
|
deployment.spec.template.spec.containers.forEach((container) => {
|
|
144
|
-
console.log(
|
|
144
|
+
console.log(yanse.bold(` ${container.name}:`));
|
|
145
145
|
console.log(` Image: ${container.image}`);
|
|
146
146
|
console.log(` Ports: ${container.ports?.map((p) => p.containerPort).join(', ') || '<none>'}`);
|
|
147
147
|
console.log(` Environment: ${container.env?.map((e) => `${e.name}=${e.value}`).join(', ') || '<none>'}`);
|
|
@@ -149,13 +149,13 @@ function describeDeployment(deployment) {
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
if (deployment.status.conditions) {
|
|
152
|
-
console.log(
|
|
153
|
-
console.log(
|
|
152
|
+
console.log(yanse.bold('\nConditions:'));
|
|
153
|
+
console.log(yanse.bold(' Type Status Reason'));
|
|
154
154
|
deployment.status.conditions.forEach((condition) => {
|
|
155
155
|
console.log(` ${condition.type.padEnd(15)}${condition.status.padEnd(8)}${condition.reason || ''}`);
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
console.log(
|
|
158
|
+
console.log(yanse.bold('\nEvents:'));
|
|
159
159
|
console.log(' <Events not available in this implementation>');
|
|
160
160
|
}
|
|
161
161
|
export default async (argv, prompter, _options) => {
|
|
@@ -169,7 +169,7 @@ export default async (argv, prompter, _options) => {
|
|
|
169
169
|
if (!resourceName) {
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
|
-
console.log(
|
|
172
|
+
console.log(yanse.blue(`Describing ${resourceType} ${resourceName} in namespace ${namespace}...`));
|
|
173
173
|
switch (resourceType) {
|
|
174
174
|
case 'pod':
|
|
175
175
|
const pod = await client.readCoreV1NamespacedPod({
|
|
@@ -202,10 +202,10 @@ export default async (argv, prompter, _options) => {
|
|
|
202
202
|
describeDeployment(deployment);
|
|
203
203
|
break;
|
|
204
204
|
default:
|
|
205
|
-
console.log(
|
|
205
|
+
console.log(yanse.yellow(`Resource type '${resourceType}' not implemented yet`));
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
catch (error) {
|
|
209
|
-
console.error(
|
|
209
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
210
210
|
}
|
|
211
211
|
};
|
package/esm/commands/exec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { spawn } from 'child_process';
|
|
3
3
|
import { KubernetesClient } from 'kubernetesjs';
|
|
4
4
|
import { getCurrentNamespace } from '../config';
|
|
@@ -9,7 +9,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
9
9
|
query: { limit: 100 }
|
|
10
10
|
});
|
|
11
11
|
if (!pods.items || pods.items.length === 0) {
|
|
12
|
-
console.log(
|
|
12
|
+
console.log(yanse.yellow(`No pods found in namespace ${namespace}`));
|
|
13
13
|
return '';
|
|
14
14
|
}
|
|
15
15
|
const options = pods.items.map(pod => ({
|
|
@@ -28,7 +28,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
28
28
|
return podName;
|
|
29
29
|
}
|
|
30
30
|
catch (error) {
|
|
31
|
-
console.error(
|
|
31
|
+
console.error(yanse.red(`Error getting pods: ${error}`));
|
|
32
32
|
return '';
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -42,7 +42,7 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
42
42
|
query: {}
|
|
43
43
|
});
|
|
44
44
|
if (!pod.spec || !pod.spec.containers || pod.spec.containers.length === 0) {
|
|
45
|
-
console.log(
|
|
45
|
+
console.log(yanse.yellow(`No containers found in pod ${podName}`));
|
|
46
46
|
return '';
|
|
47
47
|
}
|
|
48
48
|
if (pod.spec.containers.length === 1) {
|
|
@@ -64,12 +64,12 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
64
64
|
return containerName;
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
|
-
console.error(
|
|
67
|
+
console.error(yanse.red(`Error getting containers: ${error}`));
|
|
68
68
|
return '';
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
async function execInPod(namespace, podName, containerName, command) {
|
|
72
|
-
console.log(
|
|
72
|
+
console.log(yanse.blue(`Executing command in ${containerName ? 'container ' + containerName + ' of ' : ''}pod ${podName} in namespace ${namespace}...`));
|
|
73
73
|
const kubectlArgs = [
|
|
74
74
|
'exec',
|
|
75
75
|
'-it',
|
|
@@ -135,6 +135,6 @@ export default async (argv, prompter, _options) => {
|
|
|
135
135
|
await execInPod(namespace, podName, containerName, command);
|
|
136
136
|
}
|
|
137
137
|
catch (error) {
|
|
138
|
-
console.error(
|
|
138
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
139
139
|
}
|
|
140
140
|
};
|
package/esm/commands/get.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { KubernetesClient } from 'kubernetesjs';
|
|
3
3
|
import { getCurrentNamespace } from '../config';
|
|
4
4
|
async function promptResourceType(prompter, argv) {
|
|
@@ -31,7 +31,7 @@ function formatPodData(pod) {
|
|
|
31
31
|
const status = pod.status.phase;
|
|
32
32
|
const restarts = pod.status.containerStatuses?.reduce((sum, c) => sum + c.restartCount, 0) || 0;
|
|
33
33
|
const age = new Date(pod.metadata.creationTimestamp).toLocaleString();
|
|
34
|
-
console.log(
|
|
34
|
+
console.log(yanse.green(name.padEnd(50)) +
|
|
35
35
|
ready.padEnd(10) +
|
|
36
36
|
status.padEnd(15) +
|
|
37
37
|
restarts.toString().padEnd(10) +
|
|
@@ -44,7 +44,7 @@ function formatServiceData(service) {
|
|
|
44
44
|
const externalIP = service.spec.externalIPs?.join(',') || '<none>';
|
|
45
45
|
const ports = service.spec.ports?.map((p) => `${p.port}:${p.targetPort}`).join(',') || '<none>';
|
|
46
46
|
const age = new Date(service.metadata.creationTimestamp).toLocaleString();
|
|
47
|
-
console.log(
|
|
47
|
+
console.log(yanse.green(name.padEnd(30)) +
|
|
48
48
|
type.padEnd(15) +
|
|
49
49
|
clusterIP.padEnd(20) +
|
|
50
50
|
externalIP.padEnd(20) +
|
|
@@ -57,7 +57,7 @@ function formatDeploymentData(deployment) {
|
|
|
57
57
|
const upToDate = deployment.status.updatedReplicas || 0;
|
|
58
58
|
const available = deployment.status.availableReplicas || 0;
|
|
59
59
|
const age = new Date(deployment.metadata.creationTimestamp).toLocaleString();
|
|
60
|
-
console.log(
|
|
60
|
+
console.log(yanse.green(name.padEnd(30)) +
|
|
61
61
|
ready.padEnd(10) +
|
|
62
62
|
upToDate.toString().padEnd(10) +
|
|
63
63
|
available.toString().padEnd(10) +
|
|
@@ -70,8 +70,8 @@ async function getAllResources(client, namespace) {
|
|
|
70
70
|
query: { limit: 100 }
|
|
71
71
|
});
|
|
72
72
|
if (pods.items && pods.items.length > 0) {
|
|
73
|
-
console.log(
|
|
74
|
-
console.log(
|
|
73
|
+
console.log(yanse.bold('\nPODS:'));
|
|
74
|
+
console.log(yanse.bold('NAME'.padEnd(50) + 'READY'.padEnd(10) + 'STATUS'.padEnd(15) + 'RESTARTS'.padEnd(10) + 'AGE'));
|
|
75
75
|
pods.items.forEach(formatPodData);
|
|
76
76
|
}
|
|
77
77
|
const services = await client.listCoreV1NamespacedService({
|
|
@@ -79,8 +79,8 @@ async function getAllResources(client, namespace) {
|
|
|
79
79
|
query: { limit: 100 }
|
|
80
80
|
});
|
|
81
81
|
if (services.items && services.items.length > 0) {
|
|
82
|
-
console.log(
|
|
83
|
-
console.log(
|
|
82
|
+
console.log(yanse.bold('\nSERVICES:'));
|
|
83
|
+
console.log(yanse.bold('NAME'.padEnd(30) + 'TYPE'.padEnd(15) + 'CLUSTER-IP'.padEnd(20) + 'EXTERNAL-IP'.padEnd(20) + 'PORT(S)'.padEnd(20) + 'AGE'));
|
|
84
84
|
services.items.forEach(formatServiceData);
|
|
85
85
|
}
|
|
86
86
|
const deployments = await client.listAppsV1NamespacedDeployment({
|
|
@@ -88,13 +88,13 @@ async function getAllResources(client, namespace) {
|
|
|
88
88
|
query: { limit: 100 }
|
|
89
89
|
});
|
|
90
90
|
if (deployments.items && deployments.items.length > 0) {
|
|
91
|
-
console.log(
|
|
92
|
-
console.log(
|
|
91
|
+
console.log(yanse.bold('\nDEPLOYMENTS:'));
|
|
92
|
+
console.log(yanse.bold('NAME'.padEnd(30) + 'READY'.padEnd(10) + 'UP-TO-DATE'.padEnd(10) + 'AVAILABLE'.padEnd(10) + 'AGE'));
|
|
93
93
|
deployments.items.forEach(formatDeploymentData);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
catch (error) {
|
|
97
|
-
console.error(
|
|
97
|
+
console.error(yanse.red(`Error getting resources: ${error}`));
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
export default async (argv, prompter, _options) => {
|
|
@@ -104,7 +104,7 @@ export default async (argv, prompter, _options) => {
|
|
|
104
104
|
});
|
|
105
105
|
const namespace = argv.n || argv.namespace || getCurrentNamespace();
|
|
106
106
|
const resourceType = argv._?.[0] || await promptResourceType(prompter, argv);
|
|
107
|
-
console.log(
|
|
107
|
+
console.log(yanse.blue(`Getting ${resourceType} in namespace ${namespace}...`));
|
|
108
108
|
if (resourceType === 'all') {
|
|
109
109
|
await getAllResources(client, namespace);
|
|
110
110
|
return;
|
|
@@ -115,12 +115,12 @@ export default async (argv, prompter, _options) => {
|
|
|
115
115
|
path: { namespace },
|
|
116
116
|
query: { limit: 100 }
|
|
117
117
|
});
|
|
118
|
-
console.log(
|
|
118
|
+
console.log(yanse.bold('NAME'.padEnd(50) + 'READY'.padEnd(10) + 'STATUS'.padEnd(15) + 'RESTARTS'.padEnd(10) + 'AGE'));
|
|
119
119
|
if (pods.items && pods.items.length > 0) {
|
|
120
120
|
pods.items.forEach(formatPodData);
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
|
-
console.log(
|
|
123
|
+
console.log(yanse.yellow('No pods found'));
|
|
124
124
|
}
|
|
125
125
|
break;
|
|
126
126
|
case 'services':
|
|
@@ -128,12 +128,12 @@ export default async (argv, prompter, _options) => {
|
|
|
128
128
|
path: { namespace },
|
|
129
129
|
query: { limit: 100 }
|
|
130
130
|
});
|
|
131
|
-
console.log(
|
|
131
|
+
console.log(yanse.bold('NAME'.padEnd(30) + 'TYPE'.padEnd(15) + 'CLUSTER-IP'.padEnd(20) + 'EXTERNAL-IP'.padEnd(20) + 'PORT(S)'.padEnd(20) + 'AGE'));
|
|
132
132
|
if (services.items && services.items.length > 0) {
|
|
133
133
|
services.items.forEach(formatServiceData);
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
136
|
-
console.log(
|
|
136
|
+
console.log(yanse.yellow('No services found'));
|
|
137
137
|
}
|
|
138
138
|
break;
|
|
139
139
|
case 'deployments':
|
|
@@ -141,19 +141,19 @@ export default async (argv, prompter, _options) => {
|
|
|
141
141
|
path: { namespace },
|
|
142
142
|
query: { limit: 100 }
|
|
143
143
|
});
|
|
144
|
-
console.log(
|
|
144
|
+
console.log(yanse.bold('NAME'.padEnd(30) + 'READY'.padEnd(10) + 'UP-TO-DATE'.padEnd(10) + 'AVAILABLE'.padEnd(10) + 'AGE'));
|
|
145
145
|
if (deployments.items && deployments.items.length > 0) {
|
|
146
146
|
deployments.items.forEach(formatDeploymentData);
|
|
147
147
|
}
|
|
148
148
|
else {
|
|
149
|
-
console.log(
|
|
149
|
+
console.log(yanse.yellow('No deployments found'));
|
|
150
150
|
}
|
|
151
151
|
break;
|
|
152
152
|
default:
|
|
153
|
-
console.log(
|
|
153
|
+
console.log(yanse.yellow(`Resource type '${resourceType}' not implemented yet`));
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
catch (error) {
|
|
157
|
-
console.error(
|
|
157
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
158
158
|
}
|
|
159
159
|
};
|
package/esm/commands/logs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { KubernetesClient } from 'kubernetesjs';
|
|
3
3
|
import { getCurrentNamespace } from '../config';
|
|
4
4
|
async function promptPodName(prompter, argv, namespace, client) {
|
|
@@ -8,7 +8,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
8
8
|
query: { limit: 100 }
|
|
9
9
|
});
|
|
10
10
|
if (!pods.items || pods.items.length === 0) {
|
|
11
|
-
console.log(
|
|
11
|
+
console.log(yanse.yellow(`No pods found in namespace ${namespace}`));
|
|
12
12
|
return '';
|
|
13
13
|
}
|
|
14
14
|
const options = pods.items.map(pod => ({
|
|
@@ -27,7 +27,7 @@ async function promptPodName(prompter, argv, namespace, client) {
|
|
|
27
27
|
return podName;
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
|
-
console.error(
|
|
30
|
+
console.error(yanse.red(`Error getting pods: ${error}`));
|
|
31
31
|
return '';
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -41,7 +41,7 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
41
41
|
query: {}
|
|
42
42
|
});
|
|
43
43
|
if (!pod.spec || !pod.spec.containers || pod.spec.containers.length === 0) {
|
|
44
|
-
console.log(
|
|
44
|
+
console.log(yanse.yellow(`No containers found in pod ${podName}`));
|
|
45
45
|
return '';
|
|
46
46
|
}
|
|
47
47
|
if (pod.spec.containers.length === 1) {
|
|
@@ -63,7 +63,7 @@ async function promptContainerName(prompter, argv, namespace, podName, client) {
|
|
|
63
63
|
return containerName;
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
|
-
console.error(
|
|
66
|
+
console.error(yanse.red(`Error getting containers: ${error}`));
|
|
67
67
|
return '';
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -84,7 +84,7 @@ export default async (argv, prompter, _options) => {
|
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
console.log(
|
|
87
|
+
console.log(yanse.blue(`Getting logs for ${containerName ? 'container ' + containerName + ' in ' : ''}pod ${podName} in namespace ${namespace}...`));
|
|
88
88
|
const logs = await client.readCoreV1NamespacedPodLog({
|
|
89
89
|
path: {
|
|
90
90
|
namespace,
|
|
@@ -100,6 +100,6 @@ export default async (argv, prompter, _options) => {
|
|
|
100
100
|
console.log(logs);
|
|
101
101
|
}
|
|
102
102
|
catch (error) {
|
|
103
|
-
console.error(
|
|
103
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
104
104
|
}
|
|
105
105
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { spawn } from 'child_process';
|
|
3
3
|
import { KubernetesClient } from 'kubernetesjs';
|
|
4
4
|
import { getCurrentNamespace } from '../config';
|
|
@@ -9,7 +9,7 @@ async function promptServiceName(prompter, argv, namespace, client) {
|
|
|
9
9
|
query: { limit: 100 }
|
|
10
10
|
});
|
|
11
11
|
if (!services.items || services.items.length === 0) {
|
|
12
|
-
console.log(
|
|
12
|
+
console.log(yanse.yellow(`No services found in namespace ${namespace}`));
|
|
13
13
|
return '';
|
|
14
14
|
}
|
|
15
15
|
const options = services.items.map(service => ({
|
|
@@ -28,7 +28,7 @@ async function promptServiceName(prompter, argv, namespace, client) {
|
|
|
28
28
|
return serviceName;
|
|
29
29
|
}
|
|
30
30
|
catch (error) {
|
|
31
|
-
console.error(
|
|
31
|
+
console.error(yanse.red(`Error getting services: ${error}`));
|
|
32
32
|
return '';
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -42,7 +42,7 @@ async function promptPortMapping(prompter, argv, namespace, serviceName, client)
|
|
|
42
42
|
query: {}
|
|
43
43
|
});
|
|
44
44
|
if (!service.spec || !service.spec.ports || service.spec.ports.length === 0) {
|
|
45
|
-
console.log(
|
|
45
|
+
console.log(yanse.yellow(`No ports found in service ${serviceName}`));
|
|
46
46
|
return '';
|
|
47
47
|
}
|
|
48
48
|
if (service.spec.ports.length === 1) {
|
|
@@ -70,13 +70,13 @@ async function promptPortMapping(prompter, argv, namespace, serviceName, client)
|
|
|
70
70
|
return portMapping;
|
|
71
71
|
}
|
|
72
72
|
catch (error) {
|
|
73
|
-
console.error(
|
|
73
|
+
console.error(yanse.red(`Error getting service ports: ${error}`));
|
|
74
74
|
return '';
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
async function portForward(namespace, resourceType, resourceName, portMapping) {
|
|
78
|
-
console.log(
|
|
79
|
-
console.log(
|
|
78
|
+
console.log(yanse.blue(`Forwarding ports ${portMapping} to ${resourceType}/${resourceName} in namespace ${namespace}...`));
|
|
79
|
+
console.log(yanse.yellow('Press Ctrl+C to stop port forwarding'));
|
|
80
80
|
const kubectlArgs = [
|
|
81
81
|
'port-forward',
|
|
82
82
|
'-n', namespace,
|
|
@@ -133,6 +133,6 @@ export default async (argv, prompter, _options) => {
|
|
|
133
133
|
await portForward(namespace, resourceType, resourceName, portMapping);
|
|
134
134
|
}
|
|
135
135
|
catch (error) {
|
|
136
|
-
console.error(
|
|
136
|
+
console.error(yanse.red(`Error: ${error}`));
|
|
137
137
|
}
|
|
138
138
|
};
|
package/esm/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import yanse from 'yanse';
|
|
2
2
|
import { readAndParsePackageJson } from './package';
|
|
3
3
|
export const extractFirst = (argv) => {
|
|
4
4
|
const first = argv._?.[0];
|
|
@@ -11,8 +11,8 @@ export const extractFirst = (argv) => {
|
|
|
11
11
|
// Function to display the version information
|
|
12
12
|
export function displayVersion() {
|
|
13
13
|
const pkg = readAndParsePackageJson();
|
|
14
|
-
console.log(
|
|
15
|
-
console.log(
|
|
14
|
+
console.log(yanse.green(`Name: ${pkg.name}`));
|
|
15
|
+
console.log(yanse.blue(`Version: ${pkg.version}`));
|
|
16
16
|
}
|
|
17
17
|
export const usageText = `
|
|
18
18
|
Usage: k8s <command> [options]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubernetesjs/cli",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"author": "
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "KubernetesJS CLI",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"kubernetes",
|
|
@@ -20,44 +20,45 @@
|
|
|
20
20
|
"main": "index.js",
|
|
21
21
|
"module": "esm/index.js",
|
|
22
22
|
"types": "index.d.ts",
|
|
23
|
-
"homepage": "https://github.com/
|
|
24
|
-
"license": "
|
|
23
|
+
"homepage": "https://github.com/constructive-io/kubernetesjs",
|
|
24
|
+
"license": "MIT",
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public",
|
|
27
27
|
"directory": "dist"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
|
-
"url": "https://github.com/
|
|
31
|
+
"url": "https://github.com/constructive-io/kubernetesjs"
|
|
32
32
|
},
|
|
33
33
|
"bugs": {
|
|
34
|
-
"url": "https://github.com/
|
|
34
|
+
"url": "https://github.com/constructive-io/kubernetesjs/issues"
|
|
35
35
|
},
|
|
36
36
|
"bin": {
|
|
37
37
|
"k8s": "index.js",
|
|
38
38
|
"kubernetes": "index.js"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"build": "
|
|
45
|
-
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
|
|
41
|
+
"clean": "makage clean",
|
|
42
|
+
"prepack": "npm run build",
|
|
43
|
+
"build": "makage build",
|
|
44
|
+
"build:dev": "makage build --dev",
|
|
46
45
|
"lint": "eslint . --fix",
|
|
47
46
|
"test": "jest",
|
|
48
47
|
"test:watch": "jest --watch",
|
|
49
48
|
"dev": "ts-node src/index.ts"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@types/js-yaml": "^4.0.9"
|
|
51
|
+
"@types/js-yaml": "^4.0.9",
|
|
52
|
+
"@types/minimist": "^1.2.5",
|
|
53
|
+
"makage": "^0.1.8"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"chalk": "^4.1.0",
|
|
56
56
|
"deepmerge": "^4.3.1",
|
|
57
57
|
"inquirerer": "^2.0.8",
|
|
58
58
|
"js-yaml": "^4.1.0",
|
|
59
|
-
"kubernetesjs": "^0.7.
|
|
60
|
-
"minimist": "^1.2.8"
|
|
59
|
+
"kubernetesjs": "^0.7.6",
|
|
60
|
+
"minimist": "^1.2.8",
|
|
61
|
+
"yanse": "^0.1.8"
|
|
61
62
|
},
|
|
62
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "66c8c0a6c3594561a7fd827db7d07db691354ab3"
|
|
63
64
|
}
|
package/utils.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.usageText = exports.extractFirst = void 0;
|
|
7
7
|
exports.displayVersion = displayVersion;
|
|
8
8
|
exports.displayUsage = displayUsage;
|
|
9
|
-
const
|
|
9
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
10
10
|
const package_1 = require("./package");
|
|
11
11
|
const extractFirst = (argv) => {
|
|
12
12
|
const first = argv._?.[0];
|
|
@@ -20,8 +20,8 @@ exports.extractFirst = extractFirst;
|
|
|
20
20
|
// Function to display the version information
|
|
21
21
|
function displayVersion() {
|
|
22
22
|
const pkg = (0, package_1.readAndParsePackageJson)();
|
|
23
|
-
console.log(
|
|
24
|
-
console.log(
|
|
23
|
+
console.log(yanse_1.default.green(`Name: ${pkg.name}`));
|
|
24
|
+
console.log(yanse_1.default.blue(`Version: ${pkg.version}`));
|
|
25
25
|
}
|
|
26
26
|
exports.usageText = `
|
|
27
27
|
Usage: k8s <command> [options]
|