Merge pull request #99776 from p0lyn0mial/upstream-kcm-dynamic-client-builder

DynamicControllerClientBuilder: allows for plugging HTTP wrappers for custom behaviour
This commit is contained in:
Kubernetes Prow Robot 2021-04-08 15:59:43 -07:00 committed by GitHub
commit 12ed525b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}
@ -235,7 +235,11 @@ func (ts *tokenSourceImpl) Token() (*oauth2.Token, error) {
func constructClient(saNamespace, saName string, config *restclient.Config) restclient.Config {
username := apiserverserviceaccount.MakeUsername(saNamespace, saName)
ret := *restclient.AnonymousClientConfig(config)
// make a shallow copy
// the caller already castrated the config during creation
// this allows for potential extensions in the future
// for example it preserve HTTP wrappers for custom behavior per request
ret := *config
restclient.AddUserAgent(&ret, username)
return ret
}