mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 21:50:05 +00:00
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:
@@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user