Skip to content

Commit

Permalink
fix: issue with getting token causing a panic instead of error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Vafilor committed Apr 27, 2021
1 parent 38bebe6 commit 8ff71d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 7 additions & 2 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ var tokenCmd = &cobra.Command{
Long: "Get a token for a given provider. Google Cloud Platform is different from minikube, for example.",
Example: "auth token",
Run: func(cmd *cobra.Command, args []string) {
config := util.NewConfig()
config, err := util.NewConfig()
if err != nil {
fmt.Printf("Error getting kubernetes configuration: %v", err.Error())
return
}

if ServiceAccountName == "" {
ServiceAccountName = "admin"
}
Expand Down Expand Up @@ -60,7 +65,7 @@ var tokenCmd = &cobra.Command{
}

if *provider == "microk8s" {
fmt.Printf("Unable to connect to cluster. Make sure you are running with \nKUBECONFIG=./kubeconfig opctl auth token\nError: %v", err.Error())
fmt.Printf("Make sure you are running with \nKUBECONFIG=./kubeconfig opctl auth token\nError: %v", err.Error())
return
}

Expand Down
7 changes: 2 additions & 5 deletions util/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ import (

type Config = restclient.Config

func NewConfig() (config *Config) {
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
func NewConfig() (config *Config, err error) {
config, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(), &clientcmd.ConfigOverrides{}).ClientConfig()
if err != nil {
panic(err)
}

return
}
Expand Down

0 comments on commit 8ff71d6

Please sign in to comment.