From 8e061b899e66550dbd9eb56c625eefd85c66ca6d Mon Sep 17 00:00:00 2001 From: Stephen Cirner Date: Tue, 28 May 2024 23:31:28 -0400 Subject: [PATCH 1/2] fix: allow long annotations --- 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..a37fdd7d 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) } } From 035a850d24903e491a2ca1e98a9ac9a653b8a5b3 Mon Sep 17 00:00:00 2001 From: Stephen Cirner Date: Thu, 20 Jun 2024 17:07:46 -0400 Subject: [PATCH 2/2] Update internal/test/metadata.go Co-authored-by: Mark Vainomaa --- internal/test/metadata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/test/metadata.go b/internal/test/metadata.go index a37fdd7d..6bd0157f 100644 --- a/internal/test/metadata.go +++ b/internal/test/metadata.go @@ -16,7 +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, _ := range obj.GetAnnotations() { + for k := range obj.GetAnnotations() { require.LessOrEqual(t, len(k), 63) } }