gcp/cloudsql: add PSC and explicit IP type support via cloud-sql-go-connector#3678
gcp/cloudsql: add PSC and explicit IP type support via cloud-sql-go-connector#3678aplr wants to merge 6 commits intogoogle:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
0e7c9ec to
a212d59
Compare
…ompatible) Add cloud.google.com/go/cloudsqlconn alongside the existing cloudsql-proxy dependency. URLOpener now accepts both a Dialer (new, supports IP type selection) and CertSource (existing, deprecated). Default URL-based access uses Dialer, preserving auto-IP setting. CertSource remains fully functional - no breaking changes. Fixes google#3670.
|
Can you run |
|
FAIL: dependencies changed; run: internal/testing/listdeps.sh > internal/testing/alldeps |
|
Still failing: Ensuring that there are no dependencies not listed in ./internal/testing/alldeps... |
Summary
Adds Private Service Connect (PSC) support and explicit IP type selection to
gocloud.dev/gcp/cloudsql,gocloud.dev/postgres/gcppostgres, andgocloud.dev/mysql/gcpmysqlby introducing thecloud.google.com/go/cloudsqlconnlibrary alongside the existingcloudsql-proxydependency.Fixes #3670.
Changes
gcp/cloudsql: addsNewDialer/NewDialerWithIAMfactory functions, aDialerSetWire provider, and anIPTypeenum (IPTypeAuto,IPTypePublic,IPTypePrivate,IPTypePSC). ExistingCertSourceSet/NewCertSource/NewCertSourceWithIAMare retained, marked deprecated.URLOpener(both packages): gains aDialer *cloudsqlconn.Dialerfield and anIPType cloudsql.IPTypefield.Dialertakes precedence overCertSourcewhen both are set. IP type can also be set per-URL via theip_typequery parameter (?ip_type=psc).postgres.Open/mysql.Openvia the registered scheme): now useDialerinternally. Functionally identical to the previous behavior —WithAutoIP()matches the legacy--auto-ipdefault.Backwards Compatibility
This change is fully backwards compatible. The
CertSource proxy.CertSourcefield is retained on bothURLOpenerstructs (marked deprecated) and continues to work exactly as before. No existing code needs to change.cloudsql-proxy v1remains a dependency for now.The default behavior for users of
postgres.Open/mysql.Openis unchanged: connections default to auto-IP selection (public if available, otherwise private).Customization Parity & One Regression
cloud-sql-go-connectoris at parity or better withcloudsql-proxy v1on every dimension:CertSourceDialercerts.NewCertSourceOpts(httpClient, ...)WithHTTPClient(client)proxy.Client.ContextDialerWithDialFunc+ per-callWithOneOffDialFuncRemoteOpts.IPAddrTypeOptsDialOption(cleaner)WithPSC()WithLazyRefresh()WithDNSResolver()proxy.Client.MaxConnectionsThe one regression:
MaxConnections— v1 enforced a hard connection limit via an atomic counter; v2 only tracks open connections informally without enforcing a cap.One subtle behavioral change in the default global opener: previously the
gcp.HTTPClient(usinggcp.DefaultTransport()) was explicitly threaded into the cert source for SQL Admin API calls. The newDialer-based opener derives an HTTP client from the token source internally. For standard GCP environments this is equivalent; users in environments with custom HTTP proxies or CA bundles who need that transport applied to SQL Admin API calls should construct theDialermanually usingcloudsqlconn.WithHTTPClient().Migration Path to
DialerTo enable PSC or explicit IP type selection, replace
CertSourcewithDialerin your setup:Direct construction:
With Wire:
Via URL (no code change):
Open Question: Drop
cloudsql-proxydependency?The current implementation keeps
cloudsql-proxy v1to avoid a breaking change. TheCertSourcefield and the legacy proxy code path remain fully functional.An alternative would be to drop
cloudsql-proxyentirely and makeDialerthe only supported path. This would be a breaking change: anyone constructingURLOpener{CertSource: ...}or usingcloudsql.NewCertSource/CertSourceSetwould need to migrate toDialer. The migration is mechanical (see above) and the functional behavior is identical by default.Arguments for keeping it (current approach):
cloudsql-proxy v1still works fine for users who don't need PSCArguments for dropping it:
Happy to go either direction based on project preference.