@@ -19,6 +19,7 @@ import (
1919 "github.com/sirupsen/logrus"
2020 "github.com/stretchr/testify/assert"
2121 "github.com/stretchr/testify/require"
22+ utilnet "k8s.io/apimachinery/pkg/util/net"
2223 "k8s.io/client-go/rest"
2324)
2425
@@ -243,13 +244,13 @@ func TestHTTPClientHasTLSConfig(t *testing.T) {
243244 // Verify that the client has a transport configured
244245 require .NotNil (t , httpClient .Transport , "HTTP client transport should be configured" )
245246
246- // Check if it's an http.Transport with TLS config
247- transport , ok := httpClient . Transport .( * http .Transport )
248- require .True (t , ok , "Transport should be *http.Transport " )
249- require .NotNil (t , transport . TLSClientConfig , "TLS config should be set" )
247+ // Extract TLS config, unwrapping any transport wrappers (e.g. trackedTransport)
248+ tlsConfig , err := utilnet . TLSClientConfig ( httpClient .Transport )
249+ require .NoError (t , err , "Should be able to extract TLS config from transport " )
250+ require .NotNil (t , tlsConfig , "TLS config should be set" )
250251
251252 // Verify that RootCAs is configured (this proves CA cert is loaded)
252- assert .NotNil (t , transport . TLSClientConfig .RootCAs , "RootCAs should be configured from kubeConfig" )
253+ assert .NotNil (t , tlsConfig .RootCAs , "RootCAs should be configured from kubeConfig" )
253254
254255 // Verify timeout is set
255256 assert .Equal (t , 30 * time .Second , httpClient .Timeout , "Timeout should match kubeConfig" )
@@ -519,20 +520,13 @@ func TestRootCAsConfiguration(t *testing.T) {
519520 client , err := rest .HTTPClientFor (config )
520521 require .NoError (t , err )
521522
522- // Verify transport has TLS config
523- transport , ok := client . Transport .( * http .Transport )
524- require .True (t , ok )
525- require .NotNil (t , transport . TLSClientConfig )
523+ // Extract TLS config, unwrapping any transport wrappers (e.g. trackedTransport)
524+ tlsConfig , err := utilnet . TLSClientConfig ( client .Transport )
525+ require .NoError (t , err , "Should be able to extract TLS config from transport" )
526+ require .NotNil (t , tlsConfig , "TLS config should be set" )
526527
527528 // The RootCAs should be configured
528- if transport .TLSClientConfig .RootCAs != nil {
529- // Success - RootCAs are configured
530- assert .NotNil (t , transport .TLSClientConfig .RootCAs )
531- } else {
532- // On some systems, if CAData is invalid, RootCAs might be nil
533- // but the important thing is no error was returned
534- t .Log ("RootCAs is nil - this might be due to invalid test certificate" )
535- }
529+ assert .NotNil (t , tlsConfig .RootCAs , "RootCAs should be configured from kubeConfig CA data" )
536530}
537531
538532// TestHTTPClientTimeout verifies timeout configuration
0 commit comments