Add REST PrepareForUpdate() hook
As per discussion with @snmarterclayton. I implemented this for most types in the "obvious" way. I am not sure how to implement this for a couple types, though.
This commit is contained in:
@@ -49,6 +49,13 @@ func (resourcequotaStrategy) PrepareForCreate(obj runtime.Object) {
|
||||
resourcequota.Status = api.ResourceQuotaStatus{}
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (resourcequotaStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||
newResourcequota := obj.(*api.ResourceQuota)
|
||||
oldResourcequota := old.(*api.ResourceQuota)
|
||||
newResourcequota.Status = oldResourcequota.Status
|
||||
}
|
||||
|
||||
// Validate validates a new resourcequota.
|
||||
func (resourcequotaStrategy) Validate(obj runtime.Object) fielderrors.ValidationErrorList {
|
||||
resourcequota := obj.(*api.ResourceQuota)
|
||||
@@ -71,6 +78,12 @@ type resourcequotaStatusStrategy struct {
|
||||
|
||||
var StatusStrategy = resourcequotaStatusStrategy{Strategy}
|
||||
|
||||
func (resourcequotaStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||
newResourcequota := obj.(*api.ResourceQuota)
|
||||
oldResourcequota := old.(*api.ResourceQuota)
|
||||
newResourcequota.Spec = oldResourcequota.Spec
|
||||
}
|
||||
|
||||
func (resourcequotaStatusStrategy) ValidateUpdate(obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidateResourceQuotaStatusUpdate(obj.(*api.ResourceQuota), old.(*api.ResourceQuota))
|
||||
}
|
||||
|
Reference in New Issue
Block a user