parent
b22cfa8b80
commit
8a002b937a
|
@ -77,11 +77,11 @@ func expandStringSlice(s []interface{}) []string {
|
||||||
|
|
||||||
func flattenMetadata(meta metav1.ObjectMeta) []map[string]interface{} {
|
func flattenMetadata(meta metav1.ObjectMeta) []map[string]interface{} {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["annotations"] = filterAnnotations(meta.Annotations)
|
m["annotations"] = removeInternalKeys(meta.Annotations)
|
||||||
if meta.GenerateName != "" {
|
if meta.GenerateName != "" {
|
||||||
m["generate_name"] = meta.GenerateName
|
m["generate_name"] = meta.GenerateName
|
||||||
}
|
}
|
||||||
m["labels"] = meta.Labels
|
m["labels"] = removeInternalKeys(meta.Labels)
|
||||||
m["name"] = meta.Name
|
m["name"] = meta.Name
|
||||||
m["resource_version"] = meta.ResourceVersion
|
m["resource_version"] = meta.ResourceVersion
|
||||||
m["self_link"] = meta.SelfLink
|
m["self_link"] = meta.SelfLink
|
||||||
|
@ -95,16 +95,16 @@ func flattenMetadata(meta metav1.ObjectMeta) []map[string]interface{} {
|
||||||
return []map[string]interface{}{m}
|
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 {
|
for k, _ := range m {
|
||||||
if isInternalAnnotationKey(k) {
|
if isInternalKey(k) {
|
||||||
delete(m, k)
|
delete(m, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func isInternalAnnotationKey(annotationKey string) bool {
|
func isInternalKey(annotationKey string) bool {
|
||||||
u, err := url.Parse("//" + annotationKey)
|
u, err := url.Parse("//" + annotationKey)
|
||||||
if err == nil && strings.HasSuffix(u.Hostname(), "kubernetes.io") {
|
if err == nil && strings.HasSuffix(u.Hostname(), "kubernetes.io") {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsInternalAnnotationKey(t *testing.T) {
|
func TestIsInternalKey(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
Key string
|
Key string
|
||||||
Expected bool
|
Expected bool
|
||||||
|
@ -20,7 +20,7 @@ func TestIsInternalAnnotationKey(t *testing.T) {
|
||||||
}
|
}
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||||
isInternal := isInternalAnnotationKey(tc.Key)
|
isInternal := isInternalKey(tc.Key)
|
||||||
if tc.Expected && isInternal != tc.Expected {
|
if tc.Expected && isInternal != tc.Expected {
|
||||||
t.Fatalf("Expected %q to be internal", tc.Key)
|
t.Fatalf("Expected %q to be internal", tc.Key)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue