mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #23883 from liggitt/attis
Externalize immortal namespaces
This commit is contained in:
commit
524bfde377
@ -32,9 +32,11 @@ import (
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
const PluginName = "NamespaceLifecycle"
|
||||
|
||||
func init() {
|
||||
admission.RegisterPlugin("NamespaceLifecycle", func(client clientset.Interface, config io.Reader) (admission.Interface, error) {
|
||||
return NewLifecycle(client), nil
|
||||
admission.RegisterPlugin(PluginName, func(client clientset.Interface, config io.Reader) (admission.Interface, error) {
|
||||
return NewLifecycle(client, sets.NewString(api.NamespaceDefault)), nil
|
||||
})
|
||||
}
|
||||
|
||||
@ -109,7 +111,7 @@ func (l *lifecycle) Admit(a admission.Attributes) (err error) {
|
||||
}
|
||||
|
||||
// NewLifecycle creates a new namespace lifecycle admission control handler
|
||||
func NewLifecycle(c clientset.Interface) admission.Interface {
|
||||
func NewLifecycle(c clientset.Interface, immortalNamespaces sets.String) admission.Interface {
|
||||
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
||||
reflector := cache.NewReflector(
|
||||
&cache.ListWatch{
|
||||
@ -129,6 +131,6 @@ func NewLifecycle(c clientset.Interface) admission.Interface {
|
||||
Handler: admission.NewHandler(admission.Create, admission.Update, admission.Delete),
|
||||
client: c,
|
||||
store: store,
|
||||
immortalNamespaces: sets.NewString(api.NamespaceDefault),
|
||||
immortalNamespaces: immortalNamespaces,
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/client/testing/core"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
// TestAdmission
|
||||
@ -60,7 +61,7 @@ func TestAdmission(t *testing.T) {
|
||||
return true, &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
||||
})
|
||||
|
||||
lfhandler := NewLifecycle(mockClient).(*lifecycle)
|
||||
lfhandler := NewLifecycle(mockClient, sets.NewString("default")).(*lifecycle)
|
||||
lfhandler.store = store
|
||||
handler := admission.NewChainHandler(lfhandler)
|
||||
pod := api.Pod{
|
||||
|
Loading…
Reference in New Issue
Block a user