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:
Tim Hockin
2015-03-25 17:03:30 -07:00
parent b2687c1a84
commit 0f36c68244
9 changed files with 76 additions and 1 deletions

View File

@@ -59,6 +59,13 @@ func (podStrategy) PrepareForCreate(obj runtime.Object) {
}
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func (podStrategy) PrepareForUpdate(obj, old runtime.Object) {
newPod := obj.(*api.Pod)
oldPod := old.(*api.Pod)
newPod.Status = oldPod.Status
}
// Validate validates a new pod.
func (podStrategy) Validate(obj runtime.Object) fielderrors.ValidationErrorList {
pod := obj.(*api.Pod)
@@ -86,6 +93,12 @@ type podStatusStrategy struct {
var StatusStrategy = podStatusStrategy{Strategy}
func (podStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newPod := obj.(*api.Pod)
oldPod := old.(*api.Pod)
newPod.Spec = oldPod.Spec
}
func (podStatusStrategy) ValidateUpdate(obj, old runtime.Object) fielderrors.ValidationErrorList {
// TODO: merge valid fields after update
return validation.ValidatePodStatusUpdate(obj.(*api.Pod), old.(*api.Pod))