Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax of annotation values in Kubernetes?

Tags:

kubernetes

According to Kubernetes documentation

The metadata in an annotation can be small or large, structured or unstructured, and can include characters not permitted by labels.

Annotations, like labels, are key/value maps

Then there is a detailed explanation on the syntax of the annotation keys. But it says nothing about the value part.

Where can I find more about the allowed length and character set for the value of an annotation in Kubernetes?

like image 719
Thomas Avatar asked Nov 03 '25 13:11

Thomas


1 Answers

Here you can find the code that validates annotations in current master:

func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList {
    allErrs := field.ErrorList{}
    for k := range annotations {
        for _, msg := range validation.IsQualifiedName(strings.ToLower(k)) {
            allErrs = append(allErrs, field.Invalid(fldPath, k, msg))
        }
    }
    if err := ValidateAnnotationsSize(annotations); err != nil {
        allErrs = append(allErrs, field.TooLong(fldPath, "", TotalAnnotationSizeLimitB))
    }
    return allErrs
}

The keys are validated according to the rules that you mentioned. The only validation applied to the values is the total length of all annotations (size of keys + size of values for all annotations) that can't be longer than 256 kB.

const TotalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB

...

func ValidateAnnotationsSize(annotations map[string]string) error {
    var totalSize int64
    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)
    }
    return nil
}
like image 197
whites11 Avatar answered Nov 06 '25 03:11

whites11