diff --git a/armometadata/k8sutils.go b/armometadata/k8sutils.go index 21b4211..56d1c30 100644 --- a/armometadata/k8sutils.go +++ b/armometadata/k8sutils.go @@ -126,7 +126,7 @@ func ExtractMetadataFromJsonBytes(input []byte) (Metadata, error) { PodSelectorMatchLabels: map[string]string{}, } // ujson parsing - var parent, subParent, subParent2 string + var parent, subParent string err := ujson.Walk(input, func(level int, key, value []byte) bool { switch level { case 1: @@ -170,19 +170,18 @@ func ExtractMetadataFromJsonBytes(input []byte) (Metadata, error) { m.Labels[unquote(key)] = unquote(value) } - subParent2 = unquote(key) - case 4: // read ownerReferences if subParent == "ownerReferences" { m.OwnerReferences[unquote(key)] = unquote(value) } - if subParent2 == "matchLabels" { + if subParent == "podSelector" { m.PodSelectorMatchLabels[unquote(key)] = unquote(value) } } + return true }) return m, err diff --git a/armometadata/k8sutils_test.go b/armometadata/k8sutils_test.go index 0b3c758..fda6956 100644 --- a/armometadata/k8sutils_test.go +++ b/armometadata/k8sutils_test.go @@ -157,6 +157,7 @@ func TestExtractMetadataFromJsonBytes(t *testing.T) { apiVersion: "networking.k8s.io/v1", podSelectorMatchLabels: map[string]string{ "role": "frontend", + "tier": "tier1", }, }, { diff --git a/armometadata/testdata/networkpolicy_withmatching_labels.json b/armometadata/testdata/networkpolicy_withmatching_labels.json index caabc92..004c5cb 100644 --- a/armometadata/testdata/networkpolicy_withmatching_labels.json +++ b/armometadata/testdata/networkpolicy_withmatching_labels.json @@ -9,7 +9,8 @@ "spec": { "podSelector": { "matchLabels": { - "role": "frontend" + "role": "frontend", + "tier": "tier1" } }, "policyTypes": ["Ingress"],