Add application migration workflow.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import * as k8s from '@kubernetes/client-node';
|
||||
|
||||
function normalizeNoProxyValue(value?: string): string[] {
|
||||
return (value || '')
|
||||
.split(',')
|
||||
.map((entry) => entry.trim().replace(/^['"]|['"]$/g, ''))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function appendNoProxyEntries(envKey: 'NO_PROXY' | 'no_proxy', entries: string[]): void {
|
||||
const existing = normalizeNoProxyValue(process.env[envKey]);
|
||||
if (existing.includes('*')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const merged = new Set(existing);
|
||||
for (const entry of entries) {
|
||||
merged.add(entry);
|
||||
}
|
||||
|
||||
process.env[envKey] = Array.from(merged).join(',');
|
||||
}
|
||||
|
||||
export function registerKubeconfigNoProxy(kubeconfig: string): string[] {
|
||||
const kc = new k8s.KubeConfig();
|
||||
kc.loadFromString(kubeconfig);
|
||||
|
||||
const cluster = kc.getCurrentCluster() || kc.getClusters()[0];
|
||||
if (!cluster?.server) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const url = new URL(cluster.server);
|
||||
const entries = new Set<string>();
|
||||
entries.add(url.hostname);
|
||||
entries.add(url.host);
|
||||
|
||||
appendNoProxyEntries('NO_PROXY', Array.from(entries));
|
||||
appendNoProxyEntries('no_proxy', Array.from(entries));
|
||||
|
||||
return Array.from(entries);
|
||||
}
|
||||
Reference in New Issue
Block a user