Add a generation number to the object meta of all objects, and status of rcs
This commit is contained in:
@@ -18,6 +18,7 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
@@ -47,6 +48,9 @@ func (rcStrategy) NamespaceScoped() bool {
|
||||
func (rcStrategy) PrepareForCreate(obj runtime.Object) {
|
||||
controller := obj.(*api.ReplicationController)
|
||||
controller.Status = api.ReplicationControllerStatus{}
|
||||
|
||||
controller.Generation = 1
|
||||
controller.Status.ObservedGeneration = 0
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
@@ -55,6 +59,23 @@ func (rcStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||
//newController := obj.(*api.ReplicationController)
|
||||
//oldController := old.(*api.ReplicationController)
|
||||
//newController.Status = oldController.Status
|
||||
newController := obj.(*api.ReplicationController)
|
||||
oldController := old.(*api.ReplicationController)
|
||||
|
||||
// Any changes to the spec increment the generation number, any changes to the
|
||||
// status should reflect the generation number of the corresponding object. We push
|
||||
// the burden of managing the status onto the clients because we can't (in general)
|
||||
// know here what version of spec the writer of the status has seen. It may seem like
|
||||
// we can at first -- since obj contains spec -- but in the future we will probably make
|
||||
// status its own object, and even if we don't, writes may be the result of a
|
||||
// read-update-write loop, so the contents of spec may not actually be the spec that
|
||||
// the controller has *seen*.
|
||||
//
|
||||
// TODO: Any changes to a part of the object that represents desired state (labels,
|
||||
// annotations etc) should also increment the generation.
|
||||
if !reflect.DeepEqual(oldController.Spec, newController.Spec) {
|
||||
newController.Generation = oldController.Generation + 1
|
||||
}
|
||||
}
|
||||
|
||||
// Validate validates a new replication controller.
|
||||
|
Reference in New Issue
Block a user