mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
distinguish custom dialers in transport cache
This commit is contained in:
parent
fe23fa3eee
commit
d45fbce379
@ -44,6 +44,7 @@ type tlsCacheKey struct {
|
|||||||
certData string
|
certData string
|
||||||
keyData string
|
keyData string
|
||||||
serverName string
|
serverName string
|
||||||
|
dial string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t tlsCacheKey) String() string {
|
func (t tlsCacheKey) String() string {
|
||||||
@ -51,7 +52,7 @@ func (t tlsCacheKey) String() string {
|
|||||||
if len(t.keyData) > 0 {
|
if len(t.keyData) > 0 {
|
||||||
keyText = "<redacted>"
|
keyText = "<redacted>"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("insecure:%v, caData:%#v, certData:%#v, keyData:%s, serverName:%s", t.insecure, t.caData, t.certData, keyText, t.serverName)
|
return fmt.Sprintf("insecure:%v, caData:%#v, certData:%#v, keyData:%s, serverName:%s, dial:%s", t.insecure, t.caData, t.certData, keyText, t.serverName, t.dial)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) {
|
func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) {
|
||||||
@ -75,7 +76,7 @@ func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// The options didn't require a custom TLS config
|
// The options didn't require a custom TLS config
|
||||||
if tlsConfig == nil {
|
if tlsConfig == nil && config.Dial == nil {
|
||||||
return http.DefaultTransport, nil
|
return http.DefaultTransport, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,5 +110,6 @@ func tlsConfigKey(c *Config) (tlsCacheKey, error) {
|
|||||||
certData: string(c.TLS.CertData),
|
certData: string(c.TLS.CertData),
|
||||||
keyData: string(c.TLS.KeyData),
|
keyData: string(c.TLS.KeyData),
|
||||||
serverName: c.TLS.ServerName,
|
serverName: c.TLS.ServerName,
|
||||||
|
dial: fmt.Sprintf("%p", c.Dial),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package transport
|
package transport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -53,6 +54,8 @@ func TestTLSConfigKey(t *testing.T) {
|
|||||||
// Make sure config fields that affect the tls config affect the cache key
|
// Make sure config fields that affect the tls config affect the cache key
|
||||||
uniqueConfigurations := map[string]*Config{
|
uniqueConfigurations := map[string]*Config{
|
||||||
"no tls": {},
|
"no tls": {},
|
||||||
|
"dialer": {Dial: net.Dial},
|
||||||
|
"dialer2": {Dial: func(network, address string) (net.Conn, error) { return nil, nil }},
|
||||||
"insecure": {TLS: TLSConfig{Insecure: true}},
|
"insecure": {TLS: TLSConfig{Insecure: true}},
|
||||||
"cadata 1": {TLS: TLSConfig{CAData: []byte{1}}},
|
"cadata 1": {TLS: TLSConfig{CAData: []byte{1}}},
|
||||||
"cadata 2": {TLS: TLSConfig{CAData: []byte{2}}},
|
"cadata 2": {TLS: TLSConfig{CAData: []byte{2}}},
|
||||||
@ -104,11 +107,6 @@ func TestTLSConfigKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for nameA, valueA := range uniqueConfigurations {
|
for nameA, valueA := range uniqueConfigurations {
|
||||||
for nameB, valueB := range uniqueConfigurations {
|
for nameB, valueB := range uniqueConfigurations {
|
||||||
// Don't compare to ourselves
|
|
||||||
if nameA == nameB {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
keyA, err := tlsConfigKey(valueA)
|
keyA, err := tlsConfigKey(valueA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for %q: %v", nameA, err)
|
t.Errorf("Unexpected error for %q: %v", nameA, err)
|
||||||
@ -119,6 +117,15 @@ func TestTLSConfigKey(t *testing.T) {
|
|||||||
t.Errorf("Unexpected error for %q: %v", nameB, err)
|
t.Errorf("Unexpected error for %q: %v", nameB, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure we get the same key on the same config
|
||||||
|
if nameA == nameB {
|
||||||
|
if keyA != keyB {
|
||||||
|
t.Errorf("Expected identical cache keys for %q and %q, got:\n\t%s\n\t%s", nameA, nameB, keyA, keyB)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if keyA == keyB {
|
if keyA == keyB {
|
||||||
t.Errorf("Expected unique cache keys for %q and %q, got:\n\t%s\n\t%s", nameA, nameB, keyA, keyB)
|
t.Errorf("Expected unique cache keys for %q and %q, got:\n\t%s\n\t%s", nameA, nameB, keyA, keyB)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user