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
9db58ff2
Commit
9db58ff2
authored
Jul 01, 2015
by
Zach Loafman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10632 from nikhiljindal/revert-etcderrors
Revert "Merge pull request #10246 from nikhiljindal"
parents
4f9cfc84
d82d5d11
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
22 additions
and
59 deletions
+22
-59
errors.go
pkg/api/errors/errors.go
+0
-13
etcd.go
pkg/api/errors/etcd/etcd.go
+4
-12
etcd.go
pkg/registry/etcd/etcd.go
+5
-11
etcd.go
pkg/registry/generic/etcd/etcd.go
+2
-6
etcd.go
pkg/registry/pod/etcd/etcd.go
+6
-6
etcd_test.go
pkg/registry/pod/etcd/etcd_test.go
+1
-1
etcd_test.go
pkg/registry/resourcequota/etcd/etcd_test.go
+1
-1
etcd.go
pkg/registry/service/allocator/etcd/etcd.go
+3
-9
No files found.
pkg/api/errors/errors.go
View file @
9db58ff2
...
@@ -372,11 +372,6 @@ func IsServerTimeout(err error) bool {
...
@@ -372,11 +372,6 @@ func IsServerTimeout(err error) bool {
return
reasonForError
(
err
)
==
api
.
StatusReasonServerTimeout
return
reasonForError
(
err
)
==
api
.
StatusReasonServerTimeout
}
}
// IsInternalServerError determines if err is an error which indicates that there was an internal server error.
func
IsInternalServerError
(
err
error
)
bool
{
return
reasonForError
(
err
)
==
api
.
StatusReasonInternalError
}
// IsUnexpectedServerError returns true if the server response was not in the expected API format,
// IsUnexpectedServerError returns true if the server response was not in the expected API format,
// and may be the result of another HTTP actor.
// and may be the result of another HTTP actor.
func
IsUnexpectedServerError
(
err
error
)
bool
{
func
IsUnexpectedServerError
(
err
error
)
bool
{
...
@@ -414,14 +409,6 @@ func SuggestsClientDelay(err error) (int, bool) {
...
@@ -414,14 +409,6 @@ func SuggestsClientDelay(err error) (int, bool) {
return
0
,
false
return
0
,
false
}
}
func
IsAPIStatusError
(
err
error
)
bool
{
switch
err
.
(
type
)
{
case
*
StatusError
:
return
true
}
return
false
}
func
reasonForError
(
err
error
)
api
.
StatusReason
{
func
reasonForError
(
err
error
)
api
.
StatusReason
{
switch
t
:=
err
.
(
type
)
{
switch
t
:=
err
.
(
type
)
{
case
*
StatusError
:
case
*
StatusError
:
...
...
pkg/api/errors/etcd/etcd.go
View file @
9db58ff2
...
@@ -27,10 +27,8 @@ func InterpretGetError(err error, kind, name string) error {
...
@@ -27,10 +27,8 @@ func InterpretGetError(err error, kind, name string) error {
switch
{
switch
{
case
tools
.
IsEtcdNotFound
(
err
)
:
case
tools
.
IsEtcdNotFound
(
err
)
:
return
errors
.
NewNotFound
(
kind
,
name
)
return
errors
.
NewNotFound
(
kind
,
name
)
case
errors
.
IsAPIStatusError
(
err
)
:
return
err
default
:
default
:
return
err
ors
.
NewInternalError
(
err
)
return
err
}
}
}
}
...
@@ -40,10 +38,8 @@ func InterpretCreateError(err error, kind, name string) error {
...
@@ -40,10 +38,8 @@ func InterpretCreateError(err error, kind, name string) error {
switch
{
switch
{
case
tools
.
IsEtcdNodeExist
(
err
)
:
case
tools
.
IsEtcdNodeExist
(
err
)
:
return
errors
.
NewAlreadyExists
(
kind
,
name
)
return
errors
.
NewAlreadyExists
(
kind
,
name
)
case
errors
.
IsAPIStatusError
(
err
)
:
return
err
default
:
default
:
return
err
ors
.
NewInternalError
(
err
)
return
err
}
}
}
}
...
@@ -53,10 +49,8 @@ func InterpretUpdateError(err error, kind, name string) error {
...
@@ -53,10 +49,8 @@ func InterpretUpdateError(err error, kind, name string) error {
switch
{
switch
{
case
tools
.
IsEtcdTestFailed
(
err
),
tools
.
IsEtcdNodeExist
(
err
)
:
case
tools
.
IsEtcdTestFailed
(
err
),
tools
.
IsEtcdNodeExist
(
err
)
:
return
errors
.
NewConflict
(
kind
,
name
,
err
)
return
errors
.
NewConflict
(
kind
,
name
,
err
)
case
errors
.
IsAPIStatusError
(
err
)
:
return
err
default
:
default
:
return
err
ors
.
NewInternalError
(
err
)
return
err
}
}
}
}
...
@@ -66,9 +60,7 @@ func InterpretDeleteError(err error, kind, name string) error {
...
@@ -66,9 +60,7 @@ func InterpretDeleteError(err error, kind, name string) error {
switch
{
switch
{
case
tools
.
IsEtcdNotFound
(
err
)
:
case
tools
.
IsEtcdNotFound
(
err
)
:
return
errors
.
NewNotFound
(
kind
,
name
)
return
errors
.
NewNotFound
(
kind
,
name
)
case
errors
.
IsAPIStatusError
(
err
)
:
return
err
default
:
default
:
return
err
ors
.
NewInternalError
(
err
)
return
err
}
}
}
}
pkg/registry/etcd/etcd.go
View file @
9db58ff2
...
@@ -108,10 +108,7 @@ func (r *Registry) CreateService(ctx api.Context, svc *api.Service) (*api.Servic
...
@@ -108,10 +108,7 @@ func (r *Registry) CreateService(ctx api.Context, svc *api.Service) (*api.Servic
}
}
out
:=
&
api
.
Service
{}
out
:=
&
api
.
Service
{}
err
=
r
.
CreateObj
(
key
,
svc
,
out
,
0
)
err
=
r
.
CreateObj
(
key
,
svc
,
out
,
0
)
if
err
!=
nil
{
return
out
,
etcderr
.
InterpretCreateError
(
err
,
"service"
,
svc
.
Name
)
err
=
etcderr
.
InterpretCreateError
(
err
,
"Service"
,
svc
.
Name
)
}
return
out
,
err
}
}
// GetService obtains a Service specified by its name.
// GetService obtains a Service specified by its name.
...
@@ -123,7 +120,7 @@ func (r *Registry) GetService(ctx api.Context, name string) (*api.Service, error
...
@@ -123,7 +120,7 @@ func (r *Registry) GetService(ctx api.Context, name string) (*api.Service, error
var
svc
api
.
Service
var
svc
api
.
Service
err
=
r
.
ExtractObj
(
key
,
&
svc
,
false
)
err
=
r
.
ExtractObj
(
key
,
&
svc
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
etcderr
.
InterpretGetError
(
err
,
"
S
ervice"
,
name
)
return
nil
,
etcderr
.
InterpretGetError
(
err
,
"
s
ervice"
,
name
)
}
}
return
&
svc
,
nil
return
&
svc
,
nil
}
}
...
@@ -136,7 +133,7 @@ func (r *Registry) DeleteService(ctx api.Context, name string) error {
...
@@ -136,7 +133,7 @@ func (r *Registry) DeleteService(ctx api.Context, name string) error {
}
}
err
=
r
.
Delete
(
key
,
true
)
err
=
r
.
Delete
(
key
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
etcderr
.
InterpretDeleteError
(
err
,
"
S
ervice"
,
name
)
return
etcderr
.
InterpretDeleteError
(
err
,
"
s
ervice"
,
name
)
}
}
// TODO: can leave dangling endpoints, and potentially return incorrect
// TODO: can leave dangling endpoints, and potentially return incorrect
...
@@ -156,15 +153,12 @@ func (r *Registry) UpdateService(ctx api.Context, svc *api.Service) (*api.Servic
...
@@ -156,15 +153,12 @@ func (r *Registry) UpdateService(ctx api.Context, svc *api.Service) (*api.Servic
}
}
out
:=
&
api
.
Service
{}
out
:=
&
api
.
Service
{}
err
=
r
.
SetObj
(
key
,
svc
,
out
,
0
)
err
=
r
.
SetObj
(
key
,
svc
,
out
,
0
)
if
err
!=
nil
{
return
out
,
etcderr
.
InterpretUpdateError
(
err
,
"service"
,
svc
.
Name
)
err
=
etcderr
.
InterpretUpdateError
(
err
,
"Service"
,
svc
.
Name
)
}
return
out
,
err
}
}
// WatchServices begins watching for new, changed, or deleted service configurations.
// WatchServices begins watching for new, changed, or deleted service configurations.
func
(
r
*
Registry
)
WatchServices
(
ctx
api
.
Context
,
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
func
(
r
*
Registry
)
WatchServices
(
ctx
api
.
Context
,
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
version
,
err
:=
tools
.
ParseWatchResourceVersion
(
resourceVersion
,
"
S
ervice"
)
version
,
err
:=
tools
.
ParseWatchResourceVersion
(
resourceVersion
,
"
s
ervice"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/registry/generic/etcd/etcd.go
View file @
9db58ff2
...
@@ -191,9 +191,7 @@ func (e *Etcd) CreateWithName(ctx api.Context, name string, obj runtime.Object)
...
@@ -191,9 +191,7 @@ func (e *Etcd) CreateWithName(ctx api.Context, name string, obj runtime.Object)
return
err
return
err
}
}
err
=
e
.
Helper
.
CreateObj
(
key
,
obj
,
nil
,
ttl
)
err
=
e
.
Helper
.
CreateObj
(
key
,
obj
,
nil
,
ttl
)
if
err
!=
nil
{
err
=
etcderr
.
InterpretCreateError
(
err
,
e
.
EndpointName
,
name
)
err
=
etcderr
.
InterpretCreateError
(
err
,
e
.
EndpointName
,
name
)
}
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
err
=
e
.
Decorator
(
obj
)
err
=
e
.
Decorator
(
obj
)
}
}
...
@@ -252,9 +250,7 @@ func (e *Etcd) UpdateWithName(ctx api.Context, name string, obj runtime.Object)
...
@@ -252,9 +250,7 @@ func (e *Etcd) UpdateWithName(ctx api.Context, name string, obj runtime.Object)
return
err
return
err
}
}
err
=
e
.
Helper
.
SetObj
(
key
,
obj
,
nil
,
ttl
)
err
=
e
.
Helper
.
SetObj
(
key
,
obj
,
nil
,
ttl
)
if
err
!=
nil
{
err
=
etcderr
.
InterpretUpdateError
(
err
,
e
.
EndpointName
,
name
)
err
=
etcderr
.
InterpretUpdateError
(
err
,
e
.
EndpointName
,
name
)
}
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
err
=
e
.
Decorator
(
obj
)
err
=
e
.
Decorator
(
obj
)
}
}
...
...
pkg/registry/pod/etcd/etcd.go
View file @
9db58ff2
...
@@ -145,13 +145,13 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx api.Context, podID, oldMachin
...
@@ -145,13 +145,13 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx api.Context, podID, oldMachin
err
=
r
.
store
.
Helper
.
GuaranteedUpdate
(
podKey
,
&
api
.
Pod
{},
false
,
tools
.
SimpleUpdate
(
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
err
=
r
.
store
.
Helper
.
GuaranteedUpdate
(
podKey
,
&
api
.
Pod
{},
false
,
tools
.
SimpleUpdate
(
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
pod
,
ok
:=
obj
.
(
*
api
.
Pod
)
pod
,
ok
:=
obj
.
(
*
api
.
Pod
)
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
NewInternalError
(
fmt
.
Errorf
(
"received object is not of type pod: %#v"
,
obj
)
)
return
nil
,
fmt
.
Errorf
(
"unexpected object: %#v"
,
obj
)
}
}
if
pod
.
DeletionTimestamp
!=
nil
{
if
pod
.
DeletionTimestamp
!=
nil
{
return
nil
,
errors
.
NewConflict
(
"pod"
,
podID
,
fmt
.
Errorf
(
"pod %s is being deleted, cannot be assigned to a host"
,
pod
.
Name
)
)
return
nil
,
fmt
.
Errorf
(
"pod %s is being deleted, cannot be assigned to a host"
,
pod
.
Name
)
}
}
if
pod
.
Spec
.
NodeName
!=
oldMachine
{
if
pod
.
Spec
.
NodeName
!=
oldMachine
{
return
nil
,
errors
.
NewConflict
(
"pod"
,
podID
,
fmt
.
Errorf
(
"pod %v is already assigned to node %q"
,
pod
.
Name
,
pod
.
Spec
.
NodeName
)
)
return
nil
,
fmt
.
Errorf
(
"pod %v is already assigned to node %q"
,
pod
.
Name
,
pod
.
Spec
.
NodeName
)
}
}
pod
.
Spec
.
NodeName
=
machine
pod
.
Spec
.
NodeName
=
machine
if
pod
.
Annotations
==
nil
{
if
pod
.
Annotations
==
nil
{
...
@@ -222,7 +222,7 @@ func (r *LogREST) New() runtime.Object {
...
@@ -222,7 +222,7 @@ func (r *LogREST) New() runtime.Object {
func
(
r
*
LogREST
)
Get
(
ctx
api
.
Context
,
name
string
,
opts
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
LogREST
)
Get
(
ctx
api
.
Context
,
name
string
,
opts
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
logOpts
,
ok
:=
opts
.
(
*
api
.
PodLogOptions
)
logOpts
,
ok
:=
opts
.
(
*
api
.
PodLogOptions
)
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
NewInternalError
(
fmt
.
Errorf
(
"received object is not of type PodLogOptions: %#v"
,
opts
)
)
return
nil
,
fmt
.
Errorf
(
"Invalid options object: %#v"
,
opts
)
}
}
location
,
transport
,
err
:=
pod
.
LogLocation
(
r
.
store
,
r
.
kubeletConn
,
ctx
,
name
,
logOpts
)
location
,
transport
,
err
:=
pod
.
LogLocation
(
r
.
store
,
r
.
kubeletConn
,
ctx
,
name
,
logOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -270,7 +270,7 @@ func (r *ProxyREST) NewConnectOptions() (runtime.Object, bool, string) {
...
@@ -270,7 +270,7 @@ func (r *ProxyREST) NewConnectOptions() (runtime.Object, bool, string) {
func
(
r
*
ProxyREST
)
Connect
(
ctx
api
.
Context
,
id
string
,
opts
runtime
.
Object
)
(
rest
.
ConnectHandler
,
error
)
{
func
(
r
*
ProxyREST
)
Connect
(
ctx
api
.
Context
,
id
string
,
opts
runtime
.
Object
)
(
rest
.
ConnectHandler
,
error
)
{
proxyOpts
,
ok
:=
opts
.
(
*
api
.
PodProxyOptions
)
proxyOpts
,
ok
:=
opts
.
(
*
api
.
PodProxyOptions
)
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
NewInternalError
(
fmt
.
Errorf
(
"received object is not of type PodProxyOptions: %#v"
,
opts
)
)
return
nil
,
fmt
.
Errorf
(
"Invalid options object: %#v"
,
opts
)
}
}
location
,
_
,
err
:=
pod
.
ResourceLocation
(
r
.
store
,
ctx
,
id
)
location
,
_
,
err
:=
pod
.
ResourceLocation
(
r
.
store
,
ctx
,
id
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -301,7 +301,7 @@ func (r *ExecREST) New() runtime.Object {
...
@@ -301,7 +301,7 @@ func (r *ExecREST) New() runtime.Object {
func
(
r
*
ExecREST
)
Connect
(
ctx
api
.
Context
,
name
string
,
opts
runtime
.
Object
)
(
rest
.
ConnectHandler
,
error
)
{
func
(
r
*
ExecREST
)
Connect
(
ctx
api
.
Context
,
name
string
,
opts
runtime
.
Object
)
(
rest
.
ConnectHandler
,
error
)
{
execOpts
,
ok
:=
opts
.
(
*
api
.
PodExecOptions
)
execOpts
,
ok
:=
opts
.
(
*
api
.
PodExecOptions
)
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
NewInternalError
(
fmt
.
Errorf
(
"received object is not of type PodExecOptions: %#v"
,
opts
)
)
return
nil
,
fmt
.
Errorf
(
"Invalid options object: %#v"
,
opts
)
}
}
location
,
transport
,
err
:=
pod
.
ExecLocation
(
r
.
store
,
r
.
kubeletConn
,
ctx
,
name
,
execOpts
)
location
,
transport
,
err
:=
pod
.
ExecLocation
(
r
.
store
,
r
.
kubeletConn
,
ctx
,
name
,
execOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/registry/pod/etcd/etcd_test.go
View file @
9db58ff2
...
@@ -153,7 +153,7 @@ func TestCreateRegistryError(t *testing.T) {
...
@@ -153,7 +153,7 @@ func TestCreateRegistryError(t *testing.T) {
pod
:=
validNewPod
()
pod
:=
validNewPod
()
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
pod
)
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
pod
)
if
!
errors
.
IsInternalServerError
(
err
)
{
if
err
!=
fakeEtcdClient
.
Err
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
}
}
...
...
pkg/registry/resourcequota/etcd/etcd_test.go
View file @
9db58ff2
...
@@ -116,7 +116,7 @@ func TestCreateRegistryError(t *testing.T) {
...
@@ -116,7 +116,7 @@ func TestCreateRegistryError(t *testing.T) {
resourcequota
:=
validNewResourceQuota
()
resourcequota
:=
validNewResourceQuota
()
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
resourcequota
)
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
resourcequota
)
if
!
errors
.
IsInternalServerError
(
err
)
{
if
err
!=
fakeEtcdClient
.
Err
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
}
}
...
...
pkg/registry/service/allocator/etcd/etcd.go
View file @
9db58ff2
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
etcd
package
etcd
import
(
import
(
"errors"
"fmt"
"fmt"
"sync"
"sync"
...
@@ -30,8 +31,7 @@ import (
...
@@ -30,8 +31,7 @@ import (
)
)
var
(
var
(
// Placeholder error that should not be surfaced to the user.
errorUnableToAllocate
=
errors
.
New
(
"unable to allocate"
)
errorUnableToAllocate
=
k8serr
.
NewInternalError
(
fmt
.
Errorf
(
"unable to allocate"
))
)
)
// Etcd exposes a service.Allocator that is backed by etcd.
// Etcd exposes a service.Allocator that is backed by etcd.
...
@@ -121,9 +121,6 @@ func (e *Etcd) AllocateNext() (int, bool, error) {
...
@@ -121,9 +121,6 @@ func (e *Etcd) AllocateNext() (int, bool, error) {
}
}
return
nil
return
nil
})
})
if
err
!=
nil
&&
err
.
Error
()
==
errorUnableToAllocate
.
Error
()
{
err
=
nil
}
return
offset
,
ok
,
err
return
offset
,
ok
,
err
}
}
...
@@ -164,10 +161,7 @@ func (e *Etcd) tryUpdate(fn func() error) error {
...
@@ -164,10 +161,7 @@ func (e *Etcd) tryUpdate(fn func() error) error {
return
existing
,
nil
return
existing
,
nil
}),
}),
)
)
if
err
!=
nil
{
return
etcderr
.
InterpretUpdateError
(
err
,
e
.
kind
,
""
)
err
=
etcderr
.
InterpretUpdateError
(
err
,
e
.
kind
,
""
)
}
return
err
}
}
// Refresh reloads the RangeAllocation from etcd.
// Refresh reloads the RangeAllocation from etcd.
...
...
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