diff --git a/docs/api.md b/docs/api.md
index 5a298b67..5f1d7262 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -158,7 +158,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
-| `connectionString` _string_ | ConnectionString is the connection string for the Cloud SQL Instance
in the format `project_id:region:instance_name` | | Pattern: `^([^:]+(:[^:]+)?):([^:]+):([^:]+)$`
Required: \{\}
|
+| `connectionString` _string_ | ConnectionString is the connection string for the Cloud SQL Instance.
This may be an instance connection name in the format `project_id:region:instance_name`
or a DNS name for the instance. | | Required: \{\}
|
| `port` _integer_ | Port (optional) sets the tcp port for this instance. If not set, a value will
be automatically assigned by the operator and set as an environment variable
on all containers in the workload named according to PortEnvName. The operator will choose
a port so that it does not conflict with other ports on the workload. | | Minimum: 1
Optional: \{\}
|
| `autoIAMAuthN` _boolean_ | AutoIAMAuthN (optional) Enables IAM Authentication for this instance.
Default value is false. | | Optional: \{\}
|
| `privateIP` _boolean_ | PrivateIP (optional) Enable connection to the Cloud SQL instance's private ip for this instance.
Default value is false. | | Optional: \{\}
|
diff --git a/go.mod b/go.mod
index becab4dd..cf7d0d92 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,7 @@ module github.com/GoogleCloudPlatform/cloud-sql-proxy-operator
go 1.24.0
require (
+ cloud.google.com/go/cloudsqlconn v1.18.0
github.com/go-logr/logr v1.4.3
go.uber.org/zap v1.27.0
k8s.io/api v0.32.8
@@ -28,7 +29,7 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
- github.com/google/go-cmp v0.6.0 // indirect
+ github.com/google/go-cmp v0.7.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
@@ -42,19 +43,21 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
+ github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
+ github.com/stretchr/testify v1.10.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
- golang.org/x/net v0.30.0 // indirect
- golang.org/x/oauth2 v0.23.0 // indirect
- golang.org/x/sync v0.8.0 // indirect
- golang.org/x/sys v0.26.0 // indirect
- golang.org/x/term v0.25.0 // indirect
- golang.org/x/text v0.19.0 // indirect
- golang.org/x/time v0.7.0 // indirect
+ golang.org/x/net v0.43.0 // indirect
+ golang.org/x/oauth2 v0.30.0 // indirect
+ golang.org/x/sync v0.16.0 // indirect
+ golang.org/x/sys v0.35.0 // indirect
+ golang.org/x/term v0.34.0 // indirect
+ golang.org/x/text v0.28.0 // indirect
+ golang.org/x/time v0.12.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
- google.golang.org/protobuf v1.35.1 // indirect
+ google.golang.org/protobuf v1.36.7 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
diff --git a/go.sum b/go.sum
index 95349a7c..14034a1a 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,5 @@
+cloud.google.com/go/cloudsqlconn v1.18.0 h1:mP6TY/7I+nrnIh6vmbWCRJPxpFBZSL6AZhW6HaYC/OI=
+cloud.google.com/go/cloudsqlconn v1.18.0/go.mod h1:58bxZZ17Mz5D83ddMT8x6w56yKpcmVXyaOwGWkzGcMw=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -40,8 +42,8 @@ github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl76
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
-github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
+github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -88,8 +90,8 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
-github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
-github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
+github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
+github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -99,8 +101,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
-github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
-github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -124,42 +126,42 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
-golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
-golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
-golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
-golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
+golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
+golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
+golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
+golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
-golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
+golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
-golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
-golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
+golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
+golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
+golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
+golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
-golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
-golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
-golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
+golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
+golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
+golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
+golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
-golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
-golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
+golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
+golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
-google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
-google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
+google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A=
+google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
diff --git a/internal/api/v1/authproxyworkload_test.go b/internal/api/v1/authproxyworkload_test.go
index 41665e9f..12ff49f1 100644
--- a/internal/api/v1/authproxyworkload_test.go
+++ b/internal/api/v1/authproxyworkload_test.go
@@ -111,6 +111,30 @@ func TestAuthProxyWorkload_ValidateCreate_InstanceSpec(t *testing.T) {
}},
wantValid: false,
},
+ {
+ desc: "Valid, Instance configured with valid instance name",
+ spec: []cloudsqlapi.InstanceSpec{{
+ ConnectionString: "proj:region:db2",
+ Port: ptr(int32(5000)),
+ }},
+ wantValid: true,
+ },
+ {
+ desc: "Valid, Instance configured with domain name name",
+ spec: []cloudsqlapi.InstanceSpec{{
+ ConnectionString: "proj:region:db2",
+ Port: ptr(int32(5000)),
+ }},
+ wantValid: true,
+ },
+ {
+ desc: "Invalid, Instance configured with malformed name",
+ spec: []cloudsqlapi.InstanceSpec{{
+ ConnectionString: "bad name!",
+ Port: ptr(int32(5000)),
+ }},
+ wantValid: false,
+ },
}
for _, tc := range data {
t.Run(tc.desc, func(t *testing.T) {
diff --git a/internal/api/v1/authproxyworkload_types.go b/internal/api/v1/authproxyworkload_types.go
index 50c3035e..da93acb6 100644
--- a/internal/api/v1/authproxyworkload_types.go
+++ b/internal/api/v1/authproxyworkload_types.go
@@ -345,10 +345,10 @@ type TelemetrySpec struct {
// `{ "connectionString":"my-project:us-central1:my-db-server", "port":5000 }`
type InstanceSpec struct {
- // ConnectionString is the connection string for the Cloud SQL Instance
- // in the format `project_id:region:instance_name`
+ // ConnectionString is the connection string for the Cloud SQL Instance.
+ // This may be an instance connection name in the format `project_id:region:instance_name`
+ // or a DNS name for the instance.
//+kubebuilder:validation:Required
- //+kubebuilder:validation:Pattern:="^([^:]+(:[^:]+)?):([^:]+):([^:]+)$"
ConnectionString string `json:"connectionString,omitempty"`
// Port (optional) sets the tcp port for this instance. If not set, a value will
diff --git a/internal/api/v1/authproxyworkload_webhook.go b/internal/api/v1/authproxyworkload_webhook.go
index 3b361381..a0f323de 100644
--- a/internal/api/v1/authproxyworkload_webhook.go
+++ b/internal/api/v1/authproxyworkload_webhook.go
@@ -20,6 +20,7 @@ import (
"path"
"reflect"
+ "cloud.google.com/go/cloudsqlconn/instance"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -281,6 +282,7 @@ func validateInstances(spec *[]InstanceSpec, f *field.Path) field.ErrorList {
}
for i, inst := range *spec {
ff := f.Child(fmt.Sprintf("%d", i))
+ errs = append(errs, validateConnectionString(inst, f)...)
if inst.Port != nil {
for _, s := range apivalidation.IsValidPortNum(int(*inst.Port)) {
errs = append(errs, field.Invalid(ff.Child("port"), inst.Port, s))
@@ -311,6 +313,16 @@ func validateInstances(spec *[]InstanceSpec, f *field.Path) field.ErrorList {
return errs
}
+func validateConnectionString(inst InstanceSpec, f *field.Path) field.ErrorList {
+ if instance.IsValidDomain(inst.ConnectionString) {
+ return nil
+ }
+ if _, err := instance.ParseConnName(inst.ConnectionString); err != nil {
+ return []*field.Error{field.Invalid(f, inst.ConnectionString, "is not a valid instance connection name or dns name")}
+ }
+ return nil
+}
+
func validateEnvName(f *field.Path, envName string) field.ErrorList {
var errs field.ErrorList
if envName != "" {
diff --git a/internal/testintegration/integration_test.go b/internal/testintegration/integration_test.go
index 8c56ab1b..5d4c62da 100644
--- a/internal/testintegration/integration_test.go
+++ b/internal/testintegration/integration_test.go
@@ -84,6 +84,34 @@ func TestCreateAndDeleteResource(t *testing.T) {
}
+// newTestCaseClient Creates a new TestCaseClient providing unique namespace and
+// other default values.
+func newDomainNameTestCaseClient(name string, c client.Client) *testhelpers.TestCaseClient {
+ return &testhelpers.TestCaseClient{
+ Client: c,
+ Namespace: testhelpers.NewNamespaceName(name),
+ ConnectionString: "db.example.com",
+ }
+}
+
+func TestCreateAndDeleteDomainNameResource(t *testing.T) {
+ ctx := testintegration.TestContext()
+ tcc := newDomainNameTestCaseClient("create", defaultClient)
+ res, err := tcc.CreateResource(ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = tcc.WaitForFinalizerOnResource(ctx, res)
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = tcc.DeleteResourceAndWait(ctx, res)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+}
+
func TestModifiesNewDeployment(t *testing.T) {
ctx := testintegration.TestContext()
tcc := newTestCaseClient("modifynew", defaultClient)
diff --git a/internal/workload/podspec_updates_test.go b/internal/workload/podspec_updates_test.go
index e2237b9b..956a3cf1 100644
--- a/internal/workload/podspec_updates_test.go
+++ b/internal/workload/podspec_updates_test.go
@@ -135,52 +135,69 @@ func configureProxies(u *workload.Updater, wl *workload.PodWorkload, proxies []*
}
func TestUpdatePodWorkload(t *testing.T) {
- var (
- wantsName = "instance1"
- wantsPort int32 = 8080
- wantContainerName = "csql-default-" + wantsName
- wantsInstanceName = "project:server:db"
- wantsInstanceArg = fmt.Sprintf("%s?port=%d", wantsInstanceName, wantsPort)
- u = workload.NewUpdater("cloud-sql-proxy-operator/dev", workload.DefaultProxyImage, false)
- )
- var err error
+ tcs := []struct {
+ name string
+ wantsName string
+ wantsPort int32
+ wantsInstanceName string
+ }{{
+ name: "WithInstanceConnectionString",
+ wantsName: "instance1",
+ wantsPort: int32(8080),
+ wantsInstanceName: "project:server:db",
+ }, {
+ name: "WithDnsNameString",
+ wantsName: "instance1",
+ wantsPort: int32(8080),
+ wantsInstanceName: "db.example.com",
+ },
+ }
+ for _, tc := range tcs {
+ t.Run(tc.name, func(t *testing.T) {
+ u := workload.NewUpdater("cloud-sql-proxy-operator/dev", workload.DefaultProxyImage, false)
+ wantsContainerName := "csql-default-" + tc.wantsName
+ wantsInstanceArg := fmt.Sprintf("%s?port=%d", tc.wantsInstanceName, tc.wantsPort)
- // Create a pod
- wl := podWorkload()
+ var err error
- // ensure that the deployment only has one container before
- // updating the deployment.
- if len(wl.Pod.Spec.Containers) != 1 {
- t.Fatalf("got %v, wants 1. deployment containers length", len(wl.Pod.Spec.Containers))
- }
+ // Create a pod
+ wl := podWorkload()
- // Create a AuthProxyWorkload that matches the deployment
- proxy := simpleAuthProxy(wantsName, wantsInstanceName)
- proxy.Spec.Instances[0].Port = ptr(wantsPort)
+ // ensure that the deployment only has one container before
+ // updating the deployment.
+ if len(wl.Pod.Spec.Containers) != 1 {
+ t.Fatalf("got %v, wants 1. deployment containers length", len(wl.Pod.Spec.Containers))
+ }
- // Update the container with new markWorkloadNeedsUpdate
- err = configureProxies(u, wl, []*cloudsqlapi.AuthProxyWorkload{proxy})
- if err != nil {
- t.Fatal(err)
- }
+ // Create a AuthProxyWorkload that matches the deployment
+ proxy := simpleAuthProxy(tc.wantsName, tc.wantsInstanceName)
+ proxy.Spec.Instances[0].Port = ptr(tc.wantsPort)
- // test that there are now 2 containers
- if want, got := 2, len(wl.Pod.Spec.Containers); want != got {
- t.Fatalf("got %v want %v, number of deployment containers", got, want)
- }
+ // Update the container with new markWorkloadNeedsUpdate
+ err = configureProxies(u, wl, []*cloudsqlapi.AuthProxyWorkload{proxy})
+ if err != nil {
+ t.Fatal(err)
+ }
- t.Logf("Containers: {%v}", wl.Pod.Spec.Containers)
+ // test that there are now 2 containers
+ if want, got := 2, len(wl.Pod.Spec.Containers); want != got {
+ t.Fatalf("got %v want %v, number of deployment containers", got, want)
+ }
- // test that the container has the proper name following the conventions
- foundContainer, err := findContainer(wl, wantContainerName)
- if err != nil {
- t.Fatal(err)
- }
+ t.Logf("Containers: {%v}", wl.Pod.Spec.Containers)
- // test that the container args have the expected args
- if gotArg, err := hasArg(wl, wantContainerName, wantsInstanceArg); err != nil || !gotArg {
- t.Errorf("wants connection string arg %v but it was not present in proxy container args %v",
- wantsInstanceArg, foundContainer.Args)
+ // test that the container has the proper name following the conventions
+ foundContainer, err := findContainer(wl, wantsContainerName)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // test that the container args have the expected args
+ if gotArg, err := hasArg(wl, wantsContainerName, wantsInstanceArg); err != nil || !gotArg {
+ t.Errorf("wants connection string arg %v but it was not present in proxy container args %v",
+ wantsInstanceArg, foundContainer.Args)
+ }
+ })
}
}