Commit e2eefe92 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48733 from liggitt/namespace-deletion

Automatic merge from submit-queue (batch tested with PRs 48494, 48733) Never prevent deletion of resources as part of namespace lifecycle Namespace lifecycle should not prevent deletion of resources... its purpose is to prevent creation of resources in a terminating namespace, or create/update of resources in a non-existent namespace. Fixes #49027
parents 8b39fa9c 95bf4983
...@@ -105,6 +105,11 @@ func (l *lifecycle) Admit(a admission.Attributes) error { ...@@ -105,6 +105,11 @@ func (l *lifecycle) Admit(a admission.Attributes) error {
return nil return nil
} }
// always allow deletion of other resources
if a.GetOperation() == admission.Delete {
return nil
}
// always allow access review checks. Returning status about the namespace would be leaking information // always allow access review checks. Returning status about the namespace would be leaking information
if isAccessReview(a) { if isAccessReview(a) {
return nil return nil
......
...@@ -135,6 +135,24 @@ func TestAdmissionNamespaceDoesNotExist(t *testing.T) { ...@@ -135,6 +135,24 @@ func TestAdmissionNamespaceDoesNotExist(t *testing.T) {
} }
t.Errorf("expected error returned from admission handler: %v", actions) t.Errorf("expected error returned from admission handler: %v", actions)
} }
// verify create operations in the namespace cause an error
err = handler.Admit(admission.NewAttributesRecord(&pod, nil, v1.SchemeGroupVersion.WithKind("Pod").GroupKind().WithVersion("version"), pod.Namespace, pod.Name, v1.Resource("pods").WithVersion("version"), "", admission.Create, nil))
if err == nil {
t.Errorf("Expected error rejecting creates in a namespace when it is missing")
}
// verify update operations in the namespace cause an error
err = handler.Admit(admission.NewAttributesRecord(&pod, nil, v1.SchemeGroupVersion.WithKind("Pod").GroupKind().WithVersion("version"), pod.Namespace, pod.Name, v1.Resource("pods").WithVersion("version"), "", admission.Update, nil))
if err == nil {
t.Errorf("Expected error rejecting updates in a namespace when it is missing")
}
// verify delete operations in the namespace can proceed
err = handler.Admit(admission.NewAttributesRecord(nil, nil, v1.SchemeGroupVersion.WithKind("Pod").GroupKind().WithVersion("version"), pod.Namespace, pod.Name, v1.Resource("pods").WithVersion("version"), "", admission.Delete, nil))
if err != nil {
t.Errorf("Unexpected error returned from admission handler: %v", err)
}
} }
// TestAdmissionNamespaceActive verifies a resource is admitted when the namespace is active. // TestAdmissionNamespaceActive verifies a resource is admitted when the namespace is active.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment