mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +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"
|
"k8s.io/kubernetes/pkg/watch"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const PluginName = "NamespaceLifecycle"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
admission.RegisterPlugin("NamespaceLifecycle", func(client clientset.Interface, config io.Reader) (admission.Interface, error) {
|
admission.RegisterPlugin(PluginName, func(client clientset.Interface, config io.Reader) (admission.Interface, error) {
|
||||||
return NewLifecycle(client), nil
|
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
|
// 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)
|
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
||||||
reflector := cache.NewReflector(
|
reflector := cache.NewReflector(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
@ -129,6 +131,6 @@ func NewLifecycle(c clientset.Interface) admission.Interface {
|
|||||||
Handler: admission.NewHandler(admission.Create, admission.Update, admission.Delete),
|
Handler: admission.NewHandler(admission.Create, admission.Update, admission.Delete),
|
||||||
client: c,
|
client: c,
|
||||||
store: store,
|
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/testing/core"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestAdmission
|
// TestAdmission
|
||||||
@ -60,7 +61,7 @@ func TestAdmission(t *testing.T) {
|
|||||||
return true, &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
return true, &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
lfhandler := NewLifecycle(mockClient).(*lifecycle)
|
lfhandler := NewLifecycle(mockClient, sets.NewString("default")).(*lifecycle)
|
||||||
lfhandler.store = store
|
lfhandler.store = store
|
||||||
handler := admission.NewChainHandler(lfhandler)
|
handler := admission.NewChainHandler(lfhandler)
|
||||||
pod := api.Pod{
|
pod := api.Pod{
|
||||||
|
Loading…
Reference in New Issue
Block a user