mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 21:50:05 +00:00
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:
@@ -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)
|
||||
|
@@ -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(®istrytest.ControllerRegistry{}, nil))
|
||||
registry := ®istrytest.ControllerRegistry{}
|
||||
test := resttest.New(t, NewREST(registry, nil), registry.SetError)
|
||||
test.TestCreate(
|
||||
// valid
|
||||
&api.ReplicationController{
|
||||
|
Reference in New Issue
Block a user