Skip to content

Commit

Permalink
Do not add to cache within targethandler
Browse files Browse the repository at this point in the history
Signed-off-by: davis-haba <davishaba@google.com>
  • Loading branch information
davis-haba committed Mar 14, 2022
1 parent 4163d8c commit 650b65a
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions pkg/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ func (h *K8sValidationTarget) processUnstructured(o *unstructured.Unstructured)
return true, "", nil, fmt.Errorf("resource %s has no kind", o.GetName())
}

if gvk.Kind == "Namespace" {
ns, err := unstructuredToNamespace(o)
if err != nil {
return true, "", nil, err
}
if err := h.Add(ns.Name, ns); err != nil {
return true, "", nil, err
}
}

if o.GetNamespace() == "" {
return true, path.Join("cluster", url.PathEscape(gvk.GroupVersion().String()), gvk.Kind, o.GetName()), o.Object, nil
}
Expand Down Expand Up @@ -213,14 +203,6 @@ func unstructuredToAdmissionRequest(obj unstructured.Unstructured) (admissionv1.
return req, nil
}

func unstructuredToNamespace(obj *unstructured.Unstructured) (*corev1.Namespace, error) {
var ns corev1.Namespace
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ns); err != nil {
return nil, fmt.Errorf("could not convert unstructured to namespace: %s", err)
}
return &ns, nil
}

func getString(m map[string]interface{}, k string) (string, error) {
val, exists, err := unstructured.NestedFieldNoCopy(m, "kind", k)
if err != nil {
Expand Down Expand Up @@ -551,11 +533,6 @@ func (m *Matcher) Match(review interface{}) (bool, error) {
return false, err
}
ns = cachedNs
} else {
err := m.cache.Add(obj.GetNamespace(), ns)
if err != nil {
return false, err
}
}

return matchAny(m, ns, &obj, &oldObj)
Expand Down

0 comments on commit 650b65a

Please sign in to comment.