@kubernetesjs/cli 0.0.3 → 0.1.1
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 +155 -57
- 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/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Dan Lynch <pyramation@gmail.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,65 +1,163 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kubernetesjs/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"><br />
|
|
5
|
+
KubernetesJS CLI
|
|
6
|
+
</p>
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- **🔒 Fully Typed**: Complete TypeScript definitions for all functions and models for an enhanced development experience.
|
|
8
|
-
- **🚀 Zero Dependencies**: Works out of the box without the need for additional installations.
|
|
9
|
-
- **📡 Full Kubernetes API Coverage**: Supports all Kubernetes API endpoints with detailed TypeScript types.
|
|
10
|
-
- **🌐 Cross-Platform**: Works with both Node.js and browser environments.
|
|
8
|
+
A command-line interface for interacting with Kubernetes clusters, built with TypeScript.
|
|
11
9
|
|
|
12
10
|
## Installation
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
```sh
|
|
13
|
+
npm install -g @kubernetesjs/cli
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
The CLI provides several commands for managing Kubernetes resources. You can use either `k8s` or `kubernetes` as the command prefix:
|
|
15
19
|
|
|
16
|
-
```
|
|
17
|
-
|
|
20
|
+
```sh
|
|
21
|
+
k8s <command> [options]
|
|
18
22
|
# or
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
23
|
+
kubernetes <command> [options]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
- `--client-url`: Kubernetes API server URL (default: http://localhost:8001)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Available Commands
|
|
31
|
+
|
|
32
|
+
#### Get
|
|
33
|
+
Retrieve information about Kubernetes resources.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
k8s get <resource> [options]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Apply
|
|
40
|
+
Apply configurations to your Kubernetes cluster.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
k8s apply -f <file> [options]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Delete
|
|
47
|
+
Delete resources from your Kubernetes cluster.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
k8s delete <resource> <name> [options]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Describe
|
|
54
|
+
Show detailed information about a specific resource.
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
k8s describe <resource> <name> [options]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Logs
|
|
61
|
+
View logs from pods.
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
k8s logs <pod-name> [options]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### Port Forward
|
|
68
|
+
Forward ports from pods to your local machine.
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
k8s port-forward <pod-name> <local-port>:<pod-port> [options]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Exec
|
|
75
|
+
Execute commands in a container.
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
k8s exec <pod-name> -- <command> [options]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Cluster Info
|
|
82
|
+
Display information about the current cluster.
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
k8s cluster-info
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Config
|
|
89
|
+
Manage Kubernetes configuration.
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
k8s config [options]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Examples
|
|
96
|
+
|
|
97
|
+
### Get Pod Information
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
k8s get pods
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Apply a Configuration File
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
k8s apply -f deployment.yaml
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### View Pod Logs
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
k8s logs my-pod
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Port Forward to a Service
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
k8s port-forward my-pod 8080:80
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Configuration
|
|
122
|
+
|
|
123
|
+
The CLI uses the default Kubernetes configuration from `~/.kube/config`. You can specify a different configuration file using the `--kubeconfig` option.
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
When first cloning the repo:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
yarn
|
|
131
|
+
# Build the production packages
|
|
132
|
+
yarn build
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
For development with source maps:
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
yarn
|
|
139
|
+
# Build with source maps for better debugging
|
|
140
|
+
yarn build:dev
|
|
65
141
|
```
|
|
142
|
+
|
|
143
|
+
## Related
|
|
144
|
+
|
|
145
|
+
Checkout these related projects:
|
|
146
|
+
|
|
147
|
+
* [`schema-typescript`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/schema-typescript)
|
|
148
|
+
Provides robust tools for handling JSON schemas and converting them to TypeScript interfaces with ease and efficiency.
|
|
149
|
+
* [`@schema-typescript/cli`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/cli)
|
|
150
|
+
CLI is the command line utility for `schema-typescript`.
|
|
151
|
+
* [`schema-sdk`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/schema-sdk)
|
|
152
|
+
Provides robust tools for handling OpenAPI schemas and converting them to TypeScript clients with ease and efficiency.
|
|
153
|
+
* [`starship`](https://github.com/hyperweb-io/starship) Unified Testing and Development for the Interchain.
|
|
154
|
+
|
|
155
|
+
## Credits
|
|
156
|
+
|
|
157
|
+
🛠 Built by Hyperweb — if you like our tools, please checkout and contribute to [our github ⚛️](https://github.com/hyperweb-io)
|
|
158
|
+
|
|
159
|
+
## Disclaimer
|
|
160
|
+
|
|
161
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
162
|
+
|
|
163
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
|
@@ -0,0 +1,171 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
40
|
+
const kubernetesjs_1 = require("kubernetesjs");
|
|
41
|
+
const config_1 = require("../config");
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
async function promptYamlFilePath(prompter, argv) {
|
|
44
|
+
const question = {
|
|
45
|
+
type: 'text',
|
|
46
|
+
name: 'filePath',
|
|
47
|
+
message: 'Enter path to YAML file',
|
|
48
|
+
required: true
|
|
49
|
+
};
|
|
50
|
+
const { filePath } = await prompter.prompt(argv, [question]);
|
|
51
|
+
return filePath;
|
|
52
|
+
}
|
|
53
|
+
async function applyResource(client, resource, namespace) {
|
|
54
|
+
const kind = resource.kind.toLowerCase();
|
|
55
|
+
const name = resource.metadata?.name;
|
|
56
|
+
if (!name) {
|
|
57
|
+
throw new Error('Resource must have a name');
|
|
58
|
+
}
|
|
59
|
+
console.log(chalk_1.default.blue(`Applying ${kind} "${name}" in namespace ${namespace}...`));
|
|
60
|
+
try {
|
|
61
|
+
switch (kind) {
|
|
62
|
+
case 'deployment':
|
|
63
|
+
await client.createAppsV1NamespacedDeployment({
|
|
64
|
+
path: { namespace },
|
|
65
|
+
query: {
|
|
66
|
+
pretty: 'true',
|
|
67
|
+
fieldManager: 'kubernetesjs-cli'
|
|
68
|
+
},
|
|
69
|
+
body: resource
|
|
70
|
+
});
|
|
71
|
+
console.log(chalk_1.default.green(`Deployment "${name}" created/updated successfully`));
|
|
72
|
+
break;
|
|
73
|
+
case 'service':
|
|
74
|
+
await client.createCoreV1NamespacedService({
|
|
75
|
+
path: { namespace },
|
|
76
|
+
query: {
|
|
77
|
+
pretty: 'true',
|
|
78
|
+
fieldManager: 'kubernetesjs-cli'
|
|
79
|
+
},
|
|
80
|
+
body: resource
|
|
81
|
+
});
|
|
82
|
+
console.log(chalk_1.default.green(`Service "${name}" created/updated successfully`));
|
|
83
|
+
break;
|
|
84
|
+
case 'pod':
|
|
85
|
+
await client.createCoreV1NamespacedPod({
|
|
86
|
+
path: { namespace },
|
|
87
|
+
query: {
|
|
88
|
+
pretty: 'true',
|
|
89
|
+
fieldManager: 'kubernetesjs-cli'
|
|
90
|
+
},
|
|
91
|
+
body: resource
|
|
92
|
+
});
|
|
93
|
+
console.log(chalk_1.default.green(`Pod "${name}" created/updated successfully`));
|
|
94
|
+
break;
|
|
95
|
+
case 'configmap':
|
|
96
|
+
await client.createCoreV1NamespacedConfigMap({
|
|
97
|
+
path: { namespace },
|
|
98
|
+
query: {
|
|
99
|
+
pretty: 'true',
|
|
100
|
+
fieldManager: 'kubernetesjs-cli'
|
|
101
|
+
},
|
|
102
|
+
body: resource
|
|
103
|
+
});
|
|
104
|
+
console.log(chalk_1.default.green(`ConfigMap "${name}" created/updated successfully`));
|
|
105
|
+
break;
|
|
106
|
+
case 'secret':
|
|
107
|
+
await client.createCoreV1NamespacedSecret({
|
|
108
|
+
path: { namespace },
|
|
109
|
+
query: {
|
|
110
|
+
pretty: 'true',
|
|
111
|
+
fieldManager: 'kubernetesjs-cli'
|
|
112
|
+
},
|
|
113
|
+
body: resource
|
|
114
|
+
});
|
|
115
|
+
console.log(chalk_1.default.green(`Secret "${name}" created/updated successfully`));
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
console.log(chalk_1.default.yellow(`Resource kind "${kind}" not implemented yet`));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error(chalk_1.default.red(`Error applying ${kind} "${name}": ${error}`));
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.default = async (argv, prompter, _options) => {
|
|
127
|
+
try {
|
|
128
|
+
const client = new kubernetesjs_1.KubernetesClient({
|
|
129
|
+
restEndpoint: argv.clientUrl
|
|
130
|
+
});
|
|
131
|
+
const filePath = argv.f || argv._?.[0] || await promptYamlFilePath(prompter, argv);
|
|
132
|
+
if (!filePath) {
|
|
133
|
+
console.error(chalk_1.default.red('No file path provided'));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!fs.existsSync(filePath)) {
|
|
137
|
+
console.error(chalk_1.default.red(`File not found: ${filePath}`));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let resources;
|
|
141
|
+
try {
|
|
142
|
+
const content = (0, config_1.readYamlFile)(filePath);
|
|
143
|
+
if (Array.isArray(content)) {
|
|
144
|
+
resources = content;
|
|
145
|
+
}
|
|
146
|
+
else if (content.kind === 'List' && Array.isArray(content.items)) {
|
|
147
|
+
resources = content.items;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
resources = [content];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.error(chalk_1.default.red(`Error parsing YAML file: ${error}`));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
for (const resource of resources) {
|
|
158
|
+
try {
|
|
159
|
+
const namespace = resource.metadata?.namespace || argv.n || argv.namespace || 'default';
|
|
160
|
+
await applyResource(client, resource, namespace);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
console.error(chalk_1.default.red(`Failed to apply resource: ${error}`));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
console.log(chalk_1.default.green('Apply completed'));
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
console.error(chalk_1.default.red(`Error: ${error}`));
|
|
170
|
+
}
|
|
171
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const kubernetesjs_1 = require("kubernetesjs");
|
|
8
|
+
exports.default = async (_argv, _prompter, _options) => {
|
|
9
|
+
try {
|
|
10
|
+
const client = new kubernetesjs_1.KubernetesClient({
|
|
11
|
+
restEndpoint: _argv.clientUrl
|
|
12
|
+
});
|
|
13
|
+
console.log(chalk_1.default.blue('Kubernetes cluster info:'));
|
|
14
|
+
const apiVersions = await client.getAPIVersions({
|
|
15
|
+
params: {},
|
|
16
|
+
query: {}
|
|
17
|
+
});
|
|
18
|
+
console.log(chalk_1.default.bold('\nAPI Versions:'));
|
|
19
|
+
if (apiVersions.apiVersion) {
|
|
20
|
+
console.log(apiVersions.apiVersion);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error(chalk_1.default.red(`Error: ${error}`));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CLIOptions, Inquirerer } from 'inquirerer';
|
|
2
|
+
import { ParsedArgs } from 'minimist';
|
|
3
|
+
/**
|
|
4
|
+
* Handle the --config flag by parsing the YAML file and executing the appropriate command
|
|
5
|
+
* @param argv Command line arguments
|
|
6
|
+
* @param prompter Inquirerer instance
|
|
7
|
+
* @param options CLI options
|
|
8
|
+
* @param commandMap Map of available commands
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: (argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions, commandMap: Record<string, Function>) => Promise<boolean>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,81 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const config_1 = require("../config");
|
|
42
|
+
/**
|
|
43
|
+
* Handle the --config flag by parsing the YAML file and executing the appropriate command
|
|
44
|
+
* @param argv Command line arguments
|
|
45
|
+
* @param prompter Inquirerer instance
|
|
46
|
+
* @param options CLI options
|
|
47
|
+
* @param commandMap Map of available commands
|
|
48
|
+
*/
|
|
49
|
+
exports.default = async (argv, prompter, options, commandMap) => {
|
|
50
|
+
if (!argv.config) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const configPath = argv.config;
|
|
54
|
+
if (!fs.existsSync(configPath)) {
|
|
55
|
+
console.error(chalk_1.default.red(`Config file not found: ${configPath}`));
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const resource = (0, config_1.readYamlFile)(configPath);
|
|
60
|
+
const resourceType = (0, config_1.inferResourceType)(resource);
|
|
61
|
+
console.log(chalk_1.default.blue(`Detected resource type: ${resourceType}`));
|
|
62
|
+
let command;
|
|
63
|
+
command = 'apply';
|
|
64
|
+
const newArgv = {
|
|
65
|
+
...argv,
|
|
66
|
+
_: [configPath],
|
|
67
|
+
f: configPath
|
|
68
|
+
};
|
|
69
|
+
if (commandMap[command]) {
|
|
70
|
+
await commandMap[command](newArgv, prompter, options);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
console.error(chalk_1.default.red(`No command found for resource type: ${resourceType}`));
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(chalk_1.default.red(`Error processing config file: ${error}`));
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const kubernetesjs_1 = require("kubernetesjs");
|
|
8
|
+
const config_1 = require("../config");
|
|
9
|
+
async function promptNamespace(prompter, argv, client) {
|
|
10
|
+
try {
|
|
11
|
+
const namespaces = await client.listCoreV1Namespace({
|
|
12
|
+
query: {}
|
|
13
|
+
});
|
|
14
|
+
if (!namespaces.items || namespaces.items.length === 0) {
|
|
15
|
+
console.log(chalk_1.default.yellow('No namespaces found'));
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const options = namespaces.items.map(ns => ({
|
|
19
|
+
name: ns.metadata.name,
|
|
20
|
+
value: ns.metadata.name
|
|
21
|
+
}));
|
|
22
|
+
const question = {
|
|
23
|
+
type: 'autocomplete',
|
|
24
|
+
name: 'namespace',
|
|
25
|
+
message: 'Select namespace',
|
|
26
|
+
options,
|
|
27
|
+
maxDisplayLines: 10,
|
|
28
|
+
required: true
|
|
29
|
+
};
|
|
30
|
+
const { namespace } = await prompter.prompt(argv, [question]);
|
|
31
|
+
return namespace;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error(chalk_1.default.red(`Error getting namespaces: ${error}`));
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = async (argv, prompter, _options) => {
|
|
39
|
+
try {
|
|
40
|
+
const client = new kubernetesjs_1.KubernetesClient({
|
|
41
|
+
restEndpoint: argv.clientUrl
|
|
42
|
+
});
|
|
43
|
+
const subcommand = argv._?.[0];
|
|
44
|
+
if (subcommand === 'get-context') {
|
|
45
|
+
const namespace = (0, config_1.getCurrentNamespace)();
|
|
46
|
+
console.log(chalk_1.default.green(`Current namespace: ${namespace}`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (subcommand === 'set-context') {
|
|
50
|
+
if (argv.current !== true) {
|
|
51
|
+
console.error(chalk_1.default.red('Missing --current flag'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let namespace = argv.namespace;
|
|
55
|
+
if (!namespace) {
|
|
56
|
+
namespace = await promptNamespace(prompter, argv, client);
|
|
57
|
+
if (!namespace) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
(0, config_1.setCurrentNamespace)(namespace);
|
|
62
|
+
console.log(chalk_1.default.green(`Namespace set to "${namespace}"`));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
console.log(chalk_1.default.blue('Available config commands:'));
|
|
66
|
+
console.log(' get-context Display the current context');
|
|
67
|
+
console.log(' set-context --current --namespace=<namespace> Set the current namespace');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(chalk_1.default.red(`Error: ${error}`));
|
|
71
|
+
}
|
|
72
|
+
};
|