Skip to content

Commit 6ac9542

Browse files
craig[bot]shailendra-patel
andcommitted
Merge #145610
145610: drtprod: only set roachprod environment variables if not already set r=nameisbhaskar a=shailendra-patel This change modifies the environment variable initialization in the drtprod CLI to only set ROACHPROD_DNS, ROACHPROD_GCE_DNS_DOMAIN, ROACHPROD_GCE_DNS_ZONE, and ROACHPROD_GCE_DEFAULT_PROJECT if they are not already set in the environment. Previously, these variables were always overwritten, which could cause issues when users needed to use custom values. This change follows the same pattern already in place for the DD_API_KEY environment variable, providing more flexibility while maintaining the default configuration for most users. Epic: none Release note: None Co-authored-by: Shailendra Patel <[email protected]>
2 parents 9fa4a6b + 5a32e3d commit 6ac9542

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pkg/cmd/drtprod/cli/handlers.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ import (
1616
"github.com/spf13/cobra"
1717
)
1818

19+
// setEnvIfNotExists sets an environment variable only if it doesn't already exist.
20+
func setEnvIfNotExists(key, value string) {
21+
if _, exists := os.LookupEnv(key); !exists {
22+
_ = os.Setenv(key, value)
23+
}
24+
}
25+
1926
func init() {
20-
// Set environment variables for the GCE project and DNS configurations.
21-
_ = os.Setenv("ROACHPROD_DNS", "drt.crdb.io")
22-
_ = os.Setenv("ROACHPROD_GCE_DNS_DOMAIN", "drt.crdb.io")
23-
_ = os.Setenv("ROACHPROD_GCE_DNS_ZONE", "drt")
24-
_ = os.Setenv("ROACHPROD_GCE_DEFAULT_PROJECT", "cockroach-drt")
27+
// Set environment variables for the GCE project and DNS configurations if not already set.
28+
setEnvIfNotExists("ROACHPROD_DNS", "drt.crdb.io")
29+
setEnvIfNotExists("ROACHPROD_GCE_DNS_DOMAIN", "drt.crdb.io")
30+
setEnvIfNotExists("ROACHPROD_GCE_DNS_ZONE", "drt")
31+
setEnvIfNotExists("ROACHPROD_GCE_DEFAULT_PROJECT", "cockroach-drt")
2532

2633
if _, exists := os.LookupEnv("DD_API_KEY"); !exists {
2734
// set the DD_API_KEY if we are able to fetch it from the secrets.

pkg/cmd/drtprod/scripts/generate_tpcc_run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ for ((NODE=0; NODE<WORKLOAD_NODES; NODE++)); do
9999
cat <<EOF >/tmp/tpcc_run_${suffix}.sh
100100
#!/usr/bin/env bash
101101
102+
export ROACHPROD_GCE_DEFAULT_PROJECT=$ROACHPROD_GCE_DEFAULT_PROJECT
102103
./drtprod sync
103104
$([ "$execute_script" = "true" ] && [ "$NODE" -eq 0 ] && echo "${pwd}/tpcc_init_${suffix}.sh")
104105
PGURLS=\$(./drtprod load-balancer pgurl $CLUSTER | sed s/\'//g)

0 commit comments

Comments
 (0)