Merge pull request #8932 from sharifelgamal/gcpauth-warning
GCP Auth Addon: Exit with better error messagespull/8935/head
commit
4f8a649de2
|
@ -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.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")
|
||||
|
@ -81,7 +82,16 @@ 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.T(out.Tip, `To set your Google Cloud project, run:
|
||||
|
||||
gcloud config set project <project name>
|
||||
|
||||
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")
|
||||
return r.Copy(emptyFile)
|
||||
}
|
||||
|
||||
func disableAddon(cfg *config.ClusterConfig) error {
|
||||
|
@ -107,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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue