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

@@ -68,6 +68,14 @@ func (namespaceStrategy) PrepareForCreate(obj runtime.Object) {
}
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func (namespaceStrategy) PrepareForUpdate(obj, old runtime.Object) {
newNamespace := obj.(*api.Namespace)
oldNamespace := old.(*api.Namespace)
newNamespace.Spec.Finalizers = oldNamespace.Spec.Finalizers
newNamespace.Status = oldNamespace.Status
}
// Validate validates a new namespace.
func (namespaceStrategy) Validate(obj runtime.Object) fielderrors.ValidationErrorList {
namespace := obj.(*api.Namespace)
@@ -90,6 +98,12 @@ type namespaceStatusStrategy struct {
var StatusStrategy = namespaceStatusStrategy{Strategy}
func (namespaceStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newNamespace := obj.(*api.Namespace)
oldNamespace := old.(*api.Namespace)
newNamespace.Spec = oldNamespace.Spec
}
func (namespaceStatusStrategy) ValidateUpdate(obj, old runtime.Object) fielderrors.ValidationErrorList {
return validation.ValidateNamespaceStatusUpdate(obj.(*api.Namespace), old.(*api.Namespace))
}