Skip to content

Commit 38a7582

Browse files
committed
frontend: Improve cluster metadata for UI
Signed-off-by: Vincent T <[email protected]>
1 parent dd03f04 commit 38a7582

File tree

9 files changed

+37
-2
lines changed

9 files changed

+37
-2
lines changed

backend/cmd/headlamp.go

+7
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,13 @@ func (c *HeadlampConfig) getClusters() []Cluster {
11781178
"source": context.SourceStr(),
11791179
"namespace": context.KubeContext.Namespace,
11801180
"extensions": context.KubeContext.Extensions,
1181+
"origin": map[string]interface{}{
1182+
"kubeconfig": func() string {
1183+
path, _ := c.getKubeConfigPath(context.SourceStr())
1184+
return path
1185+
}(),
1186+
},
1187+
"originalName": context.Name,
11811188
},
11821189
})
11831190
}

frontend/src/components/App/Home/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ function HomeComponent(props: HomeComponentProps) {
246246
*/
247247
function getOrigin(cluster: Cluster): string {
248248
if (cluster.meta_data?.source === 'kubeconfig') {
249-
const kubeconfigPath = process.env.KUBECONFIG ?? '~/.kube/config';
249+
const sourcePath = cluster.meta_data?.origin?.kubeconfig;
250+
const kubeconfigPath = process.env.KUBECONFIG ?? sourcePath;
250251
return `Kubeconfig: ${kubeconfigPath}`;
251252
} else if (cluster.meta_data?.source === 'dynamic_cluster') {
252253
return t('translation|Plugin');

frontend/src/components/App/Settings/SettingsCluster.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,27 @@ export default function SettingsCluster() {
314314
);
315315
}
316316

317+
// Display the original name of the cluster if it was loaded from a kubeconfig file.
318+
function ClusterName() {
319+
const originalName = clusterInfo?.meta_data?.originalName;
320+
const source = clusterInfo?.meta_data?.source;
321+
// Note: display original name is currently only supported for kubeconfig sources.
322+
const displayOriginalName = source === 'kubeconfig' && originalName;
323+
324+
return (
325+
<>
326+
<Typography>{t('translation|Name')}</Typography>
327+
{displayOriginalName && (
328+
<Typography variant="body2" color="textSecondary">
329+
{t('translation|Original name of cluster: {{ originalName }}', {
330+
originalName: originalName,
331+
})}
332+
</Typography>
333+
)}
334+
</>
335+
);
336+
}
337+
317338
return (
318339
<>
319340
<SectionBox
@@ -336,7 +357,7 @@ export default function SettingsCluster() {
336357
<NameValueTable
337358
rows={[
338359
{
339-
name: t('translation|Name'),
360+
name: <ClusterName />,
340361
value: (
341362
<TextField
342363
onChange={event => {

frontend/src/i18n/locales/de/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"Cluster Settings": "",
7474
"There seem to be no clusters configured…": "",
7575
"Cluster {{ clusterName }} does not exist. Please select a valid cluster:": "",
76+
"Original name of cluster: {{ originalName }}": "",
7677
"Cluster Settings ({{ clusterName }})": "Cluster-Einstellungen ({{ clusterName }})",
7778
"Go to cluster": "",
7879
"The current name of cluster. You can define custom modified name.": "",

frontend/src/i18n/locales/en/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"Cluster Settings": "Cluster Settings",
7474
"There seem to be no clusters configured…": "There seem to be no clusters configured…",
7575
"Cluster {{ clusterName }} does not exist. Please select a valid cluster:": "Cluster {{ clusterName }} does not exist. Please select a valid cluster:",
76+
"Original name of cluster: {{ originalName }}": "Original name of cluster: {{ originalName }}",
7677
"Cluster Settings ({{ clusterName }})": "Cluster Settings ({{ clusterName }})",
7778
"Go to cluster": "Go to cluster",
7879
"The current name of cluster. You can define custom modified name.": "The current name of cluster. You can define custom modified name.",

frontend/src/i18n/locales/es/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"Cluster Settings": "",
7474
"There seem to be no clusters configured…": "",
7575
"Cluster {{ clusterName }} does not exist. Please select a valid cluster:": "",
76+
"Original name of cluster: {{ originalName }}": "",
7677
"Cluster Settings ({{ clusterName }})": "Configuración del cluster ({{ clusterName }})",
7778
"Go to cluster": "",
7879
"The current name of cluster. You can define custom modified name.": "",

frontend/src/i18n/locales/fr/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"Cluster Settings": "",
7474
"There seem to be no clusters configured…": "",
7575
"Cluster {{ clusterName }} does not exist. Please select a valid cluster:": "",
76+
"Original name of cluster: {{ originalName }}": "",
7677
"Cluster Settings ({{ clusterName }})": "Paramètres du cluster ({{ clusterName }})",
7778
"Go to cluster": "",
7879
"The current name of cluster. You can define custom modified name.": "",

frontend/src/i18n/locales/pt/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"Cluster Settings": "",
7474
"There seem to be no clusters configured…": "",
7575
"Cluster {{ clusterName }} does not exist. Please select a valid cluster:": "",
76+
"Original name of cluster: {{ originalName }}": "",
7677
"Cluster Settings ({{ clusterName }})": "Definições do cluster ({{ clusterName }})",
7778
"Go to cluster": "",
7879
"The current name of cluster. You can define custom modified name.": "",

frontend/src/i18n/locales/zh-tw/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"Cluster Settings": "叢集設置",
7474
"There seem to be no clusters configured…": "似乎沒有配置任何叢集…",
7575
"Cluster {{ clusterName }} does not exist. Please select a valid cluster:": "叢集 {{ clusterName }} 不存在。請選擇一個有效的叢集:",
76+
"Original name of cluster: {{ originalName }}": "",
7677
"Cluster Settings ({{ clusterName }})": "叢集設置 ({{ clusterName }})",
7778
"Go to cluster": "前往叢集",
7879
"The current name of cluster. You can define custom modified name.": "叢集的當前名稱。您可以定義自定義修改名稱。",

0 commit comments

Comments
 (0)