Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e5fbf861
Unverified
Commit
e5fbf861
authored
May 14, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow StatusErrors to be modified after creation
parent
f204a9f3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
21 deletions
+21
-21
errors.go
pkg/api/errors/errors.go
+15
-15
errors_test.go
pkg/api/errors/errors_test.go
+1
-1
testclient_test.go
pkg/client/unversioned/testclient/testclient_test.go
+2
-2
delete_test.go
pkg/kubectl/cmd/delete_test.go
+2
-2
cacher_test.go
pkg/storage/cacher_test.go
+1
-1
No files found.
pkg/api/errors/errors.go
View file @
e5fbf861
...
@@ -93,7 +93,7 @@ func FromObject(obj runtime.Object) error {
...
@@ -93,7 +93,7 @@ func FromObject(obj runtime.Object) error {
}
}
// NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.
// NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.
func
NewNotFound
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
)
e
rror
{
func
NewNotFound
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusNotFound
,
Code
:
http
.
StatusNotFound
,
...
@@ -108,7 +108,7 @@ func NewNotFound(qualifiedResource unversioned.GroupResource, name string) error
...
@@ -108,7 +108,7 @@ func NewNotFound(qualifiedResource unversioned.GroupResource, name string) error
}
}
// NewAlreadyExists returns an error indicating the item requested exists by that identifier.
// NewAlreadyExists returns an error indicating the item requested exists by that identifier.
func
NewAlreadyExists
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
)
e
rror
{
func
NewAlreadyExists
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusConflict
,
Code
:
http
.
StatusConflict
,
...
@@ -124,7 +124,7 @@ func NewAlreadyExists(qualifiedResource unversioned.GroupResource, name string)
...
@@ -124,7 +124,7 @@ func NewAlreadyExists(qualifiedResource unversioned.GroupResource, name string)
// NewUnauthorized returns an error indicating the client is not authorized to perform the requested
// NewUnauthorized returns an error indicating the client is not authorized to perform the requested
// action.
// action.
func
NewUnauthorized
(
reason
string
)
e
rror
{
func
NewUnauthorized
(
reason
string
)
*
StatusE
rror
{
message
:=
reason
message
:=
reason
if
len
(
message
)
==
0
{
if
len
(
message
)
==
0
{
message
=
"not authorized"
message
=
"not authorized"
...
@@ -138,7 +138,7 @@ func NewUnauthorized(reason string) error {
...
@@ -138,7 +138,7 @@ func NewUnauthorized(reason string) error {
}
}
// NewForbidden returns an error indicating the requested action was forbidden
// NewForbidden returns an error indicating the requested action was forbidden
func
NewForbidden
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
,
err
error
)
e
rror
{
func
NewForbidden
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
,
err
error
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusForbidden
,
Code
:
http
.
StatusForbidden
,
...
@@ -153,7 +153,7 @@ func NewForbidden(qualifiedResource unversioned.GroupResource, name string, err
...
@@ -153,7 +153,7 @@ func NewForbidden(qualifiedResource unversioned.GroupResource, name string, err
}
}
// NewConflict returns an error indicating the item can't be updated as provided.
// NewConflict returns an error indicating the item can't be updated as provided.
func
NewConflict
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
,
err
error
)
e
rror
{
func
NewConflict
(
qualifiedResource
unversioned
.
GroupResource
,
name
string
,
err
error
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusConflict
,
Code
:
http
.
StatusConflict
,
...
@@ -168,7 +168,7 @@ func NewConflict(qualifiedResource unversioned.GroupResource, name string, err e
...
@@ -168,7 +168,7 @@ func NewConflict(qualifiedResource unversioned.GroupResource, name string, err e
}
}
// NewGone returns an error indicating the item no longer available at the server and no forwarding address is known.
// NewGone returns an error indicating the item no longer available at the server and no forwarding address is known.
func
NewGone
(
message
string
)
e
rror
{
func
NewGone
(
message
string
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusGone
,
Code
:
http
.
StatusGone
,
...
@@ -178,7 +178,7 @@ func NewGone(message string) error {
...
@@ -178,7 +178,7 @@ func NewGone(message string) error {
}
}
// NewInvalid returns an error indicating the item is invalid and cannot be processed.
// NewInvalid returns an error indicating the item is invalid and cannot be processed.
func
NewInvalid
(
qualifiedKind
unversioned
.
GroupKind
,
name
string
,
errs
field
.
ErrorList
)
e
rror
{
func
NewInvalid
(
qualifiedKind
unversioned
.
GroupKind
,
name
string
,
errs
field
.
ErrorList
)
*
StatusE
rror
{
causes
:=
make
([]
unversioned
.
StatusCause
,
0
,
len
(
errs
))
causes
:=
make
([]
unversioned
.
StatusCause
,
0
,
len
(
errs
))
for
i
:=
range
errs
{
for
i
:=
range
errs
{
err
:=
errs
[
i
]
err
:=
errs
[
i
]
...
@@ -203,7 +203,7 @@ func NewInvalid(qualifiedKind unversioned.GroupKind, name string, errs field.Err
...
@@ -203,7 +203,7 @@ func NewInvalid(qualifiedKind unversioned.GroupKind, name string, errs field.Err
}
}
// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
func
NewBadRequest
(
reason
string
)
e
rror
{
func
NewBadRequest
(
reason
string
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusBadRequest
,
Code
:
http
.
StatusBadRequest
,
...
@@ -213,7 +213,7 @@ func NewBadRequest(reason string) error {
...
@@ -213,7 +213,7 @@ func NewBadRequest(reason string) error {
}
}
// NewServiceUnavailable creates an error that indicates that the requested service is unavailable.
// NewServiceUnavailable creates an error that indicates that the requested service is unavailable.
func
NewServiceUnavailable
(
reason
string
)
e
rror
{
func
NewServiceUnavailable
(
reason
string
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusServiceUnavailable
,
Code
:
http
.
StatusServiceUnavailable
,
...
@@ -223,7 +223,7 @@ func NewServiceUnavailable(reason string) error {
...
@@ -223,7 +223,7 @@ func NewServiceUnavailable(reason string) error {
}
}
// NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
// NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
func
NewMethodNotSupported
(
qualifiedResource
unversioned
.
GroupResource
,
action
string
)
e
rror
{
func
NewMethodNotSupported
(
qualifiedResource
unversioned
.
GroupResource
,
action
string
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusMethodNotAllowed
,
Code
:
http
.
StatusMethodNotAllowed
,
...
@@ -238,7 +238,7 @@ func NewMethodNotSupported(qualifiedResource unversioned.GroupResource, action s
...
@@ -238,7 +238,7 @@ func NewMethodNotSupported(qualifiedResource unversioned.GroupResource, action s
// NewServerTimeout returns an error indicating the requested action could not be completed due to a
// NewServerTimeout returns an error indicating the requested action could not be completed due to a
// transient error, and the client should try again.
// transient error, and the client should try again.
func
NewServerTimeout
(
qualifiedResource
unversioned
.
GroupResource
,
operation
string
,
retryAfterSeconds
int
)
e
rror
{
func
NewServerTimeout
(
qualifiedResource
unversioned
.
GroupResource
,
operation
string
,
retryAfterSeconds
int
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusInternalServerError
,
Code
:
http
.
StatusInternalServerError
,
...
@@ -255,12 +255,12 @@ func NewServerTimeout(qualifiedResource unversioned.GroupResource, operation str
...
@@ -255,12 +255,12 @@ func NewServerTimeout(qualifiedResource unversioned.GroupResource, operation str
// NewServerTimeoutForKind should not exist. Server timeouts happen when accessing resources, the Kind is just what we
// NewServerTimeoutForKind should not exist. Server timeouts happen when accessing resources, the Kind is just what we
// happened to be looking at when the request failed. This delegates to keep code sane, but we should work towards removing this.
// happened to be looking at when the request failed. This delegates to keep code sane, but we should work towards removing this.
func
NewServerTimeoutForKind
(
qualifiedKind
unversioned
.
GroupKind
,
operation
string
,
retryAfterSeconds
int
)
e
rror
{
func
NewServerTimeoutForKind
(
qualifiedKind
unversioned
.
GroupKind
,
operation
string
,
retryAfterSeconds
int
)
*
StatusE
rror
{
return
NewServerTimeout
(
unversioned
.
GroupResource
{
Group
:
qualifiedKind
.
Group
,
Resource
:
qualifiedKind
.
Kind
},
operation
,
retryAfterSeconds
)
return
NewServerTimeout
(
unversioned
.
GroupResource
{
Group
:
qualifiedKind
.
Group
,
Resource
:
qualifiedKind
.
Kind
},
operation
,
retryAfterSeconds
)
}
}
// NewInternalError returns an error indicating the item is invalid and cannot be processed.
// NewInternalError returns an error indicating the item is invalid and cannot be processed.
func
NewInternalError
(
err
error
)
e
rror
{
func
NewInternalError
(
err
error
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
http
.
StatusInternalServerError
,
Code
:
http
.
StatusInternalServerError
,
...
@@ -274,7 +274,7 @@ func NewInternalError(err error) error {
...
@@ -274,7 +274,7 @@ func NewInternalError(err error) error {
// NewTimeoutError returns an error indicating that a timeout occurred before the request
// NewTimeoutError returns an error indicating that a timeout occurred before the request
// could be completed. Clients may retry, but the operation may still complete.
// could be completed. Clients may retry, but the operation may still complete.
func
NewTimeoutError
(
message
string
,
retryAfterSeconds
int
)
e
rror
{
func
NewTimeoutError
(
message
string
,
retryAfterSeconds
int
)
*
StatusE
rror
{
return
&
StatusError
{
unversioned
.
Status
{
return
&
StatusError
{
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Code
:
StatusServerTimeout
,
Code
:
StatusServerTimeout
,
...
@@ -287,7 +287,7 @@ func NewTimeoutError(message string, retryAfterSeconds int) error {
...
@@ -287,7 +287,7 @@ func NewTimeoutError(message string, retryAfterSeconds int) error {
}
}
// NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.
// NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.
func
NewGenericServerResponse
(
code
int
,
verb
string
,
qualifiedResource
unversioned
.
GroupResource
,
name
,
serverMessage
string
,
retryAfterSeconds
int
,
isUnexpectedResponse
bool
)
e
rror
{
func
NewGenericServerResponse
(
code
int
,
verb
string
,
qualifiedResource
unversioned
.
GroupResource
,
name
,
serverMessage
string
,
retryAfterSeconds
int
,
isUnexpectedResponse
bool
)
*
StatusE
rror
{
reason
:=
unversioned
.
StatusReasonUnknown
reason
:=
unversioned
.
StatusReasonUnknown
message
:=
fmt
.
Sprintf
(
"the server responded with the status code %d but did not return more information"
,
code
)
message
:=
fmt
.
Sprintf
(
"the server responded with the status code %d but did not return more information"
,
code
)
switch
code
{
switch
code
{
...
...
pkg/api/errors/errors_test.go
View file @
e5fbf861
...
@@ -152,7 +152,7 @@ func TestNewInvalid(t *testing.T) {
...
@@ -152,7 +152,7 @@ func TestNewInvalid(t *testing.T) {
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
(
api
.
Kind
(
"Kind"
),
"name"
,
field
.
ErrorList
{
vErr
})
status
:=
err
.
(
*
StatusError
)
.
ErrStatus
status
:=
err
.
ErrStatus
if
status
.
Code
!=
422
||
status
.
Reason
!=
unversioned
.
StatusReasonInvalid
{
if
status
.
Code
!=
422
||
status
.
Reason
!=
unversioned
.
StatusReasonInvalid
{
t
.
Errorf
(
"%d: unexpected status: %#v"
,
i
,
status
)
t
.
Errorf
(
"%d: unexpected status: %#v"
,
i
,
status
)
}
}
...
...
pkg/client/unversioned/testclient/testclient_test.go
View file @
e5fbf861
...
@@ -56,9 +56,9 @@ func TestErrors(t *testing.T) {
...
@@ -56,9 +56,9 @@ func TestErrors(t *testing.T) {
o
.
Add
(
&
api
.
List
{
o
.
Add
(
&
api
.
List
{
Items
:
[]
runtime
.
Object
{
Items
:
[]
runtime
.
Object
{
// This first call to List will return this error
// This first call to List will return this error
&
(
errors
.
NewNotFound
(
api
.
Resource
(
"ServiceList"
),
""
)
.
(
*
errors
.
StatusError
)
.
ErrStatus
),
&
(
errors
.
NewNotFound
(
api
.
Resource
(
"ServiceList"
),
""
)
.
ErrStatus
),
// The second call to List will return this error
// The second call to List will return this error
&
(
errors
.
NewForbidden
(
api
.
Resource
(
"ServiceList"
),
""
,
nil
)
.
(
*
errors
.
StatusError
)
.
ErrStatus
),
&
(
errors
.
NewForbidden
(
api
.
Resource
(
"ServiceList"
),
""
,
nil
)
.
ErrStatus
),
},
},
})
})
client
:=
&
Fake
{}
client
:=
&
Fake
{}
...
...
pkg/kubectl/cmd/delete_test.go
View file @
e5fbf861
...
@@ -192,7 +192,7 @@ func TestDeleteAllNotFound(t *testing.T) {
...
@@ -192,7 +192,7 @@ func TestDeleteAllNotFound(t *testing.T) {
// Add an item to the list which will result in a 404 on delete
// Add an item to the list which will result in a 404 on delete
svc
.
Items
=
append
(
svc
.
Items
,
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
svc
.
Items
=
append
(
svc
.
Items
,
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
notFoundError
:=
&
errors
.
NewNotFound
(
api
.
Resource
(
"services"
),
"foo"
)
.
(
*
errors
.
StatusError
)
.
ErrStatus
notFoundError
:=
&
errors
.
NewNotFound
(
api
.
Resource
(
"services"
),
"foo"
)
.
ErrStatus
tf
.
Printer
=
&
testPrinter
{}
tf
.
Printer
=
&
testPrinter
{}
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
...
@@ -234,7 +234,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
...
@@ -234,7 +234,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
// Add an item to the list which will result in a 404 on delete
// Add an item to the list which will result in a 404 on delete
svc
.
Items
=
append
(
svc
.
Items
,
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
svc
.
Items
=
append
(
svc
.
Items
,
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
notFoundError
:=
&
errors
.
NewNotFound
(
api
.
Resource
(
"services"
),
"foo"
)
.
(
*
errors
.
StatusError
)
.
ErrStatus
notFoundError
:=
&
errors
.
NewNotFound
(
api
.
Resource
(
"services"
),
"foo"
)
.
ErrStatus
tf
.
Printer
=
&
testPrinter
{}
tf
.
Printer
=
&
testPrinter
{}
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
...
...
pkg/storage/cacher_test.go
View file @
e5fbf861
...
@@ -239,7 +239,7 @@ func TestWatch(t *testing.T) {
...
@@ -239,7 +239,7 @@ func TestWatch(t *testing.T) {
}
}
defer
tooOldWatcher
.
Stop
()
defer
tooOldWatcher
.
Stop
()
// Ensure we get a "Gone" error
// Ensure we get a "Gone" error
expectedGoneError
:=
errors
.
NewGone
(
""
)
.
(
*
errors
.
StatusError
)
.
ErrStatus
expectedGoneError
:=
errors
.
NewGone
(
""
)
.
ErrStatus
verifyWatchEvent
(
t
,
tooOldWatcher
,
watch
.
Error
,
&
expectedGoneError
)
verifyWatchEvent
(
t
,
tooOldWatcher
,
watch
.
Error
,
&
expectedGoneError
)
initialWatcher
,
err
:=
cacher
.
Watch
(
context
.
TODO
(),
"pods/ns/foo"
,
fooCreated
.
ResourceVersion
,
storage
.
Everything
)
initialWatcher
,
err
:=
cacher
.
Watch
(
context
.
TODO
(),
"pods/ns/foo"
,
fooCreated
.
ResourceVersion
,
storage
.
Everything
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment