@@ -27,6 +27,8 @@ import (
27
27
"net"
28
28
"net/http"
29
29
"net/http/httptest"
30
+ "net/netip"
31
+ "net/url"
30
32
"os"
31
33
"os/exec"
32
34
"path"
@@ -251,6 +253,23 @@ func runKubectlRetryOrDie(ns string, args ...string) string {
251
253
return output
252
254
}
253
255
256
+ // matches localhost / loopback skip from
257
+ // https://pkg.go.dev/golang.org/x/net/http/httpproxy#Config.ProxyFunc
258
+ func hostIsLocal (host string ) bool {
259
+ if host == "localhost" {
260
+ return true
261
+ }
262
+ nip , err := netip .ParseAddr (host )
263
+ var ip net.IP
264
+ if err == nil {
265
+ ip = net .IP (nip .AsSlice ())
266
+ if ip .IsLoopback () {
267
+ return true
268
+ }
269
+ }
270
+ return false
271
+ }
272
+
254
273
var _ = SIGDescribe ("Kubectl client" , func () {
255
274
defer ginkgo .GinkgoRecover ()
256
275
f := framework .NewDefaultFramework ("kubectl" )
@@ -467,8 +486,20 @@ var _ = SIGDescribe("Kubectl client", func() {
467
486
})
468
487
469
488
ginkgo .It ("should support exec through an HTTP proxy" , func (ctx context.Context ) {
489
+ // testContextHost is a KUBECONFIG URL
470
490
testContextHost := getTestContextHost ()
471
491
492
+ // check if testContextHost is on localhost and skip the tests
493
+ // proxy env vars are always ignored on localhost and loopback IPs
494
+ // https://pkg.go.dev/golang.org/x/net/http/httpproxy#Config.ProxyFunc
495
+ // TODO: consider if we can test proxying some other way with local clusters
496
+ // https://github.com/kubernetes/kubectl/issues/1655#issuecomment-2829408755
497
+ u , err := url .Parse (testContextHost )
498
+ framework .ExpectNoError (err , "parsing test context host: %s" , testContextHost )
499
+ if hostIsLocal (u .Hostname ()) {
500
+ e2eskipper .Skipf ("Test host %q is on localhost and would not be proxied by HTTP_PROXY, skipping test" , testContextHost )
501
+ }
502
+
472
503
ginkgo .By ("Starting http_proxy" )
473
504
var proxyLogs bytes.Buffer
474
505
testSrv := httptest .NewServer (utilnettesting .NewHTTPProxyHandler (ginkgo .GinkgoTB (), func (req * http.Request ) bool {
0 commit comments