mcp-server-kubernetes 4.2.2 → 4.2.3
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.
|
@@ -58,6 +58,12 @@ export declare class KubernetesManager {
|
|
|
58
58
|
*/
|
|
59
59
|
private hasEnvKubeconfigPath;
|
|
60
60
|
private hasEnvKubeconfig;
|
|
61
|
+
/**
|
|
62
|
+
* Load every file listed in KUBECONFIG and merge them the way kubectl does:
|
|
63
|
+
* files that do not exist are skipped, the first file to define a cluster,
|
|
64
|
+
* user or context by name wins, and the first current-context set wins.
|
|
65
|
+
*/
|
|
66
|
+
private loadEnvKubeconfigList;
|
|
61
67
|
/**
|
|
62
68
|
* Set the current context to the desired context name.
|
|
63
69
|
*
|
|
@@ -64,8 +64,9 @@ export class KubernetesManager {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
else if (this.hasEnvKubeconfig()) {
|
|
67
|
-
//
|
|
68
|
-
|
|
67
|
+
// Priority 6: KUBECONFIG, which can list several files like kubectl
|
|
68
|
+
// accepts
|
|
69
|
+
this.loadEnvKubeconfigList();
|
|
69
70
|
}
|
|
70
71
|
else {
|
|
71
72
|
// Priority 7: Default file-based configuration (existing fallback)
|
|
@@ -218,6 +219,44 @@ export class KubernetesManager {
|
|
|
218
219
|
hasEnvKubeconfig() {
|
|
219
220
|
return !!(process.env.KUBECONFIG && process.env.KUBECONFIG.trim());
|
|
220
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Load every file listed in KUBECONFIG and merge them the way kubectl does:
|
|
224
|
+
* files that do not exist are skipped, the first file to define a cluster,
|
|
225
|
+
* user or context by name wins, and the first current-context set wins.
|
|
226
|
+
*/
|
|
227
|
+
loadEnvKubeconfigList() {
|
|
228
|
+
const listed = process.env
|
|
229
|
+
.KUBECONFIG.split(path.delimiter)
|
|
230
|
+
.filter((file) => file.trim());
|
|
231
|
+
const files = listed.filter((file) => fs.existsSync(file));
|
|
232
|
+
if (files.length === 0) {
|
|
233
|
+
throw new Error(`None of the files listed in KUBECONFIG exist: ${listed.join(", ")}`);
|
|
234
|
+
}
|
|
235
|
+
this.kc.loadFromFile(files[0]);
|
|
236
|
+
for (const file of files.slice(1)) {
|
|
237
|
+
const next = new k8s.KubeConfig();
|
|
238
|
+
next.loadFromFile(file);
|
|
239
|
+
const has = (items, name) => items.some((item) => item.name === name);
|
|
240
|
+
for (const cluster of next.getClusters()) {
|
|
241
|
+
if (!has(this.kc.getClusters(), cluster.name)) {
|
|
242
|
+
this.kc.addCluster(cluster);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
for (const user of next.getUsers()) {
|
|
246
|
+
if (!has(this.kc.getUsers(), user.name)) {
|
|
247
|
+
this.kc.addUser(user);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
for (const context of next.getContexts()) {
|
|
251
|
+
if (!has(this.kc.getContexts(), context.name)) {
|
|
252
|
+
this.kc.addContext(context);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (!this.kc.getCurrentContext() && next.getCurrentContext()) {
|
|
256
|
+
this.kc.setCurrentContext(next.getCurrentContext());
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
221
260
|
/**
|
|
222
261
|
* Set the current context to the desired context name.
|
|
223
262
|
*
|