Skip to content

Commit

Permalink
labels: disable label kv length check
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Song <yansong.ys@antgroup.com>
  • Loading branch information
imeoer committed Feb 10, 2025
1 parent 571e38a commit 79a9cbb
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions labels/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

package labels

import (
"fmt"
"strings"

"github.com/containerd/errdefs"
)

const (
maxSize = 4096
// maximum length of key portion of error message if len of key + len of value > maxSize
Expand All @@ -32,24 +25,7 @@ const (
// HACK (imeoer): we need to ignore the specified image
// label kv length check for nydus / estargz images,
// which have some labels with 4k+ length.
var ignoredKeyPrefixes = []string{
"containerd.io/snapshot/nydus",
"containerd.io/snapshot/remote/stargz",
}

// Validate a label's key and value are under 4096 bytes
func Validate(k, v string) error {
for _, keyPrefix := range ignoredKeyPrefixes {
if strings.HasPrefix(k, keyPrefix) {
return nil
}
}
total := len(k) + len(v)
if total > maxSize {
if len(k) > keyMaxLen {
k = k[:keyMaxLen]
}
return fmt.Errorf("label key and value length (%d bytes) greater than maximum size (%d bytes), key: %s: %w", total, maxSize, k, errdefs.ErrInvalidArgument)
}
return nil
}

0 comments on commit 79a9cbb

Please sign in to comment.