@@ -30,6 +30,7 @@ import (
30
30
"k8s.io/apimachinery/pkg/util/validation/field"
31
31
)
32
32
33
+ // FieldImmutableErrorMsg is a error message for field is immutable.
33
34
const FieldImmutableErrorMsg string = `field is immutable`
34
35
35
36
const totalAnnotationSizeLimitB int = 256 * (1 << 10 ) // 256 kB
@@ -80,6 +81,7 @@ func validateOwnerReference(ownerReference metav1.OwnerReference, fldPath *field
80
81
return allErrs
81
82
}
82
83
84
+ // ValidateOwnerReferences validates that a set of owner references are correctly defined.
83
85
func ValidateOwnerReferences (ownerReferences []metav1.OwnerReference , fldPath * field.Path ) field.ErrorList {
84
86
allErrs := field.ErrorList {}
85
87
controllerName := ""
@@ -97,7 +99,7 @@ func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *f
97
99
return allErrs
98
100
}
99
101
100
- // Validate finalizer names
102
+ // ValidateFinalizerName validates finalizer names.
101
103
func ValidateFinalizerName (stringValue string , fldPath * field.Path ) field.ErrorList {
102
104
allErrs := field.ErrorList {}
103
105
for _ , msg := range validation .IsQualifiedName (stringValue ) {
@@ -107,6 +109,7 @@ func ValidateFinalizerName(stringValue string, fldPath *field.Path) field.ErrorL
107
109
return allErrs
108
110
}
109
111
112
+ // ValidateNoNewFinalizers validates the new finalizers has no new finalizers compare to old finalizers.
110
113
func ValidateNoNewFinalizers (newFinalizers []string , oldFinalizers []string , fldPath * field.Path ) field.ErrorList {
111
114
allErrs := field.ErrorList {}
112
115
extra := sets .NewString (newFinalizers ... ).Difference (sets .NewString (oldFinalizers ... ))
@@ -116,6 +119,7 @@ func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fld
116
119
return allErrs
117
120
}
118
121
122
+ // ValidateImmutableField validates the new value and the old value are deeply equal.
119
123
func ValidateImmutableField (newVal , oldVal interface {}, fldPath * field.Path ) field.ErrorList {
120
124
allErrs := field.ErrorList {}
121
125
if ! apiequality .Semantic .DeepEqual (oldVal , newVal ) {
@@ -137,7 +141,7 @@ func ValidateObjectMeta(objMeta *metav1.ObjectMeta, requiresNamespace bool, name
137
141
return ValidateObjectMetaAccessor (metadata , requiresNamespace , nameFn , fldPath )
138
142
}
139
143
140
- // ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already
144
+ // ValidateObjectMetaAccessor validates an object's metadata on creation. It expects that name generation has already
141
145
// been performed.
142
146
// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
143
147
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
208
212
return allErrs
209
213
}
210
214
211
- // ValidateObjectMetaUpdate validates an object's metadata when updated
215
+ // ValidateObjectMetaUpdate validates an object's metadata when updated.
212
216
func ValidateObjectMetaUpdate (newMeta , oldMeta * metav1.ObjectMeta , fldPath * field.Path ) field.ErrorList {
213
217
newMetadata , err := meta .Accessor (newMeta )
214
218
if err != nil {
@@ -225,6 +229,7 @@ func ValidateObjectMetaUpdate(newMeta, oldMeta *metav1.ObjectMeta, fldPath *fiel
225
229
return ValidateObjectMetaAccessorUpdate (newMetadata , oldMetadata , fldPath )
226
230
}
227
231
232
+ // ValidateObjectMetaAccessorUpdate validates an object's metadata when updated.
228
233
func ValidateObjectMetaAccessorUpdate (newMeta , oldMeta metav1.Object , fldPath * field.Path ) field.ErrorList {
229
234
var allErrs field.ErrorList
230
235
0 commit comments