Documentation
¶
Overview ¶
Package validation contains generic api type validation functions.
Index ¶
- Constants
- Variables
- func NameIsDNS1035Label(name string, prefix bool) []string
- func NameIsDNSLabel(name string, prefix bool) []string
- func NameIsDNSSubdomain(name string, prefix bool) []string
- func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList
- func ValidateAnnotationsSize(annotations map[string]string) error
- func ValidateFinalizerName(stringValue string, fldPath *field.Path) field.ErrorList
- func ValidateFinalizers(finalizers []string, fldPath *field.Path) field.ErrorList
- func ValidateImmutableField(newVal, oldVal interface{}, fldPath *field.Path) field.ErrorList
- func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fldPath *field.Path) field.ErrorList
- func ValidateNonnegativeField(value int64, fldPath *field.Path) field.ErrorList
- func ValidateObjectMeta(objMeta *metav1.ObjectMeta, requiresNamespace bool, nameFn ValidateNameFunc, ...) field.ErrorList
- func ValidateObjectMetaAccessor(meta metav1.Object, requiresNamespace bool, nameFn ValidateNameFunc, ...) field.ErrorList
- func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *field.Path) field.ErrorList
- func ValidateObjectMetaAccessorWithOpts(meta metav1.Object, isNamespaced bool, nameFn ValidateNameFuncWithErrors, ...) field.ErrorList
- func ValidateObjectMetaUpdate(newMeta, oldMeta *metav1.ObjectMeta, fldPath *field.Path) field.ErrorList
- func ValidateObjectMetaWithOpts(objMeta *metav1.ObjectMeta, isNamespaced bool, ...) field.ErrorList
- func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *field.Path) field.ErrorList
- type ObjectMetaValidationOption
- type ValidateNameFunc
- type ValidateNameFuncWithErrors
Constants ¶
const FieldImmutableErrorMsg string = `field is immutable`
FieldImmutableErrorMsg is a error message for field is immutable.
const IsNegativeErrorMsg string = `must be greater than or equal to 0`
IsNegativeErrorMsg is a error message for value must be greater than or equal to 0.
const TotalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB
Variables ¶
var BannedOwners = map[schema.GroupVersionKind]struct{}{
{Group: "", Version: "v1", Kind: "Event"}: {},
}
BannedOwners is a black list of object that are not allowed to be owners.
var ValidateNamespaceName = NameIsDNSLabel
ValidateNamespaceName can be used to check whether the given namespace name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.
var ValidateServiceAccountName = NameIsDNSSubdomain
ValidateServiceAccountName can be used to check whether the given service account name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.
Functions ¶
func NameIsDNS1035Label ¶
NameIsDNS1035Label is a ValidateNameFunc for names that must be a DNS 952 label.
func NameIsDNSLabel ¶
NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.
func NameIsDNSSubdomain ¶
NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain.
func ValidateAnnotations ¶
ValidateAnnotations validates that a set of annotations are correctly defined.
func ValidateAnnotationsSize ¶ added in v0.22.0
func ValidateFinalizerName ¶
ValidateFinalizerName validates finalizer names.
func ValidateFinalizers ¶
ValidateFinalizers tests if the finalizers name are valid, and if there are conflicting finalizers.
func ValidateImmutableField ¶
ValidateImmutableField validates the new value and the old value are deeply equal.
func ValidateNoNewFinalizers ¶
func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fldPath *field.Path) field.ErrorList
ValidateNoNewFinalizers validates the new finalizers has no new finalizers compare to old finalizers.
func ValidateNonnegativeField ¶
ValidateNonnegativeField validates that given value is not negative.
func ValidateObjectMeta ¶
func ValidateObjectMeta(objMeta *metav1.ObjectMeta, requiresNamespace bool, nameFn ValidateNameFunc, fldPath *field.Path) field.ErrorList
ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already been performed.
func ValidateObjectMetaAccessor ¶
func ValidateObjectMetaAccessor(meta metav1.Object, requiresNamespace bool, nameFn ValidateNameFunc, fldPath *field.Path) field.ErrorList
ValidateObjectMetaAccessor validates an object's metadata on creation. It expects that name generation has already been performed.
func ValidateObjectMetaAccessorUpdate ¶
func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *field.Path) field.ErrorList
ValidateObjectMetaAccessorUpdate validates an object's metadata when updated.
func ValidateObjectMetaAccessorWithOpts ¶ added in v0.35.0
func ValidateObjectMetaAccessorWithOpts(meta metav1.Object, isNamespaced bool, nameFn ValidateNameFuncWithErrors, fldPath *field.Path, options ...ObjectMetaValidationOption) field.ErrorList
ValidateObjectMetaAccessorWithOpts validates an object's metadata on creation. It expects that name generation has already been performed, so name validation is always executed.
This is similar to ValidateObjectMetaAccessor, but uses options to buy future-safety and uses different signature for the name validation function. It also does not directly validate the generateName field, because name generation should have already been performed and it is the result of that generastion that must conform to the nameFn.
func ValidateObjectMetaUpdate ¶
func ValidateObjectMetaUpdate(newMeta, oldMeta *metav1.ObjectMeta, fldPath *field.Path) field.ErrorList
ValidateObjectMetaUpdate validates an object's metadata when updated.
func ValidateObjectMetaWithOpts ¶ added in v0.35.0
func ValidateObjectMetaWithOpts(objMeta *metav1.ObjectMeta, isNamespaced bool, nameFn ValidateNameFuncWithErrors, fldPath *field.Path, options ...ObjectMetaValidationOption) field.ErrorList
ValidateObjectMetaWithOpts validates an object's metadata on creation. It expects that name generation has already been performed, so name validation is always executed.
This is similar to ValidateObjectMeta, but uses options to buy future-safety and uses different signature for the name validation function. It also does not directly validate the generateName field, because name generation should have already been performed and it is the result of that generastion that must conform to the nameFn.
func ValidateOwnerReferences ¶
func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *field.Path) field.ErrorList
ValidateOwnerReferences validates that a set of owner references are correctly defined.
Types ¶
type ObjectMetaValidationOption ¶ added in v0.35.0
type ObjectMetaValidationOption func(opts *objectMetaValidationOptions)
ObjectMetaValidationOption specifies a behavioral modifier for ValidateObjectMetaWithOpts and ValidateObjectMetaAccessorWithOpts.
type ValidateNameFunc ¶
ValidateNameFunc validates that the provided name is valid for a given resource type. Not all resources have the same validation rules for names. Prefix is true if the name will have a value appended to it. If the name is not valid, this returns a list of descriptions of individual characteristics of the value that were not valid. Otherwise this returns an empty list or nil.
type ValidateNameFuncWithErrors ¶ added in v0.35.0
ValidateNameFuncWithErrors validates that the provided name is valid for a given resource type.
This is similar to ValidateNameFunc, except that it produces an ErrorList.