parent
b22cfa8b80
commit
8a002b937a
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue