rename ResetBeforeCreate to PrepareForCreate

This commit is contained in:
Tim Hockin
2015-03-25 14:45:07 -07:00
parent 914ab94ae0
commit b2687c1a84
11 changed files with 23 additions and 22 deletions

View File

@@ -34,16 +34,17 @@ type RESTCreateStrategy interface {
// NamespaceScoped returns true if the object must be within a namespace. // NamespaceScoped returns true if the object must be within a namespace.
NamespaceScoped() bool NamespaceScoped() bool
// ResetBeforeCreate is invoked on create before validation to remove any fields // PrepareForCreate is invoked on create before validation to normalize
// that may not be persisted. // the object. For example: remove fields that are not to be persisted,
ResetBeforeCreate(obj runtime.Object) // sort order-insensitive list fields, etc.
PrepareForCreate(obj runtime.Object)
// Validate is invoked after default fields in the object have been filled in before // Validate is invoked after default fields in the object have been filled in before
// the object is persisted. // the object is persisted.
Validate(obj runtime.Object) fielderrors.ValidationErrorList Validate(obj runtime.Object) fielderrors.ValidationErrorList
} }
// BeforeCreate ensures that common operations for all resources are performed on creation. It only returns // BeforeCreate ensures that common operations for all resources are performed on creation. It only returns
// errors that can be converted to api.Status. It invokes ResetBeforeCreate, then GenerateName, then Validate. // errors that can be converted to api.Status. It invokes PrepareForCreate, then GenerateName, then Validate.
// It returns nil if the object should be created. // It returns nil if the object should be created.
func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Object) error { func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Object) error {
objectMeta, kind, kerr := objectMetaAndKind(strategy, obj) objectMeta, kind, kerr := objectMetaAndKind(strategy, obj)
@@ -58,7 +59,7 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Obje
} else { } else {
objectMeta.Namespace = api.NamespaceNone objectMeta.Namespace = api.NamespaceNone
} }
strategy.ResetBeforeCreate(obj) strategy.PrepareForCreate(obj)
api.FillObjectMetaSystemFields(ctx, objectMeta) api.FillObjectMetaSystemFields(ctx, objectMeta)
api.GenerateName(strategy, objectMeta) api.GenerateName(strategy, objectMeta)

View File

@@ -60,8 +60,8 @@ func (svcStrategy) NamespaceScoped() bool {
return true return true
} }
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. // PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (svcStrategy) ResetBeforeCreate(obj runtime.Object) { func (svcStrategy) PrepareForCreate(obj runtime.Object) {
service := obj.(*api.Service) service := obj.(*api.Service)
service.Status = api.ServiceStatus{} service.Status = api.ServiceStatus{}
} }

View File

@@ -42,8 +42,8 @@ func (rcStrategy) NamespaceScoped() bool {
return true return true
} }
// ResetBeforeCreate clears the status of a replication controller before creation. // PrepareForCreate clears the status of a replication controller before creation.
func (rcStrategy) ResetBeforeCreate(obj runtime.Object) { func (rcStrategy) PrepareForCreate(obj runtime.Object) {
controller := obj.(*api.ReplicationController) controller := obj.(*api.ReplicationController)
controller.Status = api.ReplicationControllerStatus{} controller.Status = api.ReplicationControllerStatus{}
} }

View File

@@ -43,8 +43,8 @@ func (endpointsStrategy) NamespaceScoped() bool {
return true return true
} }
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. // PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (endpointsStrategy) ResetBeforeCreate(obj runtime.Object) { func (endpointsStrategy) PrepareForCreate(obj runtime.Object) {
_ = obj.(*api.Endpoints) _ = obj.(*api.Endpoints)
} }

View File

@@ -43,7 +43,7 @@ type testRESTStrategy struct {
func (t *testRESTStrategy) NamespaceScoped() bool { return t.namespaceScoped } func (t *testRESTStrategy) NamespaceScoped() bool { return t.namespaceScoped }
func (t *testRESTStrategy) AllowCreateOnUpdate() bool { return t.allowCreateOnUpdate } func (t *testRESTStrategy) AllowCreateOnUpdate() bool { return t.allowCreateOnUpdate }
func (t *testRESTStrategy) ResetBeforeCreate(obj runtime.Object) {} func (t *testRESTStrategy) PrepareForCreate(obj runtime.Object) {}
func (t *testRESTStrategy) Validate(obj runtime.Object) fielderrors.ValidationErrorList { func (t *testRESTStrategy) Validate(obj runtime.Object) fielderrors.ValidationErrorList {
return nil return nil
} }

View File

@@ -53,8 +53,8 @@ func (nodeStrategy) AllowCreateOnUpdate() bool {
return false return false
} }
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. // PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (nodeStrategy) ResetBeforeCreate(obj runtime.Object) { func (nodeStrategy) PrepareForCreate(obj runtime.Object) {
_ = obj.(*api.Node) _ = obj.(*api.Node)
// Nodes allow *all* fields, including status, to be set. // Nodes allow *all* fields, including status, to be set.
} }

View File

@@ -43,8 +43,8 @@ func (namespaceStrategy) NamespaceScoped() bool {
return false return false
} }
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. // PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (namespaceStrategy) ResetBeforeCreate(obj runtime.Object) { func (namespaceStrategy) PrepareForCreate(obj runtime.Object) {
// on create, status is active // on create, status is active
namespace := obj.(*api.Namespace) namespace := obj.(*api.Namespace)
namespace.Status = api.NamespaceStatus{ namespace.Status = api.NamespaceStatus{

View File

@@ -33,7 +33,7 @@ func TestNamespaceStrategy(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo"}, ObjectMeta: api.ObjectMeta{Name: "foo"},
Status: api.NamespaceStatus{Phase: api.NamespaceTerminating}, Status: api.NamespaceStatus{Phase: api.NamespaceTerminating},
} }
Strategy.ResetBeforeCreate(namespace) Strategy.PrepareForCreate(namespace)
if namespace.Status.Phase != api.NamespaceActive { if namespace.Status.Phase != api.NamespaceActive {
t.Errorf("Namespaces do not allow setting phase on create") t.Errorf("Namespaces do not allow setting phase on create")
} }

View File

@@ -50,8 +50,8 @@ func (podStrategy) NamespaceScoped() bool {
return true return true
} }
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. // PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (podStrategy) ResetBeforeCreate(obj runtime.Object) { func (podStrategy) PrepareForCreate(obj runtime.Object) {
pod := obj.(*api.Pod) pod := obj.(*api.Pod)
pod.Status = api.PodStatus{ pod.Status = api.PodStatus{
Host: pod.Spec.Host, Host: pod.Spec.Host,

View File

@@ -43,8 +43,8 @@ func (resourcequotaStrategy) NamespaceScoped() bool {
return true return true
} }
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. // PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (resourcequotaStrategy) ResetBeforeCreate(obj runtime.Object) { func (resourcequotaStrategy) PrepareForCreate(obj runtime.Object) {
resourcequota := obj.(*api.ResourceQuota) resourcequota := obj.(*api.ResourceQuota)
resourcequota.Status = api.ResourceQuotaStatus{} resourcequota.Status = api.ResourceQuotaStatus{}
} }

View File

@@ -51,7 +51,7 @@ func TestResourceQuotaStrategy(t *testing.T) {
}, },
}, },
} }
Strategy.ResetBeforeCreate(resourceQuota) Strategy.PrepareForCreate(resourceQuota)
if resourceQuota.Status.Used != nil { if resourceQuota.Status.Used != nil {
t.Errorf("ResourceQuota does not allow setting status on create") t.Errorf("ResourceQuota does not allow setting status on create")
} }