From fa118e23ec1de21c1236bb6d59dd246af549c537 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Tue, 23 Mar 2021 11:29:07 +0100 Subject: [PATCH] DynamicControllerClientBuilder: allows for plugging HTTP wrappers for custom behaviour There might be cases in which callers want to preserve HTTP wrappers for custom behavior per request. For example, there might be distributions that would like to add custom HTTP Headers for each HTTP request. This PR allows for that. It uses the Wrap method that adds a transport middleware function that will give the caller an opportunity to wrap the underlying http.RoundTripper prior to the first API call being made. We cannot use WrapTransport because it simply overwrites RoundTrippers for the current config instead of appending to already existing ones. --- .../pkg/clientbuilder/client_builder_dynamic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/controller-manager/pkg/clientbuilder/client_builder_dynamic.go b/staging/src/k8s.io/controller-manager/pkg/clientbuilder/client_builder_dynamic.go index 00f925cc7b8..81946198374 100644 --- a/staging/src/k8s.io/controller-manager/pkg/clientbuilder/client_builder_dynamic.go +++ b/staging/src/k8s.io/controller-manager/pkg/clientbuilder/client_builder_dynamic.go @@ -116,7 +116,7 @@ func (t *DynamicControllerClientBuilder) Config(saName string) (*restclient.Conf rt, ok := t.roundTripperFuncMap[saName] if ok { - configCopy.WrapTransport = rt + configCopy.Wrap(rt) } else { cachedTokenSource := transport.NewCachedTokenSource(&tokenSourceImpl{ namespace: t.Namespace, @@ -125,7 +125,7 @@ func (t *DynamicControllerClientBuilder) Config(saName string) (*restclient.Conf expirationSeconds: t.expirationSeconds, leewayPercent: t.leewayPercent, }) - configCopy.WrapTransport = transport.ResettableTokenSourceWrapTransport(cachedTokenSource) + configCopy.Wrap(transport.ResettableTokenSourceWrapTransport(cachedTokenSource)) t.roundTripperFuncMap[saName] = configCopy.WrapTransport }