allow tests to pass with dummy creds

pull/10853/head
Sharif Elgamal 2021-03-23 14:41:04 -07:00
parent 020c2f102e
commit 36deb4cb06
2 changed files with 37 additions and 31 deletions

View File

@ -60,7 +60,7 @@ func enableOrDisableGCPAuth(cfg *config.ClusterConfig, name string, val string)
func enableAddonGCPAuth(cfg *config.ClusterConfig) error {
if !Force && detect.IsOnGCE() {
exit.Message(reason.InternalCredsNotFound, "It seems that you are running in GCE, which means authentication should work without the GCP Auth addon. If you would still like to authenticate using a credentials file, use the --force flag.")
exit.Message(reason.InternalCredsNotNeeded, "It seems that you are running in GCE, which means authentication should work without the GCP Auth addon. If you would still like to authenticate using a credentials file, use the --force flag.")
}
// Grab command runner from running cluster
@ -88,10 +88,14 @@ func enableAddonGCPAuth(cfg *config.ClusterConfig) error {
return err
}
// Force here will allow tests to pass with false credentials
token, err := creds.TokenSource.Token()
if err != nil {
if err != nil && !Force {
return err
}
// Only try to add secret if Token was found
if err == nil {
data := map[string][]byte{
".dockercfg": []byte(fmt.Sprintf(`{"https://gcr.io":{"username":"oauth2accesstoken","password":"%s","email":"none"}}`, token.AccessToken)),
}
@ -134,6 +138,7 @@ func enableAddonGCPAuth(cfg *config.ClusterConfig) error {
}
}
}
// First check if the project env var is explicitly set
projectEnv := os.Getenv("GOOGLE_CLOUD_PROJECT")

View File

@ -120,6 +120,7 @@ var (
InternalViewTmpl = Kind{ID: "MK_VIEW_TMPL", ExitCode: ExProgramError}
InternalYamlMarshal = Kind{ID: "MK_YAML_MARSHAL", ExitCode: ExProgramError}
InternalCredsNotFound = Kind{ID: "MK_CREDENTIALS_NOT_FOUND", ExitCode: ExProgramNotFound, Style: style.Shrug}
InternalCredsNotNeeded = Kind{ID: "MK_CREDENTIALS_NOT_NEEDED", ExitCode: ExProgramNotFound, Style: style.Shrug}
InternalSemverParse = Kind{ID: "MK_SEMVER_PARSE", ExitCode: ExProgramError}
DaemonizeError = Kind{ID: "MK_DAEMONIZE", ExitCode: ExProgramError}