mirror of https://github.com/k3s-io/k3s
Merge pull request #6614 from brendandburns/validate
Add Validate in addition to ValidateUpdate to validation for most resources.pull/6/head
commit
c72dc15e8e
|
@ -1225,6 +1225,7 @@ func validateFinalizerName(stringValue string) errs.ValidationErrorList {
|
|||
|
||||
// ValidateNamespaceUpdate tests to make sure a namespace update can be applied.
|
||||
// newNamespace is updated with fields that cannot be changed
|
||||
// TODO The syntax here is the reverse of the (old, new) pattern in most other validation. Fix this.
|
||||
func ValidateNamespaceUpdate(newNamespace *api.Namespace, oldNamespace *api.Namespace) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, ValidateObjectMetaUpdate(&oldNamespace.ObjectMeta, &newNamespace.ObjectMeta).Prefix("metadata")...)
|
||||
|
|
|
@ -71,7 +71,9 @@ func (rcStrategy) AllowCreateOnUpdate() bool {
|
|||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (rcStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidateReplicationControllerUpdate(old.(*api.ReplicationController), obj.(*api.ReplicationController))
|
||||
validationErrorList := validation.ValidateReplicationController(obj.(*api.ReplicationController))
|
||||
updateErrorList := validation.ValidateReplicationControllerUpdate(old.(*api.ReplicationController), obj.(*api.ReplicationController))
|
||||
return append(validationErrorList, updateErrorList...)
|
||||
}
|
||||
|
||||
// ControllerToSelectableFields returns a label set that represents the object.
|
||||
|
|
|
@ -69,7 +69,8 @@ func (endpointsStrategy) AllowCreateOnUpdate() bool {
|
|||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (endpointsStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidateEndpointsUpdate(old.(*api.Endpoints), obj.(*api.Endpoints))
|
||||
errorList := validation.ValidateEndpoints(obj.(*api.Endpoints))
|
||||
return append(errorList, validation.ValidateEndpointsUpdate(old.(*api.Endpoints), obj.(*api.Endpoints))...)
|
||||
}
|
||||
|
||||
// MatchEndpoints returns a generic matcher for a given label and field selector.
|
||||
|
|
|
@ -74,7 +74,8 @@ func (nodeStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.Va
|
|||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (nodeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidateMinionUpdate(old.(*api.Node), obj.(*api.Node))
|
||||
errorList := validation.ValidateMinion(obj.(*api.Node))
|
||||
return append(errorList, validation.ValidateMinionUpdate(old.(*api.Node), obj.(*api.Node))...)
|
||||
}
|
||||
|
||||
// ResourceGetter is an interface for retrieving resources by ResourceLocation.
|
||||
|
|
|
@ -89,7 +89,8 @@ func (namespaceStrategy) AllowCreateOnUpdate() bool {
|
|||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (namespaceStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidateNamespaceUpdate(obj.(*api.Namespace), old.(*api.Namespace))
|
||||
errorList := validation.ValidateNamespace(obj.(*api.Namespace))
|
||||
return append(errorList, validation.ValidateNamespaceUpdate(obj.(*api.Namespace), old.(*api.Namespace))...)
|
||||
}
|
||||
|
||||
type namespaceStatusStrategy struct {
|
||||
|
|
|
@ -65,7 +65,8 @@ func (persistentvolumeStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
|||
}
|
||||
|
||||
func (persistentvolumeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidatePersistentVolumeUpdate(obj.(*api.PersistentVolume), old.(*api.PersistentVolume))
|
||||
errorList := validation.ValidatePersistentVolume(obj.(*api.PersistentVolume))
|
||||
return append(errorList, validation.ValidatePersistentVolumeUpdate(obj.(*api.PersistentVolume), old.(*api.PersistentVolume))...)
|
||||
}
|
||||
|
||||
type persistentvolumeStatusStrategy struct {
|
||||
|
|
|
@ -65,7 +65,8 @@ func (persistentvolumeclaimStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
|||
}
|
||||
|
||||
func (persistentvolumeclaimStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidatePersistentVolumeClaimUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))
|
||||
errorList := validation.ValidatePersistentVolumeClaim(obj.(*api.PersistentVolumeClaim))
|
||||
return append(errorList, validation.ValidatePersistentVolumeClaimUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))...)
|
||||
}
|
||||
|
||||
type persistentvolumeclaimStatusStrategy struct {
|
||||
|
|
|
@ -1062,6 +1062,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
|
|||
Host: "machine",
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: "foobar",
|
||||
Image: "foo:v1",
|
||||
},
|
||||
},
|
||||
|
@ -1080,6 +1081,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
|
|||
Host: "machine",
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: "foobar",
|
||||
Image: "foo:v2",
|
||||
ImagePullPolicy: api.PullIfNotPresent,
|
||||
TerminationMessagePath: api.TerminationMessagePathDefault,
|
||||
|
|
|
@ -79,7 +79,8 @@ func (podStrategy) AllowCreateOnUpdate() bool {
|
|||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (podStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod))
|
||||
errorList := validation.ValidatePod(obj.(*api.Pod))
|
||||
return append(errorList, validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod))...)
|
||||
}
|
||||
|
||||
// CheckGracefulDelete allows a pod to be gracefully deleted.
|
||||
|
|
|
@ -69,7 +69,8 @@ func (resourcequotaStrategy) AllowCreateOnUpdate() bool {
|
|||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (resourcequotaStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidateResourceQuotaUpdate(obj.(*api.ResourceQuota), old.(*api.ResourceQuota))
|
||||
errorList := validation.ValidateResourceQuota(obj.(*api.ResourceQuota))
|
||||
return append(errorList, validation.ValidateResourceQuotaUpdate(obj.(*api.ResourceQuota), old.(*api.ResourceQuota))...)
|
||||
}
|
||||
|
||||
type resourcequotaStatusStrategy struct {
|
||||
|
|
Loading…
Reference in New Issue