From 90dadd0ce6cc712ffcbc114825b726f0dede2666 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Thu, 6 Aug 2020 11:47:09 -0700 Subject: [PATCH 1/3] better error messages for not finding creds --- pkg/addons/gcpauth/enable.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/addons/gcpauth/enable.go b/pkg/addons/gcpauth/enable.go index 93c7d091cf95..96e6768554cb 100644 --- a/pkg/addons/gcpauth/enable.go +++ b/pkg/addons/gcpauth/enable.go @@ -26,6 +26,7 @@ import ( "golang.org/x/oauth2/google" "k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/config" + "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/mustload" "k8s.io/minikube/pkg/minikube/out" ) @@ -57,7 +58,7 @@ func enableAddon(cfg *config.ClusterConfig) error { ctx := context.Background() creds, err := google.FindDefaultCredentials(ctx) if err != nil { - return err + exit.WithError("Could not find any GCP credentials. Either run `gcloud auth login` or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your credentials file.", err) } f := assets.NewMemoryAssetTarget(creds.JSON, credentialsPath, "0444") @@ -81,7 +82,12 @@ func enableAddon(cfg *config.ClusterConfig) error { return r.Copy(f) } - return nil + out.WarningT("Could not determine a Google Cloud project, which might be ok.") + out.WarningT("If you want it set, either set the GOOGLE_CLOUD_PROJECT environment variable or run `gcloud config set project `") + + // Copy an empty file in to avoid errors about missing files + emptyFile := assets.NewMemoryAssetTarget([]byte{}, projectPath, "0444") + return r.Copy(emptyFile) } func disableAddon(cfg *config.ClusterConfig) error { From 16ba55d05fad4c76665a035dfe7c36b0a3fb67e2 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Thu, 6 Aug 2020 12:36:54 -0700 Subject: [PATCH 2/3] better error message --- pkg/addons/gcpauth/enable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/addons/gcpauth/enable.go b/pkg/addons/gcpauth/enable.go index 96e6768554cb..fd388a10ac71 100644 --- a/pkg/addons/gcpauth/enable.go +++ b/pkg/addons/gcpauth/enable.go @@ -58,7 +58,7 @@ func enableAddon(cfg *config.ClusterConfig) error { ctx := context.Background() creds, err := google.FindDefaultCredentials(ctx) if err != nil { - exit.WithError("Could not find any GCP credentials. Either run `gcloud auth login` or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your credentials file.", err) + exit.WithCodeT(exit.Failure, "Could not find any GCP credentials. Either run `gcloud auth login` or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your credentials file.") } f := assets.NewMemoryAssetTarget(creds.JSON, credentialsPath, "0444") From 02930c0d514e48985fe2b92ea54c683a5b95e5aa Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Thu, 6 Aug 2020 13:45:46 -0700 Subject: [PATCH 3/3] fix tip output and do not output ending tip disabling --- pkg/addons/gcpauth/enable.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/addons/gcpauth/enable.go b/pkg/addons/gcpauth/enable.go index fd388a10ac71..20dd5cef2bbd 100644 --- a/pkg/addons/gcpauth/enable.go +++ b/pkg/addons/gcpauth/enable.go @@ -83,7 +83,11 @@ func enableAddon(cfg *config.ClusterConfig) error { } out.WarningT("Could not determine a Google Cloud project, which might be ok.") - out.WarningT("If you want it set, either set the GOOGLE_CLOUD_PROJECT environment variable or run `gcloud config set project `") + out.T(out.Tip, `To set your Google Cloud project, run: + + gcloud config set project + +or set the GOOGLE_CLOUD_PROJECT environment variable.`) // Copy an empty file in to avoid errors about missing files emptyFile := assets.NewMemoryAssetTarget([]byte{}, projectPath, "0444") @@ -113,7 +117,13 @@ func disableAddon(cfg *config.ClusterConfig) error { // DisplayAddonMessage display an gcp auth addon specific message to the user func DisplayAddonMessage(cfg *config.ClusterConfig, name string, val string) error { - out.T(out.Notice, "Your GCP credentials will now be mounted into every pod created in the {{.name}} cluster.", out.V{"name": cfg.Name}) - out.T(out.Notice, "If you don't want credential mounted into a specific pod, add a label with the `gcp-auth-skip-secret` key to your pod configuration.") + enable, err := strconv.ParseBool(val) + if err != nil { + return errors.Wrapf(err, "parsing bool: %s", name) + } + if enable { + out.T(out.Notice, "Your GCP credentials will now be mounted into every pod created in the {{.name}} cluster.", out.V{"name": cfg.Name}) + out.T(out.Notice, "If you don't want your credentials mounted into a specific pod, add a label with the `gcp-auth-skip-secret` key to your pod configuration.") + } return nil }