From a01d02b7fd0af15abf4a76c2466527e9a3988e0a Mon Sep 17 00:00:00 2001 From: "Julian V. Modesto" Date: Tue, 18 May 2021 17:28:11 -0400 Subject: [PATCH 1/2] Make validation totalAnnotationSizeLimitB public. Replace the forked totalAnnotationSizeLimitB with apimachineryvalidation.TotalAnnotationSizeLimitB. Kubernetes-commit: 55ff96301797a503b6ee1d09f0eb2ffc827f01b1 --- pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go b/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go index ad651a2b5..551661a06 100644 --- a/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go +++ b/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go @@ -21,12 +21,11 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" + apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" ) -const totalAnnotationSizeLimitB int64 = 256 * (1 << 10) // 256 kB - type lastAppliedUpdater struct { fieldManager Manager } @@ -126,8 +125,8 @@ func isAnnotationsValid(annotations map[string]string) error { for k, v := range annotations { totalSize += (int64)(len(k)) + (int64)(len(v)) } - if totalSize > (int64)(totalAnnotationSizeLimitB) { - return fmt.Errorf("annotations size %d is larger than limit %d", totalSize, totalAnnotationSizeLimitB) + if totalSize > (int64)(apimachineryvalidation.TotalAnnotationSizeLimitB) { + return fmt.Errorf("annotations size %d is larger than limit %d", totalSize, apimachineryvalidation.TotalAnnotationSizeLimitB) } return nil } From f753bce9f869811faad5dd300aa856fae19ac6e4 Mon Sep 17 00:00:00 2001 From: "Julian V. Modesto" Date: Tue, 25 May 2021 16:01:38 -0400 Subject: [PATCH 2/2] Make a public ValidateAnnotationsSize Kubernetes-commit: 2e771b8e745c4a3be0d5bae3a6dc94087284c73b --- .../handlers/fieldmanager/lastappliedupdater.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go b/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go index 551661a06..7cd4eb128 100644 --- a/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go +++ b/pkg/endpoints/handlers/fieldmanager/lastappliedupdater.go @@ -93,7 +93,7 @@ func setLastApplied(obj runtime.Object, value string) error { annotations = map[string]string{} } annotations[corev1.LastAppliedConfigAnnotation] = value - if isAnnotationsValid(annotations) != nil { + if err := apimachineryvalidation.ValidateAnnotationsSize(annotations); err != nil { delete(annotations, corev1.LastAppliedConfigAnnotation) } accessor.SetAnnotations(annotations) @@ -119,14 +119,3 @@ func buildLastApplied(obj runtime.Object) (string, error) { } return string(lastApplied), nil } - -func isAnnotationsValid(annotations map[string]string) error { - var totalSize int64 - for k, v := range annotations { - totalSize += (int64)(len(k)) + (int64)(len(v)) - } - if totalSize > (int64)(apimachineryvalidation.TotalAnnotationSizeLimitB) { - return fmt.Errorf("annotations size %d is larger than limit %d", totalSize, apimachineryvalidation.TotalAnnotationSizeLimitB) - } - return nil -}