Skip to content

Commit af3b9e6

Browse files
committed
reduce dependencies in apimachinery net testing utils
Consumers of the kubernetes golang API and clients must use k8s.io/api,apimachinery,client-go. This is also require to download all the necessary dependencies. The apimachinery code contains a testing util for proxies that is used in client-go and in the kubectl e2e. Since the tests on e2e require ginkgo and we want to ensure this testing library is not used in production, we cast the interface to match one of those libraries, but the problem is that this forces consumers of apimachinery to also download the ginkgo library. Since NewHTTPProxyHandler receives a testing.TB interface, there is no need to cast the interface, if someone wants to use it by implementing a testing interface it is already aware of the risks.
1 parent 69ab91a commit af3b9e6

File tree

14 files changed

+17
-51
lines changed

14 files changed

+17
-51
lines changed

staging/src/k8s.io/api/go.sum

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apimachinery/go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ require (
1919
github.com/google/uuid v1.6.0
2020
github.com/moby/spdystream v0.5.0
2121
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f
22-
github.com/onsi/ginkgo/v2 v2.21.0
2322
github.com/spf13/pflag v1.0.5
2423
github.com/stretchr/testify v1.9.0
2524
golang.org/x/net v0.33.0
@@ -39,20 +38,17 @@ require (
3938
github.com/go-openapi/jsonpointer v0.21.0 // indirect
4039
github.com/go-openapi/jsonreference v0.20.2 // indirect
4140
github.com/go-openapi/swag v0.23.0 // indirect
42-
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
43-
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
4441
github.com/josharian/intern v1.0.0 // indirect
4542
github.com/json-iterator/go v1.1.12 // indirect
4643
github.com/mailru/easyjson v0.7.7 // indirect
4744
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4845
github.com/modern-go/reflect2 v1.0.2 // indirect
46+
github.com/onsi/ginkgo/v2 v2.21.0 // indirect
4947
github.com/onsi/gomega v1.35.1 // indirect
5048
github.com/pkg/errors v0.9.1 // indirect
5149
github.com/pmezard/go-difflib v1.0.0 // indirect
5250
github.com/x448/float16 v0.8.4 // indirect
53-
golang.org/x/sys v0.28.0 // indirect
5451
golang.org/x/text v0.21.0 // indirect
55-
golang.org/x/tools v0.26.0 // indirect
5652
google.golang.org/protobuf v1.35.1 // indirect
5753
gopkg.in/yaml.v3 v3.0.1 // indirect
5854
)

staging/src/k8s.io/apimachinery/go.sum

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apimachinery/pkg/util/net/testing/http.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,14 @@ import (
2626
"net/http/httputil"
2727
"sync"
2828
"testing"
29-
30-
"github.com/onsi/ginkgo/v2"
3129
)
3230

33-
type TB interface {
34-
Logf(format string, args ...any)
35-
}
36-
3731
// NewHTTPProxyHandler returns a new HTTPProxyHandler. It accepts an optional
3832
// hook which is called early in the handler to export request state. If the
3933
// hook returns false, the handler returns immediately with a server error.
40-
func NewHTTPProxyHandler(t TB, hook func(req *http.Request) bool) *HTTPProxyHandler {
41-
// Ensure that this is only used in tests. This code has not been security
42-
// reviewed.
43-
switch t.(type) {
44-
case testing.TB, ginkgo.GinkgoTInterface:
45-
default:
46-
panic("t is not a known test interface")
47-
}
34+
// Ensure that this is only used in tests. This code has not been security
35+
// reviewed.
36+
func NewHTTPProxyHandler(t testing.TB, hook func(req *http.Request) bool) *HTTPProxyHandler {
4837
h := &HTTPProxyHandler{
4938
hook: hook,
5039
httpProxy: httputil.ReverseProxy{
@@ -65,7 +54,7 @@ type HTTPProxyHandler struct {
6554
hook func(r *http.Request) bool
6655
// httpProxy is the reverse proxy we use for standard http proxy requests.
6756
httpProxy httputil.ReverseProxy
68-
t TB
57+
t testing.TB
6958
}
7059

7160
// ServeHTTP handles an HTTP proxy request.

staging/src/k8s.io/client-go/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ require (
4545
github.com/go-openapi/jsonpointer v0.21.0 // indirect
4646
github.com/go-openapi/jsonreference v0.20.2 // indirect
4747
github.com/go-openapi/swag v0.23.0 // indirect
48-
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
4948
github.com/google/btree v1.1.3 // indirect
5049
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
5150
github.com/josharian/intern v1.0.0 // indirect
@@ -55,7 +54,6 @@ require (
5554
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5655
github.com/modern-go/reflect2 v1.0.2 // indirect
5756
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
58-
github.com/onsi/ginkgo/v2 v2.21.0 // indirect
5957
github.com/pkg/errors v0.9.1 // indirect
6058
github.com/pmezard/go-difflib v1.0.0 // indirect
6159
github.com/stretchr/objx v0.5.2 // indirect

staging/src/k8s.io/cluster-bootstrap/go.sum

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/code-generator/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/go-openapi/jsonpointer v0.21.0 // indirect
3131
github.com/go-openapi/jsonreference v0.20.2 // indirect
3232
github.com/go-openapi/swag v0.23.0 // indirect
33+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
3334
github.com/josharian/intern v1.0.0 // indirect
3435
github.com/json-iterator/go v1.1.12 // indirect
3536
github.com/mailru/easyjson v0.7.7 // indirect
@@ -38,6 +39,7 @@ require (
3839
github.com/x448/float16 v0.8.4 // indirect
3940
golang.org/x/mod v0.21.0 // indirect
4041
golang.org/x/sync v0.10.0 // indirect
42+
golang.org/x/sys v0.28.0 // indirect
4143
golang.org/x/tools v0.26.0 // indirect
4244
google.golang.org/protobuf v1.35.1 // indirect
4345
gopkg.in/yaml.v3 v3.0.1 // indirect

staging/src/k8s.io/code-generator/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/csi-translation-lib/go.sum

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/kube-controller-manager/go.sum

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)