2021-01-05 22:07:33 +00:00
|
|
|
// Copyright 2021 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package kubeclient
|
|
|
|
|
2021-02-03 13:19:34 +00:00
|
|
|
import (
|
|
|
|
restclient "k8s.io/client-go/rest"
|
|
|
|
"k8s.io/client-go/transport"
|
|
|
|
)
|
2021-01-05 22:07:33 +00:00
|
|
|
|
|
|
|
type Option func(*clientConfig)
|
|
|
|
|
|
|
|
type clientConfig struct {
|
2021-02-03 13:19:34 +00:00
|
|
|
config *restclient.Config
|
|
|
|
middlewares []Middleware
|
|
|
|
transportWrapper transport.WrapperFunc
|
2021-01-05 22:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func WithConfig(config *restclient.Config) Option {
|
|
|
|
return func(c *clientConfig) {
|
|
|
|
c.config = config
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMiddleware(middleware Middleware) Option {
|
|
|
|
return func(c *clientConfig) {
|
2021-01-13 01:27:41 +00:00
|
|
|
if middleware == nil {
|
|
|
|
return // support passing in a nil middleware as a no-op
|
|
|
|
}
|
|
|
|
|
2021-01-05 22:07:33 +00:00
|
|
|
c.middlewares = append(c.middlewares, middleware)
|
|
|
|
}
|
|
|
|
}
|
2021-02-03 13:19:34 +00:00
|
|
|
|
|
|
|
// WithTransportWrapper will wrap the client-go http.RoundTripper chain *after* the middleware
|
|
|
|
// wrapper is applied. I.e., this wrapper has the opportunity to supply an http.RoundTripper that
|
|
|
|
// runs first in the client-go http.RoundTripper chain.
|
|
|
|
func WithTransportWrapper(wrapper transport.WrapperFunc) Option {
|
|
|
|
return func(c *clientConfig) {
|
|
|
|
c.transportWrapper = wrapper
|
|
|
|
}
|
|
|
|
}
|