mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
Make endpoints return 400 instead of 500
This commit is contained in:
@@ -17,10 +17,10 @@ limitations under the License.
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@@ -48,7 +48,7 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
// List satisfies the RESTStorage interface.
|
||||
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
if !label.Empty() || !field.Empty() {
|
||||
return nil, errors.New("label/field selectors are not supported on endpoints")
|
||||
return nil, errors.NewBadRequest("label/field selectors are not supported on endpoints")
|
||||
}
|
||||
return rs.registry.ListEndpoints(ctx)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
|
||||
|
||||
// Delete satisfies the RESTStorage interface but is unimplemented.
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (<-chan apiserver.RESTResult, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
return nil, errors.NewBadRequest("Endpoints are read-only")
|
||||
}
|
||||
|
||||
// New implements the RESTStorage interface.
|
||||
|
@@ -96,3 +96,14 @@ func TestEndpointsRegistryList(t *testing.T) {
|
||||
t.Errorf("Unexpected resource version: %#v", sl)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointsRegistryDelete(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
storage := NewREST(registry)
|
||||
_, err := storage.Delete(api.NewContext(), "n/a")
|
||||
if err == nil {
|
||||
t.Error("unexpected non-error")
|
||||
} else if !errors.IsBadRequest(err) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user