|
|
|
@@ -30,6 +30,7 @@ import (
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// FieldImmutableErrorMsg is a error message for field is immutable.
|
|
|
|
|
const FieldImmutableErrorMsg string = `field is immutable`
|
|
|
|
|
|
|
|
|
|
const totalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB
|
|
|
|
@@ -80,6 +81,7 @@ func validateOwnerReference(ownerReference metav1.OwnerReference, fldPath *field
|
|
|
|
|
return allErrs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ValidateOwnerReferences validates that a set of owner references are correctly defined.
|
|
|
|
|
func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *field.Path) field.ErrorList {
|
|
|
|
|
allErrs := field.ErrorList{}
|
|
|
|
|
controllerName := ""
|
|
|
|
@@ -97,7 +99,7 @@ func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *f
|
|
|
|
|
return allErrs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate finalizer names
|
|
|
|
|
// ValidateFinalizerName validates finalizer names.
|
|
|
|
|
func ValidateFinalizerName(stringValue string, fldPath *field.Path) field.ErrorList {
|
|
|
|
|
allErrs := field.ErrorList{}
|
|
|
|
|
for _, msg := range validation.IsQualifiedName(stringValue) {
|
|
|
|
@@ -107,6 +109,7 @@ func ValidateFinalizerName(stringValue string, fldPath *field.Path) field.ErrorL
|
|
|
|
|
return allErrs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ValidateNoNewFinalizers validates the new finalizers has no new finalizers compare to old finalizers.
|
|
|
|
|
func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fldPath *field.Path) field.ErrorList {
|
|
|
|
|
allErrs := field.ErrorList{}
|
|
|
|
|
extra := sets.NewString(newFinalizers...).Difference(sets.NewString(oldFinalizers...))
|
|
|
|
@@ -116,6 +119,7 @@ func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fld
|
|
|
|
|
return allErrs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ValidateImmutableField validates the new value and the old value are deeply equal.
|
|
|
|
|
func ValidateImmutableField(newVal, oldVal interface{}, fldPath *field.Path) field.ErrorList {
|
|
|
|
|
allErrs := field.ErrorList{}
|
|
|
|
|
if !apiequality.Semantic.DeepEqual(oldVal, newVal) {
|
|
|
|
@@ -137,7 +141,7 @@ func ValidateObjectMeta(objMeta *metav1.ObjectMeta, requiresNamespace bool, name
|
|
|
|
|
return ValidateObjectMetaAccessor(metadata, requiresNamespace, nameFn, fldPath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already
|
|
|
|
|
// ValidateObjectMetaAccessor validates an object's metadata on creation. It expects that name generation has already
|
|
|
|
|
// been performed.
|
|
|
|
|
// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
|
|
|
|
|
func ValidateObjectMetaAccessor(meta metav1.Object, requiresNamespace bool, nameFn ValidateNameFunc, fldPath *field.Path) field.ErrorList {
|
|
|
|
@@ -208,7 +212,7 @@ func ValidateFinalizers(finalizers []string, fldPath *field.Path) field.ErrorLis
|
|
|
|
|
return allErrs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ValidateObjectMetaUpdate validates an object's metadata when updated
|
|
|
|
|
// ValidateObjectMetaUpdate validates an object's metadata when updated.
|
|
|
|
|
func ValidateObjectMetaUpdate(newMeta, oldMeta *metav1.ObjectMeta, fldPath *field.Path) field.ErrorList {
|
|
|
|
|
newMetadata, err := meta.Accessor(newMeta)
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -225,6 +229,7 @@ func ValidateObjectMetaUpdate(newMeta, oldMeta *metav1.ObjectMeta, fldPath *fiel
|
|
|
|
|
return ValidateObjectMetaAccessorUpdate(newMetadata, oldMetadata, fldPath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ValidateObjectMetaAccessorUpdate validates an object's metadata when updated.
|
|
|
|
|
func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *field.Path) field.ErrorList {
|
|
|
|
|
var allErrs field.ErrorList
|
|
|
|
|
|
|
|
|
|