Skip to content

Commit ea041cb

Browse files
Merge pull request #1142 from openshift-bot/synchronize-upstream
NO-ISSUE: Synchronize From Upstream Repositories
2 parents 0f36599 + 3cb424a commit ea041cb

File tree

17 files changed

+377
-87
lines changed

17 files changed

+377
-87
lines changed

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/openshift/operator-framework-olm
22

3-
go 1.24.4
3+
go 1.24.6
44

55
require (
66
github.com/blang/semver/v4 v4.0.0
@@ -13,7 +13,7 @@ require (
1313
github.com/mikefarah/yq/v3 v3.0.0-20201202084205-8846255d1c37
1414
github.com/onsi/ginkgo/v2 v2.27.2
1515
github.com/openshift/api v0.0.0-20251023193535-8691c3014652
16-
github.com/operator-framework/api v0.35.0
16+
github.com/operator-framework/api v0.36.0
1717
github.com/operator-framework/operator-lifecycle-manager v0.0.0-00010101000000-000000000000
1818
github.com/operator-framework/operator-registry v1.60.0
1919
github.com/sirupsen/logrus v1.9.3
@@ -28,7 +28,7 @@ require (
2828
k8s.io/code-generator v0.34.1
2929
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b
3030
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
31-
sigs.k8s.io/controller-runtime v0.22.3
31+
sigs.k8s.io/controller-runtime v0.22.4
3232
sigs.k8s.io/controller-tools v0.19.0
3333
)
3434

@@ -50,7 +50,7 @@ require (
5050
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
5151
github.com/cespare/xxhash/v2 v2.3.0 // indirect
5252
github.com/containerd/cgroups/v3 v3.0.5 // indirect
53-
github.com/containerd/containerd v1.7.28 // indirect
53+
github.com/containerd/containerd v1.7.29 // indirect
5454
github.com/containerd/containerd/api v1.9.0 // indirect
5555
github.com/containerd/continuity v0.4.5 // indirect
5656
github.com/containerd/errdefs v1.0.0 // indirect
@@ -156,7 +156,7 @@ require (
156156
github.com/proglottis/gpgme v0.1.5 // indirect
157157
github.com/prometheus/client_golang v1.23.2 // indirect
158158
github.com/prometheus/client_model v0.6.2 // indirect
159-
github.com/prometheus/common v0.67.1 // indirect
159+
github.com/prometheus/common v0.67.2 // indirect
160160
github.com/prometheus/procfs v0.16.1 // indirect
161161
github.com/rivo/uniseg v0.4.7 // indirect
162162
github.com/russross/blackfriday/v2 v2.1.0 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
6464
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
6565
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
6666
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
67-
github.com/containerd/containerd v1.7.28 h1:Nsgm1AtcmEh4AHAJ4gGlNSaKgXiNccU270Dnf81FQ3c=
68-
github.com/containerd/containerd v1.7.28/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
67+
github.com/containerd/containerd v1.7.29 h1:90fWABQsaN9mJhGkoVnuzEY+o1XDPbg9BTC9QTAHnuE=
68+
github.com/containerd/containerd v1.7.29/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
6969
github.com/containerd/containerd/api v1.9.0 h1:HZ/licowTRazus+wt9fM6r/9BQO7S0vD5lMcWspGIg0=
7070
github.com/containerd/containerd/api v1.9.0/go.mod h1:GhghKFmTR3hNtyznBoQ0EMWr9ju5AqHjcZPsSpTKutI=
7171
github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=
@@ -511,8 +511,8 @@ github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvM
511511
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
512512
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
513513
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
514-
github.com/prometheus/common v0.67.1 h1:OTSON1P4DNxzTg4hmKCc37o4ZAZDv0cfXLkOt0oEowI=
515-
github.com/prometheus/common v0.67.1/go.mod h1:RpmT9v35q2Y+lsieQsdOh5sXZ6ajUGC8NjZAmr8vb0Q=
514+
github.com/prometheus/common v0.67.2 h1:PcBAckGFTIHt2+L3I33uNRTlKTplNzFctXcWhPyAEN8=
515+
github.com/prometheus/common v0.67.2/go.mod h1:63W3KZb1JOKgcjlIr64WW/LvFGAqKPj0atm+knVGEko=
516516
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
517517
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
518518
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
@@ -1026,8 +1026,8 @@ oras.land/oras-go/v2 v2.6.0 h1:X4ELRsiGkrbeox69+9tzTu492FMUu7zJQW6eJU+I2oc=
10261026
oras.land/oras-go/v2 v2.6.0/go.mod h1:magiQDfG6H1O9APp+rOsvCPcW1GD2MM7vgnKY0Y+u1o=
10271027
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0 h1:qPrZsv1cwQiFeieFlRqT627fVZ+tyfou/+S5S0H5ua0=
10281028
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
1029-
sigs.k8s.io/controller-runtime v0.22.3 h1:I7mfqz/a/WdmDCEnXmSPm8/b/yRTy6JsKKENTijTq8Y=
1030-
sigs.k8s.io/controller-runtime v0.22.3/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
1029+
sigs.k8s.io/controller-runtime v0.22.4 h1:GEjV7KV3TY8e+tJ2LCTxUTanW4z/FmNB7l327UfMq9A=
1030+
sigs.k8s.io/controller-runtime v0.22.4/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
10311031
sigs.k8s.io/controller-tools v0.19.0 h1:OU7jrPPiZusryu6YK0jYSjPqg8Vhf8cAzluP9XGI5uk=
10321032
sigs.k8s.io/controller-tools v0.19.0/go.mod h1:y5HY/iNDFkmFla2CfQoVb2AQXMsBk4ad84iR1PLANB0=
10331033
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=

staging/api/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/operator-framework/api
22

3-
go 1.24.4
3+
go 1.24.6
44

55
require (
66
github.com/blang/semver/v4 v4.0.0
@@ -14,7 +14,7 @@ require (
1414
k8s.io/apiextensions-apiserver v0.34.1
1515
k8s.io/apimachinery v0.34.1
1616
k8s.io/client-go v0.34.1
17-
sigs.k8s.io/controller-runtime v0.22.1
17+
sigs.k8s.io/controller-runtime v0.22.3
1818
sigs.k8s.io/yaml v1.6.0
1919
)
2020

staging/api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8
263263
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
264264
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0 h1:qPrZsv1cwQiFeieFlRqT627fVZ+tyfou/+S5S0H5ua0=
265265
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
266-
sigs.k8s.io/controller-runtime v0.22.1 h1:Ah1T7I+0A7ize291nJZdS1CabF/lB4E++WizgV24Eqg=
267-
sigs.k8s.io/controller-runtime v0.22.1/go.mod h1:FwiwRjkRPbiN+zp2QRp7wlTCzbUXxZ/D4OzuQUDwBHY=
266+
sigs.k8s.io/controller-runtime v0.22.3 h1:I7mfqz/a/WdmDCEnXmSPm8/b/yRTy6JsKKENTijTq8Y=
267+
sigs.k8s.io/controller-runtime v0.22.3/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
268268
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
269269
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
270270
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=

staging/operator-lifecycle-manager/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/operator-framework/operator-lifecycle-manager
22

3-
go 1.24.4
3+
go 1.24.6
44

55
require (
66
github.com/blang/semver/v4 v4.0.0
@@ -21,13 +21,13 @@ require (
2121
github.com/onsi/gomega v1.38.2
2222
github.com/openshift/api v0.0.0-20221021112143-4226c2167e40
2323
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a
24-
github.com/operator-framework/api v0.35.0
24+
github.com/operator-framework/api v0.36.0
2525
github.com/operator-framework/operator-registry v1.60.0
2626
github.com/otiai10/copy v1.14.1
2727
github.com/pkg/errors v0.9.1
2828
github.com/prometheus/client_golang v1.23.2
2929
github.com/prometheus/client_model v0.6.2
30-
github.com/prometheus/common v0.67.1
30+
github.com/prometheus/common v0.67.2
3131
github.com/sirupsen/logrus v1.9.3
3232
github.com/spf13/cobra v1.10.1
3333
github.com/spf13/pflag v1.0.10
@@ -50,7 +50,7 @@ require (
5050
k8s.io/kube-aggregator v0.34.1
5151
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b
5252
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
53-
sigs.k8s.io/controller-runtime v0.22.3
53+
sigs.k8s.io/controller-runtime v0.22.4
5454
sigs.k8s.io/controller-tools v0.19.0
5555
)
5656

@@ -67,7 +67,7 @@ require (
6767
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
6868
github.com/cespare/xxhash/v2 v2.3.0 // indirect
6969
github.com/containerd/cgroups/v3 v3.0.5 // indirect
70-
github.com/containerd/containerd v1.7.28 // indirect
70+
github.com/containerd/containerd v1.7.29 // indirect
7171
github.com/containerd/containerd/api v1.9.0 // indirect
7272
github.com/containerd/continuity v0.4.5 // indirect
7373
github.com/containerd/errdefs v1.0.0 // indirect

staging/operator-lifecycle-manager/go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
9090
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
9191
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
9292
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
93-
github.com/containerd/containerd v1.7.28 h1:Nsgm1AtcmEh4AHAJ4gGlNSaKgXiNccU270Dnf81FQ3c=
94-
github.com/containerd/containerd v1.7.28/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
93+
github.com/containerd/containerd v1.7.29 h1:90fWABQsaN9mJhGkoVnuzEY+o1XDPbg9BTC9QTAHnuE=
94+
github.com/containerd/containerd v1.7.29/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
9595
github.com/containerd/containerd/api v1.9.0 h1:HZ/licowTRazus+wt9fM6r/9BQO7S0vD5lMcWspGIg0=
9696
github.com/containerd/containerd/api v1.9.0/go.mod h1:GhghKFmTR3hNtyznBoQ0EMWr9ju5AqHjcZPsSpTKutI=
9797
github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=
@@ -484,8 +484,8 @@ github.com/openshift/api v0.0.0-20221021112143-4226c2167e40/go.mod h1:aQ6LDasvHM
484484
github.com/openshift/build-machinery-go v0.0.0-20211213093930-7e33a7eb4ce3/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
485485
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a h1:ylsEgoC8Dlg4A0C1TLH0A4x/TZao7k1YveLwROhRUdk=
486486
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a/go.mod h1:eDO5QeVi2IiXmDwB0e2z1DpAznWroZKe978pzZwFBzg=
487-
github.com/operator-framework/api v0.35.0 h1:xKrffuGEagk3CWy6zqdK5YmIErlBtWUblNNK+q7ld7c=
488-
github.com/operator-framework/api v0.35.0/go.mod h1:A9UNu/pdcO1RauMHvV54unp4DNm/Y5fMVbGDpnIIF+M=
487+
github.com/operator-framework/api v0.36.0 h1:6+duRhamCvB540JbvNp/1+Pot7luff7HqdAOm9bAntg=
488+
github.com/operator-framework/api v0.36.0/go.mod h1:QSmHMx8XpGsNWvjU5CUelVZC916VLp/TZhfYvGKpghM=
489489
github.com/operator-framework/operator-registry v1.60.0 h1:eUP14WThVTNx+/5hQR9Jyg0nxbf5cOg7hK/GgaOA5Tg=
490490
github.com/operator-framework/operator-registry v1.60.0/go.mod h1:PojPivJbKZgD9RG77JWxFpQRo3iCoUn6WR3aTiS6HBI=
491491
github.com/otiai10/copy v1.14.1 h1:5/7E6qsUMBaH5AnQ0sSLzzTg1oTECmcCmT6lvF45Na8=
@@ -505,8 +505,8 @@ github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UH
505505
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
506506
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
507507
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
508-
github.com/prometheus/common v0.67.1 h1:OTSON1P4DNxzTg4hmKCc37o4ZAZDv0cfXLkOt0oEowI=
509-
github.com/prometheus/common v0.67.1/go.mod h1:RpmT9v35q2Y+lsieQsdOh5sXZ6ajUGC8NjZAmr8vb0Q=
508+
github.com/prometheus/common v0.67.2 h1:PcBAckGFTIHt2+L3I33uNRTlKTplNzFctXcWhPyAEN8=
509+
github.com/prometheus/common v0.67.2/go.mod h1:63W3KZb1JOKgcjlIr64WW/LvFGAqKPj0atm+knVGEko=
510510
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
511511
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
512512
github.com/redis/go-redis/extra/rediscmd/v9 v9.10.0 h1:uTiEyEyfLhkw678n6EulHVto8AkcXVr8zUcBJNZ0ark=
@@ -1139,8 +1139,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
11391139
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
11401140
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0 h1:qPrZsv1cwQiFeieFlRqT627fVZ+tyfou/+S5S0H5ua0=
11411141
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
1142-
sigs.k8s.io/controller-runtime v0.22.3 h1:I7mfqz/a/WdmDCEnXmSPm8/b/yRTy6JsKKENTijTq8Y=
1143-
sigs.k8s.io/controller-runtime v0.22.3/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
1142+
sigs.k8s.io/controller-runtime v0.22.4 h1:GEjV7KV3TY8e+tJ2LCTxUTanW4z/FmNB7l327UfMq9A=
1143+
sigs.k8s.io/controller-runtime v0.22.4/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
11441144
sigs.k8s.io/controller-tools v0.19.0 h1:OU7jrPPiZusryu6YK0jYSjPqg8Vhf8cAzluP9XGI5uk=
11451145
sigs.k8s.io/controller-tools v0.19.0/go.mod h1:y5HY/iNDFkmFla2CfQoVb2AQXMsBk4ad84iR1PLANB0=
11461146
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2/go.mod h1:B+TnT182UBxE84DiCz4CVE26eOSDAeYCpfDnC2kdKMY=

staging/operator-lifecycle-manager/pkg/controller/registry/grpc/source_test.go

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package grpc
33

44
import (
55
"context"
6+
"fmt"
67
"net"
78
"net/url"
89
"os"
10+
"strings"
911
"sync"
1012
"testing"
1113
"time"
1214

1315
"github.com/sirupsen/logrus"
1416
"github.com/stretchr/testify/require"
17+
"golang.org/x/net/proxy"
1518
"google.golang.org/grpc"
1619
"google.golang.org/grpc/connectivity"
1720

@@ -157,6 +160,143 @@ func TestConnectionEvents(t *testing.T) {
157160
}
158161
}
159162

163+
// Confirms the controller records failure when the registry endpoint cannot be reached.
164+
func TestConnectionEventsRecordsFailureForUnreachableAddress(t *testing.T) {
165+
catalogKey := registry.CatalogKey{Name: "test", Namespace: "test"}
166+
167+
syncer := NewFakeSourceSyncer(1)
168+
sources := NewSourceStore(logrus.New(), 500*time.Millisecond, time.Second, syncer.sync)
169+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
170+
defer cancel()
171+
sources.Start(ctx)
172+
173+
_, err := sources.Add(catalogKey, "127.0.0.1:65534")
174+
require.NoError(t, err)
175+
176+
require.Eventually(t, func() bool {
177+
syncer.Lock()
178+
defer syncer.Unlock()
179+
for _, state := range syncer.History[catalogKey] {
180+
if state == connectivity.TransientFailure {
181+
return true
182+
}
183+
}
184+
return false
185+
}, 5*time.Second, 100*time.Millisecond, "expected transient failure when catalog address is unreachable")
186+
}
187+
188+
// Validates proxied connections succeed even when the client cannot resolve the cluster address.
189+
func TestGrpcConnectionConnectsThroughProxyForClusterAddress(t *testing.T) {
190+
t.Setenv("GRPC_PROXY", "")
191+
t.Setenv("grpc_proxy", "")
192+
t.Setenv("NO_PROXY", "")
193+
t.Setenv("no_proxy", "")
194+
195+
serve, backendAddr, stopServer := server(&fakes.FakeQuery{})
196+
go serve()
197+
defer stopServer()
198+
199+
target := "service.namespace.svc:50051"
200+
201+
directConn, err := grpcConnection(target)
202+
require.NoError(t, err)
203+
waitForState(t, directConn, 5*time.Second, func(state connectivity.State) bool {
204+
return state == connectivity.TransientFailure || state == connectivity.Shutdown
205+
})
206+
require.NoError(t, directConn.Close())
207+
208+
dialer := setupTestProxyDialer(backendAddr)
209+
210+
t.Setenv("GRPC_PROXY", "grpc-test://proxy")
211+
t.Setenv("NO_PROXY", "")
212+
213+
proxyConn, err := grpcConnection(target)
214+
require.NoError(t, err)
215+
defer proxyConn.Close()
216+
217+
waitForState(t, proxyConn, 10*time.Second, func(state connectivity.State) bool {
218+
return state == connectivity.Ready
219+
})
220+
221+
require.Greater(t, dialer.Calls(), 0, "expected proxy dialer to be used")
222+
require.NotEmpty(t, dialer.LastAddr(), "expected proxy dialer to record address")
223+
require.True(t, strings.Contains(dialer.LastAddr(), target), "expected dial address to include target, got %q", dialer.LastAddr())
224+
}
225+
226+
func waitForState(t *testing.T, conn *grpc.ClientConn, timeout time.Duration, match func(connectivity.State) bool) {
227+
t.Helper()
228+
229+
var last connectivity.State
230+
require.Eventually(t, func() bool {
231+
conn.Connect()
232+
last = conn.GetState()
233+
if match(last) {
234+
return true
235+
}
236+
237+
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
238+
conn.WaitForStateChange(ctx, last)
239+
cancel()
240+
241+
last = conn.GetState()
242+
return match(last)
243+
}, timeout, 100*time.Millisecond, fmt.Sprintf("connection never satisfied predicate; last state=%s", last))
244+
}
245+
246+
var (
247+
registerTestProxyDialerOnce sync.Once
248+
testProxyDialer = &recordingProxyDialer{}
249+
)
250+
251+
func setupTestProxyDialer(backend string) *recordingProxyDialer {
252+
registerTestProxyDialerOnce.Do(func() {
253+
proxy.RegisterDialerType("grpc-test", func(u *url.URL, _ proxy.Dialer) (proxy.Dialer, error) {
254+
return testProxyDialer, nil
255+
})
256+
})
257+
testProxyDialer.Reset(backend)
258+
return testProxyDialer
259+
}
260+
261+
type recordingProxyDialer struct {
262+
mu sync.Mutex
263+
backend string
264+
addrs []string
265+
calls int
266+
}
267+
268+
func (d *recordingProxyDialer) Dial(network, addr string) (net.Conn, error) {
269+
d.mu.Lock()
270+
d.calls++
271+
d.addrs = append(d.addrs, addr)
272+
backend := d.backend
273+
d.mu.Unlock()
274+
return net.Dial(network, backend)
275+
}
276+
277+
func (d *recordingProxyDialer) Reset(backend string) {
278+
d.mu.Lock()
279+
defer d.mu.Unlock()
280+
d.backend = backend
281+
d.addrs = nil
282+
d.calls = 0
283+
}
284+
285+
func (d *recordingProxyDialer) Calls() int {
286+
d.mu.Lock()
287+
defer d.mu.Unlock()
288+
return d.calls
289+
}
290+
291+
func (d *recordingProxyDialer) LastAddr() string {
292+
d.mu.Lock()
293+
defer d.mu.Unlock()
294+
if len(d.addrs) == 0 {
295+
return ""
296+
}
297+
return d.addrs[len(d.addrs)-1]
298+
}
299+
160300
func TestGetEnvAny(t *testing.T) {
161301
type envVar struct {
162302
key string

0 commit comments

Comments
 (0)