diff --git a/builtin/providers/kubernetes/structures.go b/builtin/providers/kubernetes/structures.go index 360edc12e..2359f96e5 100644 --- a/builtin/providers/kubernetes/structures.go +++ b/builtin/providers/kubernetes/structures.go @@ -77,11 +77,11 @@ func expandStringSlice(s []interface{}) []string { func flattenMetadata(meta metav1.ObjectMeta) []map[string]interface{} { m := make(map[string]interface{}) - m["annotations"] = filterAnnotations(meta.Annotations) + m["annotations"] = removeInternalKeys(meta.Annotations) if meta.GenerateName != "" { m["generate_name"] = meta.GenerateName } - m["labels"] = meta.Labels + m["labels"] = removeInternalKeys(meta.Labels) m["name"] = meta.Name m["resource_version"] = meta.ResourceVersion m["self_link"] = meta.SelfLink @@ -95,16 +95,16 @@ func flattenMetadata(meta metav1.ObjectMeta) []map[string]interface{} { return []map[string]interface{}{m} } -func filterAnnotations(m map[string]string) map[string]string { +func removeInternalKeys(m map[string]string) map[string]string { for k, _ := range m { - if isInternalAnnotationKey(k) { + if isInternalKey(k) { delete(m, k) } } return m } -func isInternalAnnotationKey(annotationKey string) bool { +func isInternalKey(annotationKey string) bool { u, err := url.Parse("//" + annotationKey) if err == nil && strings.HasSuffix(u.Hostname(), "kubernetes.io") { return true diff --git a/builtin/providers/kubernetes/structures_test.go b/builtin/providers/kubernetes/structures_test.go index 2a0b9003e..a423c3f9a 100644 --- a/builtin/providers/kubernetes/structures_test.go +++ b/builtin/providers/kubernetes/structures_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -func TestIsInternalAnnotationKey(t *testing.T) { +func TestIsInternalKey(t *testing.T) { testCases := []struct { Key string Expected bool @@ -20,7 +20,7 @@ func TestIsInternalAnnotationKey(t *testing.T) { } for i, tc := range testCases { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { - isInternal := isInternalAnnotationKey(tc.Key) + isInternal := isInternalKey(tc.Key) if tc.Expected && isInternal != tc.Expected { t.Fatalf("Expected %q to be internal", tc.Key) }