mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 05:36:12 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user