provider/kubernetes: Ignore k8s internal labels

Fixes #13716
This commit is contained in:
Radek Simko 2017-06-02 14:15:26 +01:00
parent b22cfa8b80
commit 8a002b937a
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
2 changed files with 7 additions and 7 deletions

View File

@ -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

View File

@ -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)
}