diff --git a/cmd/root.go b/cmd/root.go index c7a489ef6..4808832d5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -527,6 +527,10 @@ CPU may be throttled and a background refresh cannot run reliably against all specified instances. If an instance is unreachable, the Proxy exits with a failure status code.`) + localFlags.BoolVar(&c.conf.SkipFailedInstanceConfig, "skip-failed-instance-config", false, + `If set, the Proxy will skip any instances that are invalid/unreachable ( +only applicable to Unix sockets)`) + // Global and per instance flags localFlags.StringVarP(&c.conf.Addr, "address", "a", "127.0.0.1", "(*) Address to bind Cloud SQL instance listeners.") diff --git a/docs/cmd/cloud-sql-proxy.md b/docs/cmd/cloud-sql-proxy.md index 4c6b48b19..852d7fb57 100644 --- a/docs/cmd/cloud-sql-proxy.md +++ b/docs/cmd/cloud-sql-proxy.md @@ -277,6 +277,8 @@ cloud-sql-proxy INSTANCE_CONNECTION_NAME... [flags] --run-connection-test Runs a connection test against all specified instances. If an instance is unreachable, the Proxy exits with a failure status code. + --skip-failed-instance-config If set, the Proxy will skip any instances that are invalid/unreachable ( + only applicable to Unix sockets) --sqladmin-api-endpoint string API endpoint for all Cloud SQL Admin API requests. (default: https://sqladmin.googleapis.com) -l, --structured-logs Enable structured logging with LogEntry format --telemetry-prefix string Prefix for Cloud Monitoring metrics. diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index e242d1c05..ac4aae83b 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -267,6 +267,11 @@ type Config struct { // RunConnectionTest determines whether the Proxy should attempt a connection // to all specified instances to verify the network path is valid. RunConnectionTest bool + + // SkipFailedInstanceConfig determines whether the Proxy should skip failed + // connections to Cloud SQL instances instead of exiting on startup. + // This only applies to Unix sockets. + SkipFailedInstanceConfig bool } // dialOptions interprets appropriate dial options for a particular instance @@ -546,6 +551,11 @@ func NewClient(ctx context.Context, d cloudsql.Dialer, l cloudsql.Logger, conf * for _, inst := range conf.Instances { m, err := c.newSocketMount(ctx, conf, pc, inst) if err != nil { + if conf.SkipFailedInstanceConfig { + l.Errorf("[%v] Unable to mount socket: %v (skipped due to skip-failed-instance-config flag)", inst.Name, err) + continue + } + for _, m := range mnts { mErr := m.Close() if mErr != nil { diff --git a/internal/proxy/proxy_test.go b/internal/proxy/proxy_test.go index 0faac73a3..e014ac644 100644 --- a/internal/proxy/proxy_test.go +++ b/internal/proxy/proxy_test.go @@ -309,6 +309,20 @@ func TestClientInitialization(t *testing.T) { filepath.Join(testUnixSocketPathPg), }, }, + { + desc: "with Unix socket and two instances, one invalid but skipped", + in: &proxy.Config{ + UnixSocket: testDir, + Instances: []proxy.InstanceConnConfig{ + {Name: pg}, + {Name: "proj:region:fakeserver"}, + }, + SkipFailedInstanceConfig: true, + }, + wantUnixAddrs: []string{ + filepath.Join(testDir, pg, ".s.PGSQL.5432"), + }, + }, { desc: "with TCP port for non functional instance", in: &proxy.Config{ diff --git a/migration-guide.md b/migration-guide.md index a830b2797..1bc0dfc9f 100644 --- a/migration-guide.md +++ b/migration-guide.md @@ -144,29 +144,29 @@ The following table lists in alphabetical order v1 flags and their v2 version. - ❌: Not supported in V2 - 🤔: Unplanned, but has open feature request -| v1 | v2 | Notes | -| --------------------------- | --------------------- | ------------------------------------------------------------------------------------ | -| check_region | ❌ | | -| credential_file | credentials-file | | -| dir | unix-socket | | -| enable_iam_login | auto-iam-authn | | -| fd_rlimit | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1258) | -| fuse | fuse | | -| fuse_tmp | fuse-temp-dir | | -| health_check_port | http-port | Use --http-address=0.0.0.0 when using a health check in Kubernetes | -| host | sqladmin-api-endpoint | | -| instances_metadata | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1259) | -| ip_address_types | private-ip | Defaults to public. To connect to a private IP, you must add the --private-ip flag | -| log_debug_stdout | ❌ | v2 logs to stdout, errors to stderr by default | -| max_connections | max-connections | | -| projects | ❌ | v2 prefers explicit connection configuration to avoid user error | -| quiet | quiet | quiet disables all logging except errors | -| quota_project | quota-project | | -| refresh_config_throttle | ❌ | | -| skip_failed_instance_config | ❌ | This flag was only necessary with Unix sockets. Use TCP sockets to avoid failed startup. | -| structured_logs | structured-logs | | -| term_timeout | max-sigterm-delay | | -| token | token | | -| use_http_health_check | health-check | | -| verbose | ❌ | | -| version | version | | +| v1 | v2 | Notes | +| --------------------------- | --------------------------- | ------------------------------------------------------------------------------------ | +| check_region | ❌ | | +| credential_file | credentials-file | | +| dir | unix-socket | | +| enable_iam_login | auto-iam-authn | | +| fd_rlimit | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1258) | +| fuse | fuse | | +| fuse_tmp | fuse-temp-dir | | +| health_check_port | http-port | Use --http-address=0.0.0.0 when using a health check in Kubernetes | +| host | sqladmin-api-endpoint | | +| instances_metadata | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1259) | +| ip_address_types | private-ip | Defaults to public. To connect to a private IP, you must add the --private-ip flag | +| log_debug_stdout | ❌ | v2 logs to stdout, errors to stderr by default | +| max_connections | max-connections | | +| projects | ❌ | v2 prefers explicit connection configuration to avoid user error | +| quiet | quiet | quiet disables all logging except errors | +| quota_project | quota-project | | +| refresh_config_throttle | ❌ | | +| skip_failed_instance_config | skip-failed-instance-config | | +| structured_logs | structured-logs | | +| term_timeout | max-sigterm-delay | | +| token | token | | +| use_http_health_check | health-check | | +| verbose | ❌ | | +| version | version | |