From 20b4d27e5830db31bbbb35323282fd52842bc42b Mon Sep 17 00:00:00 2001 From: Stephen Cirner Date: Thu, 10 Oct 2024 22:41:40 -0400 Subject: [PATCH] fix: allow long annotations (#421) * fix: allow long annotations * Update internal/test/metadata.go Co-authored-by: Mark Vainomaa --------- Co-authored-by: Mark Vainomaa --- internal/kube/labels.go | 2 +- internal/kube/labels_test.go | 3 ++- internal/test/metadata.go | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/kube/labels.go b/internal/kube/labels.go index 30b419b4..006d540f 100644 --- a/internal/kube/labels.go +++ b/internal/kube/labels.go @@ -59,7 +59,7 @@ func NormalizeMetadata(obj *metav1.ObjectMeta) { annots := make(map[string]string) for k, v := range obj.Annotations { - annots[ToLabelKey(k)] = trimMiddle(v, 63) + annots[ToLabelKey(k)] = v } obj.Annotations = annots diff --git a/internal/kube/labels_test.go b/internal/kube/labels_test.go index f06752b1..2b83836a 100644 --- a/internal/kube/labels_test.go +++ b/internal/kube/labels_test.go @@ -86,7 +86,7 @@ func TestNormalizeMetadata(t *testing.T) { obj := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: strings.Repeat(" name ", 500), - Annotations: map[string]string{strings.Repeat("annot-key", 500): strings.Repeat("value", 500), "cloud.google.com/neg": `{"ingress": true}`}, + Annotations: map[string]string{strings.Repeat("annot-key", 500): strings.Repeat("value", 500), "cloud.google.com/neg": `{"ingress": true}`, "long-value": strings.Repeat("value", 500)}, Labels: map[string]string{strings.Repeat("label-key", 500): strings.Repeat("value", 500)}, }, } @@ -95,4 +95,5 @@ func TestNormalizeMetadata(t *testing.T) { test.RequireValidMetadata(t, obj) require.Equal(t, `{"ingress": true}`, obj.Annotations["cloud.google.com/neg"]) + require.Equal(t, strings.Repeat("value", 500), obj.Annotations["long-value"]) } diff --git a/internal/test/metadata.go b/internal/test/metadata.go index b00750ca..6bd0157f 100644 --- a/internal/test/metadata.go +++ b/internal/test/metadata.go @@ -16,8 +16,7 @@ func RequireValidMetadata(t *testing.T, obj client.Object) { require.LessOrEqual(t, len(k), 63) require.LessOrEqual(t, len(v), 63, k) } - for k, v := range obj.GetAnnotations() { + for k := range obj.GetAnnotations() { require.LessOrEqual(t, len(k), 63) - require.LessOrEqual(t, len(v), 63, k) } }