Turn 409 into 500 Try Again Later when using generateName

If a client says they want the name to be generated, a 409 is
not appropriate (since they didn't specify a name). Instead, we
should return the next most appropriate error, which is a 5xx
error indicating the request failed but the client *should* try
again.  Since there is no 5xx error that exactly fits this purpose,
use 500 with StatusReasonTryAgainLater set.

This commit does not implement client retry on TryAgainLater, but
clients should retry up to a certain number of times.
This commit is contained in:
Clayton Coleman
2015-01-28 23:11:29 -05:00
parent e485dc93ca
commit 1588970ec4
21 changed files with 237 additions and 18 deletions

View File

@@ -62,6 +62,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
return apiserver.MakeAsync(func() (runtime.Object, error) {
if err := rs.registry.CreateController(ctx, controller); err != nil {
err = rest.CheckGeneratedNameError(rest.ReplicationControllers, err, controller)
return apiserver.RESTResult{}, err
}
return rs.registry.GetController(ctx, controller.Name)

View File

@@ -51,7 +51,9 @@ func TestListControllersError(t *testing.T) {
}
func TestListEmptyControllerList(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{nil, &api.ReplicationControllerList{ListMeta: api.ListMeta{ResourceVersion: "1"}}}
mockRegistry := registrytest.ControllerRegistry{
Controllers: &api.ReplicationControllerList{ListMeta: api.ListMeta{ResourceVersion: "1"}},
}
storage := REST{
registry: &mockRegistry,
}
@@ -444,7 +446,8 @@ func TestUpdateControllerWithConflictingNamespace(t *testing.T) {
}
func TestCreate(t *testing.T) {
test := resttest.New(t, NewREST(&registrytest.ControllerRegistry{}, nil))
registry := &registrytest.ControllerRegistry{}
test := resttest.New(t, NewREST(registry, nil), registry.SetError)
test.TestCreate(
// valid
&api.ReplicationController{