From f2585c8c8a4cd43da87543f4e5a95b9108c253e3 Mon Sep 17 00:00:00 2001 From: Vincent T Date: Tue, 14 Oct 2025 13:07:53 -0400 Subject: [PATCH] WIP adding cluster duplicate names --- .../src/components/App/Home/ClusterTable.tsx | 2 + .../components/cluster/KubeConfigLoader.tsx | 54 +++++++++++++++++-- frontend/src/lib/k8s/index.ts | 4 ++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/App/Home/ClusterTable.tsx b/frontend/src/components/App/Home/ClusterTable.tsx index 20ed93d73a1..9e10ba77399 100644 --- a/frontend/src/components/App/Home/ClusterTable.tsx +++ b/frontend/src/components/App/Home/ClusterTable.tsx @@ -128,6 +128,8 @@ export default function ClusterTable({ * @returns A description of where the cluster is picked up from: dynamic, in-cluster, or from a kubeconfig file. */ function getOrigin(cluster: Cluster): string { + console.log('cluster data', cluster); + if (cluster?.meta_data?.source === 'kubeconfig') { const sourcePath = cluster?.meta_data?.origin?.kubeconfig; return sourcePath ? `Kubeconfig: ${sourcePath}` : 'Kubeconfig'; diff --git a/frontend/src/components/cluster/KubeConfigLoader.tsx b/frontend/src/components/cluster/KubeConfigLoader.tsx index 1dd1ed49dd9..ef3a1f01e27 100644 --- a/frontend/src/components/cluster/KubeConfigLoader.tsx +++ b/frontend/src/components/cluster/KubeConfigLoader.tsx @@ -61,7 +61,11 @@ interface kubeconfig { currentContext: string; } -function configWithSelectedClusters(config: kubeconfig, selectedClusters: string[]): kubeconfig { +function configWithSelectedClusters( + config: kubeconfig, + selectedClusters: string[], + configFileName: string +): kubeconfig { const newConfig: kubeconfig = { clusters: [], users: [], @@ -83,6 +87,14 @@ function configWithSelectedClusters(config: kubeconfig, selectedClusters: string if (!cluster) { return; } + + // Add ClusterID to meta_data + if (!cluster.cluster.meta_data) { + cluster.cluster.meta_data = {}; + } + + cluster.cluster.meta_data.ClusterID = `${configFileName}+${cluster.name}`; + clusters[cluster.name] = cluster; // Optionally add the user. @@ -95,6 +107,10 @@ function configWithSelectedClusters(config: kubeconfig, selectedClusters: string }); newConfig.clusters = Object.values(clusters); + + console.log('more all clusters:', clusters); + debugger; // <-- This will pause execution if dev tools are open + newConfig.users = Object.values(users); return newConfig; @@ -155,14 +171,34 @@ function KubeConfigLoader() { } } if (state === Step.ConfigureClusters) { - function loadClusters() { - const selectedClusterConfig = configWithSelectedClusters(fileContent, selectedClusters); - setCluster({ kubeconfig: btoa(yaml.dump(selectedClusterConfig)) }) + async function loadClusters() { + const selectedClusterConfig = configWithSelectedClusters( + fileContent, + selectedClusters, + configFileName + ); + + console.log('selectedClusterConfig:', JSON.stringify(selectedClusterConfig, null, 2)); // <-- Readable output + // debugger; // <-- This will pause execution if dev tools are open + + await setCluster({ kubeconfig: btoa(yaml.dump(selectedClusterConfig)) }) .then(res => { if (res?.clusters?.length > 0) { + console.log('READING RES FOR CLUSTER', res); + debugger; // <-- This will pause execution if dev tools are open + + // for some reason, trying to udpate the redux stateless config does not work here??? + // we run the dispatch and everything lookgs like it should fit, the console logs for the meta_data are maybe in the right place? + // - this could be an issue with the way I am injecting the meta_data clusterID above, maybe that is not the correct shape + // - also maybe the data is being rewritten? like the yaml shows it as meta_data there, but maybe it isnt a official format so it gets rewritten? + // this could maybe explain why when console logging in get origin, the cluster meta_data for ClusterID is not there + // it just says "dynamic_cluster", so maybe it is going > my injected meta_data > gets read somewhere else > rewritten to dynamic_cluster dispatch(setStatelessConfig(res)); } setState(Step.Success); + + console.log('READING RES FOR CLUSTER', res); + debugger; // <-- This will pause execution if dev tools are open }) .catch(e => { console.debug('Error setting up clusters from kubeconfig:', e); @@ -180,7 +216,13 @@ function KubeConfigLoader() { const dispatch = useDispatch(); const { t } = useTranslation(['translation']); - const onDrop = (acceptedFiles: Blob[]) => { + const [configFileName, setConfigFileName] = useState(''); + + const onDrop = (acceptedFiles: File[]) => { + if (acceptedFiles.length > 0) { + console.log('Selected file name:', acceptedFiles[0].name); + setConfigFileName(acceptedFiles[0].name); + } setError(''); const reader = new FileReader(); reader.onerror = () => setError(t("translation|Couldn't read kubeconfig file")); @@ -189,7 +231,9 @@ function KubeConfigLoader() { const data = String.fromCharCode.apply(null, [ ...new Uint8Array(reader.result as ArrayBuffer), ]); + console.log('Raw file data:', data); // <-- Add here to see the raw file contents const doc = yaml.load(data) as kubeconfig; + console.log('Parsed kubeconfig:', doc); // <-- Add here to see the parsed kubeconfig object if (!doc.clusters) { throw new Error(t('translation|No clusters found!')); } diff --git a/frontend/src/lib/k8s/index.ts b/frontend/src/lib/k8s/index.ts index bd22687c2bb..da987fb29db 100644 --- a/frontend/src/lib/k8s/index.ts +++ b/frontend/src/lib/k8s/index.ts @@ -114,6 +114,10 @@ export function useClustersConf(): ConfigState['allClusters'] { const state = useTypedSelector(state => state.config); const clusters = _.cloneDeep(state.clusters || {}); const allClusters = _.cloneDeep(state.allClusters || {}); + + console.log('clusters from redux', clusters); + console.log('allClusters from redux', allClusters); + Object.assign(allClusters, clusters); if (state.statelessClusters) {