Plumb context to strategy methods
This commit is contained in:
@@ -44,7 +44,7 @@ func (namespaceStrategy) NamespaceScoped() bool {
|
||||
}
|
||||
|
||||
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
|
||||
func (namespaceStrategy) PrepareForCreate(obj runtime.Object) {
|
||||
func (namespaceStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
// on create, status is active
|
||||
namespace := obj.(*api.Namespace)
|
||||
namespace.Status = api.NamespaceStatus{
|
||||
@@ -69,7 +69,7 @@ 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) {
|
||||
func (namespaceStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
newNamespace := obj.(*api.Namespace)
|
||||
oldNamespace := old.(*api.Namespace)
|
||||
newNamespace.Spec.Finalizers = oldNamespace.Spec.Finalizers
|
||||
@@ -107,7 +107,7 @@ type namespaceStatusStrategy struct {
|
||||
|
||||
var StatusStrategy = namespaceStatusStrategy{Strategy}
|
||||
|
||||
func (namespaceStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||
func (namespaceStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
newNamespace := obj.(*api.Namespace)
|
||||
oldNamespace := old.(*api.Namespace)
|
||||
newNamespace.Spec = oldNamespace.Spec
|
||||
@@ -128,7 +128,7 @@ func (namespaceFinalizeStrategy) ValidateUpdate(ctx api.Context, obj, old runtim
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (namespaceFinalizeStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||
func (namespaceFinalizeStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
newNamespace := obj.(*api.Namespace)
|
||||
oldNamespace := old.(*api.Namespace)
|
||||
newNamespace.Status = oldNamespace.Status
|
||||
|
@@ -37,7 +37,7 @@ func TestNamespaceStrategy(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "10"},
|
||||
Status: api.NamespaceStatus{Phase: api.NamespaceTerminating},
|
||||
}
|
||||
Strategy.PrepareForCreate(namespace)
|
||||
Strategy.PrepareForCreate(ctx, namespace)
|
||||
if namespace.Status.Phase != api.NamespaceActive {
|
||||
t.Errorf("Namespaces do not allow setting phase on create")
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func TestNamespaceStrategy(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar", ResourceVersion: "4"},
|
||||
}
|
||||
// ensure we copy spec.finalizers from old to new
|
||||
Strategy.PrepareForUpdate(invalidNamespace, namespace)
|
||||
Strategy.PrepareForUpdate(ctx, invalidNamespace, namespace)
|
||||
if len(invalidNamespace.Spec.Finalizers) != 1 || invalidNamespace.Spec.Finalizers[0] != api.FinalizerKubernetes {
|
||||
t.Errorf("PrepareForUpdate should have preserved old.spec.finalizers")
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func TestNamespaceStatusStrategy(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "9", DeletionTimestamp: &now},
|
||||
Status: api.NamespaceStatus{Phase: api.NamespaceTerminating},
|
||||
}
|
||||
StatusStrategy.PrepareForUpdate(namespace, oldNamespace)
|
||||
StatusStrategy.PrepareForUpdate(ctx, namespace, oldNamespace)
|
||||
if namespace.Status.Phase != api.NamespaceTerminating {
|
||||
t.Errorf("Namespace status updates should allow change of phase: %v", namespace.Status.Phase)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func TestNamespaceFinalizeStrategy(t *testing.T) {
|
||||
Spec: api.NamespaceSpec{Finalizers: []api.FinalizerName{"example.com/foo"}},
|
||||
Status: api.NamespaceStatus{Phase: api.NamespaceTerminating},
|
||||
}
|
||||
FinalizeStrategy.PrepareForUpdate(namespace, oldNamespace)
|
||||
FinalizeStrategy.PrepareForUpdate(ctx, namespace, oldNamespace)
|
||||
if namespace.Status.Phase != api.NamespaceActive {
|
||||
t.Errorf("finalize updates should not allow change of phase: %v", namespace.Status.Phase)
|
||||
}
|
||||
|
Reference in New Issue
Block a user