From 5d184822027bcda82fc57bc8b1af2c5d6af4bfc2 Mon Sep 17 00:00:00 2001 From: Enrico Candino Date: Fri, 23 Feb 2024 17:20:35 +0100 Subject: [PATCH] fix panics (#350) --- cmd/kubectl_token.go | 3 +++ cmd/server.go | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/kubectl_token.go b/cmd/kubectl_token.go index 2c297885..f27881ca 100644 --- a/cmd/kubectl_token.go +++ b/cmd/kubectl_token.go @@ -280,6 +280,9 @@ func cacheCredential(ctx *cli.Context, cred *config.ExecCredential, id string) e return err } + if sc.KubeCredentials[id] == nil { + sc.KubeCredentials = make(map[string]*config.ExecCredential) + } sc.KubeCredentials[id] = cred cf.Servers[server] = sc return cf.Write() diff --git a/cmd/server.go b/cmd/server.go index 37bc9596..ef373ac0 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -71,8 +71,12 @@ func serverCurrent(ctx *cli.Context) error { } serverName := cf.CurrentServer - URL := cf.Servers[serverName].URL - fmt.Printf("Name: %s URL: %s\n", serverName, URL) + currentServer, found := cf.Servers[serverName] + if !found { + return errors.New("Current server not set") + } + + fmt.Printf("Name: %s URL: %s\n", serverName, currentServer.URL) return nil }