Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-detect google-project if provider is Google and no project is su… #492

Merged
merged 2 commits into from
Mar 13, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions provider/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sort"
"strings"

"cloud.google.com/go/compute/metadata"
"github.com/linki/instrumented_http"
log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -133,6 +134,14 @@ func NewGoogleProvider(project string, domainFilter DomainFilter, zoneIDFilter Z
return nil, err
}

if project == "" {
mProject, mErr := metadata.ProjectID()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we get an error here, should we continue with an empty string as project name, or should it fail the provider setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run metadata.ProjectID() outside of GCP you SHOULD get an empty string returned - no errors should happen under normal circumstances if I understand the library correctly. But I choose to treat an error happening as we continue with an empty string and end up erroring out with the same message as would happen when no project is specified before this patch.
I'm uncertain if it would make more sense to let the process die in case of errors here. My thought was that at least this approach would make the patch non-dangerous, and see what you guys thought was best.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

if mErr == nil {
log.Infof("Google project auto-detected: %s", mProject)
project = mProject
}
}

provider := &GoogleProvider{
project: project,
domainFilter: domainFilter,
Expand Down