Skip to content

Commit bde7871

Browse files
authored
Merge pull request GoogleCloudPlatform#145 from ceocoder/use_INSTANCES_flag
cmd: use INSTANCES env var
2 parents 6f4ac91 + 025b8c3 commit bde7871

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ cloud_sql_proxy takes a few arguments to configure:
2020
directory indicated by `-dir` is mounted.
2121
* `-instances="project1:region:instance1,project3:region:instance1"`: A comma-separated list
2222
of instances to open inside `-dir`. Also supports exposing a tcp port instead of using Unix Domain Sockets; see examples below.
23+
Same list can be provided via INSTANCES environment variable, in case when both are provided - proxy will use command line flag.
2324
* `-instances_metadata=metadata_key`: Usable on [GCE](https://cloud.google.com/compute/docs/quickstart) only. The given [GCE metadata](https://cloud.google.com/compute/docs/metadata) key will be
2425
polled for a list of instances to open in `-dir`. The format for the value is the same as the 'instances' flag. A hanging-poll strategy is used, meaning that changes to
2526
the metadata value will be reflected in the `-dir` even while the proxy is

cmd/cloud_sql_proxy/cloud_sql_proxy.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Unix socket-based connections.`)
6363
instances = flag.String("instances", "", `Comma-separated list of fully qualified instances (project:region:name)
6464
to connect to. If the name has the suffix '=tcp:port', a TCP server is opened
6565
on the specified port to proxy to that instance. Otherwise, one socket file per
66-
instance is opened in 'dir'. Not compatible with -fuse`)
66+
instance is opened in 'dir'. You may use INSTANCES environment variable
67+
for the same effect. Using both will use value from flag, Not compatible with -fuse`)
6768
instanceSrc = flag.String("instances_metadata", "", `If provided, it is treated as a path to a metadata value which
6869
is polled for a comma-separated list of instances to connect to. For example,
6970
to use the instance metadata value named 'cloud-sql-instances' you would
@@ -138,6 +139,9 @@ Connection:
138139
139140
When connecting over TCP, the -instances parameter is required.
140141
142+
Supplying INSTANCES environment variable achieves the same effect. One can
143+
use that to keep k8s manifest files constant across multiple environments
144+
141145
-instances_metadata
142146
When running on GCE (Google Compute Engine) you can avoid the need to
143147
specify the list of instances on the command line by using the Metadata
@@ -388,6 +392,12 @@ func main() {
388392
log.SetOutput(ioutil.Discard)
389393
}
390394

395+
// TODO: needs a better place for consolidation
396+
// if instances is blank and env var INSTANCES is supplied use it
397+
if envInstances := os.Getenv("INSTANCES"); *instances == "" && envInstances != "" {
398+
*instances = envInstances
399+
}
400+
391401
instList := stringList(*instances)
392402
projList := stringList(*projects)
393403
// TODO: it'd be really great to consolidate flag verification in one place.

0 commit comments

Comments
 (0)