mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 22:53:22 +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:
@@ -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))
|
||||
|
Reference in New Issue
Block a user