-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
138711: roachprod: refactor gcp environment variable initialization r=vidit-bhat,srosenberg a=shailendra-patel Moved the initialization of default variables related to the GCP Project and DNS into the GCP provider Init function instead of initializing them during package initialization. Setting default variables as global variables caused issues when environment variables are modified before calling Init. Epic: none Release note: None Co-authored-by: Shailendra Patel <[email protected]>
- Loading branch information
Showing
4 changed files
with
20 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,12 @@ const ( | |
var providerInstance = &Provider{} | ||
|
||
var ( | ||
defaultDefaultProject, defaultMetadataProject, defaultDNSProject, defaultDefaultServiceAccount string | ||
// projects for which a cron GC job exists. | ||
projectsWithGC []string | ||
) | ||
|
||
func initGCEProjectDefaults() { | ||
defaultDefaultProject = config.EnvOrDefaultString( | ||
"ROACHPROD_GCE_DEFAULT_PROJECT", "cockroach-ephemeral", | ||
) | ||
|
@@ -80,7 +86,8 @@ var ( | |
"ROACHPROD_GCE_DEFAULT_SERVICE_ACCOUNT", | ||
"[email protected]", | ||
) | ||
) | ||
projectsWithGC = []string{defaultDefaultProject} | ||
} | ||
|
||
// DefaultProject returns the default GCE project. This is used to determine whether | ||
// certain features, such as DNS names are enabled. | ||
|
@@ -93,9 +100,6 @@ func DefaultProject() string { | |
return defaultDefaultProject | ||
} | ||
|
||
// projects for which a cron GC job exists. | ||
var projectsWithGC = []string{defaultDefaultProject} | ||
|
||
// Denotes if this provider was successfully initialized. | ||
var initialized = false | ||
|
||
|
@@ -107,6 +111,9 @@ var initialized = false | |
// Note that, when roachprod is used as a binary, the defaults for | ||
// providerInstance properties initialized here can be overriden by flags. | ||
func Init() error { | ||
initGCEProjectDefaults() | ||
initDNSDefault() | ||
|
||
providerInstance.Projects = []string{defaultDefaultProject} | ||
projectFromEnv := os.Getenv("GCE_PROJECT") | ||
if projectFromEnv != "" { | ||
|