mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-17 16:52:22 +00:00
add noop persister to plugin loader
Kubernetes-commit: 2dd86fe8c2cc7b655085b773bd1a06bc2ab54bbd
This commit is contained in:
parent
f80da32721
commit
b804f9f657
@ -47,6 +47,13 @@ type AuthProviderConfigPersister interface {
|
|||||||
Persist(map[string]string) error
|
Persist(map[string]string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type noopPersister struct{}
|
||||||
|
|
||||||
|
func (n *noopPersister) Persist(_ map[string]string) error {
|
||||||
|
// no operation persister
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// All registered auth provider plugins.
|
// All registered auth provider plugins.
|
||||||
var pluginsLock sync.Mutex
|
var pluginsLock sync.Mutex
|
||||||
var plugins = make(map[string]Factory)
|
var plugins = make(map[string]Factory)
|
||||||
@ -69,5 +76,8 @@ func GetAuthProvider(clusterAddress string, apc *clientcmdapi.AuthProviderConfig
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("no Auth Provider found for name %q", apc.Name)
|
return nil, fmt.Errorf("no Auth Provider found for name %q", apc.Name)
|
||||||
}
|
}
|
||||||
|
if persister == nil {
|
||||||
|
persister = &noopPersister{}
|
||||||
|
}
|
||||||
return p(clusterAddress, apc.Config, persister)
|
return p(clusterAddress, apc.Config, persister)
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,28 @@ func TestAuthPluginPersist(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_WhenNilPersister_NoOpPersisterIsAssigned(t *testing.T) {
|
||||||
|
|
||||||
|
if err := RegisterAuthProviderPlugin("anyPlugin", pluginPersistProvider); err != nil {
|
||||||
|
t.Errorf("unexpected error: failed to register 'anyPlugin': %v", err)
|
||||||
|
}
|
||||||
|
cfg := &clientcmdapi.AuthProviderConfig{
|
||||||
|
Name: "anyPlugin",
|
||||||
|
Config: nil,
|
||||||
|
}
|
||||||
|
plugin, err := GetAuthProvider("127.0.0.1", cfg, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: failed to get 'anyPlugin': %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
anyPlugin := plugin.(*pluginPersist)
|
||||||
|
|
||||||
|
if _, ok := anyPlugin.persister.(*noopPersister); !ok {
|
||||||
|
t.Errorf("expected to be No Operation persister")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// emptyTransport provides an empty http.Response with an initialized header
|
// emptyTransport provides an empty http.Response with an initialized header
|
||||||
// to allow wrapping RoundTrippers to set header values.
|
// to allow wrapping RoundTrippers to set header values.
|
||||||
type emptyTransport struct{}
|
type emptyTransport struct{}
|
||||||
|
Loading…
Reference in New Issue
Block a user