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.
This commit is contained in:
Lukasz Szaszkiewicz
2021-03-23 11:29:07 +01:00
parent cc4bd511bb
commit fa118e23ec

View File

@@ -116,7 +116,7 @@ func (t *DynamicControllerClientBuilder) Config(saName string) (*restclient.Conf
rt, ok := t.roundTripperFuncMap[saName] rt, ok := t.roundTripperFuncMap[saName]
if ok { if ok {
configCopy.WrapTransport = rt configCopy.Wrap(rt)
} else { } else {
cachedTokenSource := transport.NewCachedTokenSource(&tokenSourceImpl{ cachedTokenSource := transport.NewCachedTokenSource(&tokenSourceImpl{
namespace: t.Namespace, namespace: t.Namespace,
@@ -125,7 +125,7 @@ func (t *DynamicControllerClientBuilder) Config(saName string) (*restclient.Conf
expirationSeconds: t.expirationSeconds, expirationSeconds: t.expirationSeconds,
leewayPercent: t.leewayPercent, leewayPercent: t.leewayPercent,
}) })
configCopy.WrapTransport = transport.ResettableTokenSourceWrapTransport(cachedTokenSource) configCopy.Wrap(transport.ResettableTokenSourceWrapTransport(cachedTokenSource))
t.roundTripperFuncMap[saName] = configCopy.WrapTransport t.roundTripperFuncMap[saName] = configCopy.WrapTransport
} }