Skip to content

Conversation

ianis-c
Copy link

@ianis-c ianis-c commented Jun 25, 2025

Issue #, if available:
No linked issue.

Description of changes:
This feature retrieve and show the current EKS cluster being shown in the eks-node-viewer main UI.
It can be useful when working with more than one cluster (one or more clusters per environment for example).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ianis-c ianis-c requested a review from a team as a code owner June 25, 2025 12:00
@ianis-c ianis-c requested a review from tzneal June 25, 2025 18:22
@ianis-c
Copy link
Author

ianis-c commented Jul 4, 2025

Hi @tzneal, do you think this feature could be integrated ?

kubeconfig = "~/.kube/config"
}

out, err := exec.Command("kubectl", "config", "current-context", "--kubeconfig", kubeconfig).Output()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to pull this from the kubeconfig file, I would greatly prefer that to running the kubectl binary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, would be better to just parse the json config file. I'll do that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get it via something like this:

-func getConfig(kubeconfig, context string) (*rest.Config, error) {
-	// use the current context in kubeconfig
-	return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
+func getConfig(kubeconfig, context string) (string, *rest.Config, error) {
+	loadCfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
 		&clientcmd.ClientConfigLoadingRules{Precedence: strings.Split(kubeconfig, ":")},
-		&clientcmd.ConfigOverrides{CurrentContext: context}).ClientConfig()
+		&clientcmd.ConfigOverrides{CurrentContext: context})
+	raw, err := loadCfg.RawConfig()
+	if err != nil {
+		return "", nil, err
+	}
+	cfg, err := loadCfg.ClientConfig()
+	if err != nil {
+		return "", nil, err
+	}
+	return raw.CurrentContext, cfg, err
 }

@@ -88,6 +88,10 @@ func (u *UIModel) View() string {
})

ctw := text.NewColorTabWriter(&b, 0, 8, 1)

fmt.Fprintln(&b, "Viewing cluster: ", u.cluster.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think taking up a new line on the screen is too much, can it be fit anywhere else? Maybe after the "q: quit" message?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in my use case it's a pretty important information thanks why I put it up but I can move it bottom under the controls description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants