Commit 0d717272 authored by Chao Xu's avatar Chao Xu

Never let cluster-scoped resources skip webhooks

parent dc9dd59a
...@@ -195,8 +195,8 @@ type Webhook struct { ...@@ -195,8 +195,8 @@ type Webhook struct {
// NamespaceSelector decides whether to run the webhook on an object based // NamespaceSelector decides whether to run the webhook on an object based
// on whether the namespace for that object matches the selector. If the // on whether the namespace for that object matches the selector. If the
// object itself is a namespace, the matching is performed on // object itself is a namespace, the matching is performed on
// object.metadata.labels. If the object is other cluster scoped resource, // object.metadata.labels. If the object is another cluster scoped resource,
// it is not subjected to the webhook. // it never skips the webhook.
// //
// For example, to run the webhook on any objects whose namespace is not // For example, to run the webhook on any objects whose namespace is not
// associated with "runlevel" of "0" or "1"; you will set the selector as // associated with "runlevel" of "0" or "1"; you will set the selector as
......
...@@ -147,8 +147,8 @@ type Webhook struct { ...@@ -147,8 +147,8 @@ type Webhook struct {
// NamespaceSelector decides whether to run the webhook on an object based // NamespaceSelector decides whether to run the webhook on an object based
// on whether the namespace for that object matches the selector. If the // on whether the namespace for that object matches the selector. If the
// object itself is a namespace, the matching is performed on // object itself is a namespace, the matching is performed on
// object.metadata.labels. If the object is other cluster scoped resource, // object.metadata.labels. If the object is another cluster scoped resource,
// it is not subjected to the webhook. // it never skips the webhook.
// //
// For example, to run the webhook on any objects whose namespace is not // For example, to run the webhook on any objects whose namespace is not
// associated with "runlevel" of "0" or "1"; you will set the selector as // associated with "runlevel" of "0" or "1"; you will set the selector as
......
...@@ -90,10 +90,10 @@ func (m *Matcher) MatchNamespaceSelector(h *v1beta1.Webhook, attr admission.Attr ...@@ -90,10 +90,10 @@ func (m *Matcher) MatchNamespaceSelector(h *v1beta1.Webhook, attr admission.Attr
namespaceName := attr.GetNamespace() namespaceName := attr.GetNamespace()
if len(namespaceName) == 0 && attr.GetResource().Resource != "namespaces" { if len(namespaceName) == 0 && attr.GetResource().Resource != "namespaces" {
// If the request is about a cluster scoped resource, and it is not a // If the request is about a cluster scoped resource, and it is not a
// namespace, it is exempted from all webhooks for now. // namespace, it is never exempted.
// TODO: figure out a way selective exempt cluster scoped resources. // TODO: figure out a way selective exempt cluster scoped resources.
// Also update the comment in types.go // Also update the comment in types.go
return false, nil return true, nil
} }
namespaceLabels, err := m.GetNamespaceLabels(attr) namespaceLabels, err := m.GetNamespaceLabels(attr)
// this means the namespace is not found, for backwards compatibility, // this means the namespace is not found, for backwards compatibility,
......
...@@ -113,7 +113,7 @@ func TestGetNamespaceLabels(t *testing.T) { ...@@ -113,7 +113,7 @@ func TestGetNamespaceLabels(t *testing.T) {
} }
} }
func TestExemptClusterScopedResource(t *testing.T) { func TestNotExemptClusterScopedResource(t *testing.T) {
hook := &registrationv1beta1.Webhook{ hook := &registrationv1beta1.Webhook{
NamespaceSelector: &metav1.LabelSelector{}, NamespaceSelector: &metav1.LabelSelector{},
} }
...@@ -123,7 +123,7 @@ func TestExemptClusterScopedResource(t *testing.T) { ...@@ -123,7 +123,7 @@ func TestExemptClusterScopedResource(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if matches { if !matches {
t.Errorf("cluster scoped resources (but not a namespace) should be exempted from all webhooks") t.Errorf("cluster scoped resources (but not a namespace) should not be exempted from webhooks")
} }
} }
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