mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
move api/errors to apimachinery
This commit is contained in:
parent
eb9f953496
commit
680ce72c07
@ -1,54 +0,0 @@
|
|||||||
package(default_visibility = ["//visibility:public"])
|
|
||||||
|
|
||||||
licenses(["notice"])
|
|
||||||
|
|
||||||
load(
|
|
||||||
"@io_bazel_rules_go//go:def.bzl",
|
|
||||||
"go_library",
|
|
||||||
"go_test",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_library(
|
|
||||||
name = "go_default_library",
|
|
||||||
srcs = [
|
|
||||||
"doc.go",
|
|
||||||
"errors.go",
|
|
||||||
],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
deps = [
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/runtime",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/util/validation/field",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
go_test(
|
|
||||||
name = "go_default_test",
|
|
||||||
srcs = ["errors_test.go"],
|
|
||||||
library = ":go_default_library",
|
|
||||||
tags = ["automanaged"],
|
|
||||||
deps = [
|
|
||||||
"//pkg/api:go_default_library",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/runtime",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
|
|
||||||
"//vendor:k8s.io/apimachinery/pkg/util/validation/field",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "package-srcs",
|
|
||||||
srcs = glob(["**"]),
|
|
||||||
tags = ["automanaged"],
|
|
||||||
visibility = ["//visibility:private"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "all-srcs",
|
|
||||||
srcs = [
|
|
||||||
":package-srcs",
|
|
||||||
"//pkg/api/errors/storage:all-srcs",
|
|
||||||
],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
)
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2014 The Kubernetes Authors.
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -14,5 +14,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package errors provides detailed error types for api field validation.
|
// Package errors is for verify-godeps.sh and is temporary
|
||||||
package errors // import "k8s.io/kubernetes/pkg/api/errors"
|
// TODO apimachinery remove this empty package. Godep fails without this because heapster relies
|
||||||
|
// on this package. This will allow us to start splitting packages, but will force
|
||||||
|
// heapster to update on their next kube rebase.
|
||||||
|
package errors
|
||||||
|
18
staging/src/k8s.io/apimachinery/pkg/api/errors/doc.go
Normal file
18
staging/src/k8s.io/apimachinery/pkg/api/errors/doc.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2014 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package errors provides detailed error types for api field validation.
|
||||||
|
package errors // import "k8s.io/kubernetes/pkg/api/errors"
|
@ -26,11 +26,17 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func resource(resource string) schema.GroupResource {
|
||||||
|
return schema.GroupResource{Group: "", Resource: resource}
|
||||||
|
}
|
||||||
|
func kind(kind string) schema.GroupKind {
|
||||||
|
return schema.GroupKind{Group: "", Kind: kind}
|
||||||
|
}
|
||||||
|
|
||||||
func TestErrorNew(t *testing.T) {
|
func TestErrorNew(t *testing.T) {
|
||||||
err := NewAlreadyExists(api.Resource("tests"), "1")
|
err := NewAlreadyExists(resource("tests"), "1")
|
||||||
if !IsAlreadyExists(err) {
|
if !IsAlreadyExists(err) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonAlreadyExists)
|
t.Errorf("expected to be %s", metav1.StatusReasonAlreadyExists)
|
||||||
}
|
}
|
||||||
@ -56,34 +62,34 @@ func TestErrorNew(t *testing.T) {
|
|||||||
t.Errorf("expected to not be %s", metav1.StatusReasonMethodNotAllowed)
|
t.Errorf("expected to not be %s", metav1.StatusReasonMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsConflict(NewConflict(api.Resource("tests"), "2", errors.New("message"))) {
|
if !IsConflict(NewConflict(resource("tests"), "2", errors.New("message"))) {
|
||||||
t.Errorf("expected to be conflict")
|
t.Errorf("expected to be conflict")
|
||||||
}
|
}
|
||||||
if !IsNotFound(NewNotFound(api.Resource("tests"), "3")) {
|
if !IsNotFound(NewNotFound(resource("tests"), "3")) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonNotFound)
|
t.Errorf("expected to be %s", metav1.StatusReasonNotFound)
|
||||||
}
|
}
|
||||||
if !IsInvalid(NewInvalid(api.Kind("Test"), "2", nil)) {
|
if !IsInvalid(NewInvalid(kind("Test"), "2", nil)) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonInvalid)
|
t.Errorf("expected to be %s", metav1.StatusReasonInvalid)
|
||||||
}
|
}
|
||||||
if !IsBadRequest(NewBadRequest("reason")) {
|
if !IsBadRequest(NewBadRequest("reason")) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonBadRequest)
|
t.Errorf("expected to be %s", metav1.StatusReasonBadRequest)
|
||||||
}
|
}
|
||||||
if !IsForbidden(NewForbidden(api.Resource("tests"), "2", errors.New("reason"))) {
|
if !IsForbidden(NewForbidden(resource("tests"), "2", errors.New("reason"))) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonForbidden)
|
t.Errorf("expected to be %s", metav1.StatusReasonForbidden)
|
||||||
}
|
}
|
||||||
if !IsUnauthorized(NewUnauthorized("reason")) {
|
if !IsUnauthorized(NewUnauthorized("reason")) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonUnauthorized)
|
t.Errorf("expected to be %s", metav1.StatusReasonUnauthorized)
|
||||||
}
|
}
|
||||||
if !IsServerTimeout(NewServerTimeout(api.Resource("tests"), "reason", 0)) {
|
if !IsServerTimeout(NewServerTimeout(resource("tests"), "reason", 0)) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonServerTimeout)
|
t.Errorf("expected to be %s", metav1.StatusReasonServerTimeout)
|
||||||
}
|
}
|
||||||
if time, ok := SuggestsClientDelay(NewServerTimeout(api.Resource("tests"), "doing something", 10)); time != 10 || !ok {
|
if time, ok := SuggestsClientDelay(NewServerTimeout(resource("tests"), "doing something", 10)); time != 10 || !ok {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonServerTimeout)
|
t.Errorf("expected to be %s", metav1.StatusReasonServerTimeout)
|
||||||
}
|
}
|
||||||
if time, ok := SuggestsClientDelay(NewTimeoutError("test reason", 10)); time != 10 || !ok {
|
if time, ok := SuggestsClientDelay(NewTimeoutError("test reason", 10)); time != 10 || !ok {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonTimeout)
|
t.Errorf("expected to be %s", metav1.StatusReasonTimeout)
|
||||||
}
|
}
|
||||||
if !IsMethodNotSupported(NewMethodNotSupported(api.Resource("foos"), "delete")) {
|
if !IsMethodNotSupported(NewMethodNotSupported(resource("foos"), "delete")) {
|
||||||
t.Errorf("expected to be %s", metav1.StatusReasonMethodNotAllowed)
|
t.Errorf("expected to be %s", metav1.StatusReasonMethodNotAllowed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +158,7 @@ func TestNewInvalid(t *testing.T) {
|
|||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
vErr, expected := testCase.Err, testCase.Details
|
vErr, expected := testCase.Err, testCase.Details
|
||||||
expected.Causes[0].Message = vErr.ErrorBody()
|
expected.Causes[0].Message = vErr.ErrorBody()
|
||||||
err := NewInvalid(api.Kind("Kind"), "name", field.ErrorList{vErr})
|
err := NewInvalid(kind("Kind"), "name", field.ErrorList{vErr})
|
||||||
status := err.ErrStatus
|
status := err.ErrStatus
|
||||||
if status.Code != 422 || status.Reason != metav1.StatusReasonInvalid {
|
if status.Code != 422 || status.Reason != metav1.StatusReasonInvalid {
|
||||||
t.Errorf("%d: unexpected status: %#v", i, status)
|
t.Errorf("%d: unexpected status: %#v", i, status)
|
Loading…
Reference in New Issue
Block a user