Plumb context to strategy methods

This commit is contained in:
Jordan Liggitt
2016-08-08 16:15:33 -04:00
parent 16621cd32d
commit 4db004972a
58 changed files with 166 additions and 165 deletions

View File

@@ -47,7 +47,7 @@ func (rcStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a replication controller before creation.
func (rcStrategy) PrepareForCreate(obj runtime.Object) {
func (rcStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
controller := obj.(*api.ReplicationController)
controller.Status = api.ReplicationControllerStatus{}
@@ -55,7 +55,7 @@ func (rcStrategy) PrepareForCreate(obj runtime.Object) {
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func (rcStrategy) PrepareForUpdate(obj, old runtime.Object) {
func (rcStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
newController := obj.(*api.ReplicationController)
oldController := old.(*api.ReplicationController)
// update is not allowed to set status
@@ -133,7 +133,7 @@ type rcStatusStrategy struct {
var StatusStrategy = rcStatusStrategy{Strategy}
func (rcStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
func (rcStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
newRc := obj.(*api.ReplicationController)
oldRc := old.(*api.ReplicationController)
// update is not allowed to set spec

View File

@@ -59,7 +59,7 @@ func TestControllerStrategy(t *testing.T) {
},
}
Strategy.PrepareForCreate(rc)
Strategy.PrepareForCreate(ctx, rc)
if rc.Status.Replicas != 0 {
t.Error("ReplicationController should not allow setting status.replicas on create")
}
@@ -74,7 +74,7 @@ func TestControllerStrategy(t *testing.T) {
invalidRc := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "bar", ResourceVersion: "4"},
}
Strategy.PrepareForUpdate(invalidRc, rc)
Strategy.PrepareForUpdate(ctx, invalidRc, rc)
errs = Strategy.ValidateUpdate(ctx, invalidRc, rc)
if len(errs) == 0 {
t.Errorf("Expected a validation error")
@@ -129,7 +129,7 @@ func TestControllerStatusStrategy(t *testing.T) {
ObservedGeneration: int64(11),
},
}
StatusStrategy.PrepareForUpdate(newController, oldController)
StatusStrategy.PrepareForUpdate(ctx, newController, oldController)
if newController.Status.Replicas != 3 {
t.Errorf("Replication controller status updates should allow change of replicas: %v", newController.Status.Replicas)
}