2022-11-22 09:10:07 +00:00
|
|
|
package clientset
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
"github.com/go-logr/logr"
|
2022-11-22 09:10:07 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/metrics"
|
|
|
|
k8s_io_client_go_metadata "k8s.io/client-go/metadata"
|
|
|
|
"k8s.io/client-go/rest"
|
|
|
|
)
|
|
|
|
|
2023-04-25 15:31:09 +00:00
|
|
|
type UpstreamInterface = k8s_io_client_go_metadata.Interface
|
|
|
|
|
2022-11-22 09:10:07 +00:00
|
|
|
type Interface interface {
|
2023-04-25 15:31:09 +00:00
|
|
|
UpstreamInterface
|
2022-11-22 15:12:30 +00:00
|
|
|
WithMetrics(metrics.MetricsConfigManager, metrics.ClientType) Interface
|
2022-11-22 09:10:07 +00:00
|
|
|
WithTracing() Interface
|
2022-11-22 15:12:30 +00:00
|
|
|
WithLogging(logr.Logger) Interface
|
2022-11-22 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
func From(inner k8s_io_client_go_metadata.Interface, opts ...NewOption) Interface {
|
|
|
|
i := from(inner)
|
|
|
|
for _, opt := range opts {
|
|
|
|
i = opt(i)
|
|
|
|
}
|
|
|
|
return i
|
2022-11-22 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type NewOption func(Interface) Interface
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
func WithMetrics(m metrics.MetricsConfigManager, t metrics.ClientType) NewOption {
|
|
|
|
return func(i Interface) Interface {
|
|
|
|
return i.WithMetrics(m, t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithTracing() NewOption {
|
|
|
|
return func(i Interface) Interface {
|
|
|
|
return i.WithTracing()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithLogging(logger logr.Logger) NewOption {
|
|
|
|
return func(i Interface) Interface {
|
|
|
|
return i.WithLogging(logger)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 09:10:07 +00:00
|
|
|
func NewForConfig(c *rest.Config, opts ...NewOption) (Interface, error) {
|
|
|
|
inner, err := k8s_io_client_go_metadata.NewForConfig(c)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return From(inner, opts...), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewForConfigAndClient(c *rest.Config, httpClient *http.Client, opts ...NewOption) (Interface, error) {
|
|
|
|
inner, err := k8s_io_client_go_metadata.NewForConfigAndClient(c, httpClient)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return From(inner, opts...), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewForConfigOrDie(c *rest.Config, opts ...NewOption) Interface {
|
|
|
|
return From(k8s_io_client_go_metadata.NewForConfigOrDie(c), opts...)
|
|
|
|
}
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
type wrapper struct {
|
|
|
|
k8s_io_client_go_metadata.Interface
|
2022-11-22 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
func from(inner k8s_io_client_go_metadata.Interface, opts ...NewOption) Interface {
|
|
|
|
return &wrapper{inner}
|
2022-11-22 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i *wrapper) WithMetrics(m metrics.MetricsConfigManager, t metrics.ClientType) Interface {
|
|
|
|
return from(WrapWithMetrics(i, m, t))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *wrapper) WithTracing() Interface {
|
|
|
|
return from(WrapWithTracing(i))
|
|
|
|
}
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
func (i *wrapper) WithLogging(logger logr.Logger) Interface {
|
|
|
|
return from(WrapWithLogging(i, logger))
|
2022-11-22 09:10:07 +00:00
|
|
|
}
|