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
0127c453
Commit
0127c453
authored
Dec 10, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18163 from timothysc/storage_error_handling
Auto commit by PR queue bot
parents
8847c6db
a4282469
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
23 deletions
+70
-23
.gitignore
.gitignore
+3
-0
etcd.go
pkg/api/errors/etcd/etcd.go
+16
-16
errors.go
pkg/apiserver/errors.go
+2
-2
master.go
pkg/master/master.go
+1
-0
master_test.go
pkg/master/master_test.go
+2
-3
etcd.go
pkg/registry/service/allocator/etcd/etcd.go
+1
-2
errors.go
pkg/storage/errors.go
+45
-0
No files found.
.gitignore
View file @
0127c453
...
...
@@ -13,6 +13,9 @@
.idea/
*.iml
# Vscode files
.vscode/**
# This is where the result of the go build goes
/output/**
/output
...
...
pkg/api/errors/etcd/etcd.go
View file @
0127c453
...
...
@@ -18,68 +18,68 @@ package etcd
import
(
"k8s.io/kubernetes/pkg/api/errors"
etcdutil
"k8s.io/kubernetes/pkg/storage/etcd/util
"
"k8s.io/kubernetes/pkg/storage
"
)
// InterpretListError converts a generic e
tcd e
rror on a retrieval
// InterpretListError converts a generic error on a retrieval
// operation into the appropriate API error.
func
InterpretListError
(
err
error
,
kind
string
)
error
{
switch
{
case
etcdutil
.
IsEtcd
NotFound
(
err
)
:
case
storage
.
Is
NotFound
(
err
)
:
return
errors
.
NewNotFound
(
kind
,
""
)
case
etcdutil
.
IsEtcd
Unreachable
(
err
)
:
case
storage
.
Is
Unreachable
(
err
)
:
return
errors
.
NewServerTimeout
(
kind
,
"list"
,
2
)
// TODO: make configurable or handled at a higher level
default
:
return
err
}
}
// InterpretGetError converts a generic e
tcd e
rror on a retrieval
// InterpretGetError converts a generic error on a retrieval
// operation into the appropriate API error.
func
InterpretGetError
(
err
error
,
kind
,
name
string
)
error
{
switch
{
case
etcdutil
.
IsEtcd
NotFound
(
err
)
:
case
storage
.
Is
NotFound
(
err
)
:
return
errors
.
NewNotFound
(
kind
,
name
)
case
etcdutil
.
IsEtcd
Unreachable
(
err
)
:
case
storage
.
Is
Unreachable
(
err
)
:
return
errors
.
NewServerTimeout
(
kind
,
"get"
,
2
)
// TODO: make configurable or handled at a higher level
default
:
return
err
}
}
// InterpretCreateError converts a generic e
tcd e
rror on a create
// InterpretCreateError converts a generic error on a create
// operation into the appropriate API error.
func
InterpretCreateError
(
err
error
,
kind
,
name
string
)
error
{
switch
{
case
etcdutil
.
IsEtcd
NodeExist
(
err
)
:
case
storage
.
Is
NodeExist
(
err
)
:
return
errors
.
NewAlreadyExists
(
kind
,
name
)
case
etcdutil
.
IsEtcd
Unreachable
(
err
)
:
case
storage
.
Is
Unreachable
(
err
)
:
return
errors
.
NewServerTimeout
(
kind
,
"create"
,
2
)
// TODO: make configurable or handled at a higher level
default
:
return
err
}
}
// InterpretUpdateError converts a generic e
tcd e
rror on a update
// InterpretUpdateError converts a generic error on a update
// operation into the appropriate API error.
func
InterpretUpdateError
(
err
error
,
kind
,
name
string
)
error
{
switch
{
case
etcdutil
.
IsEtcdTestFailed
(
err
),
etcdutil
.
IsEtcd
NodeExist
(
err
)
:
case
storage
.
IsTestFailed
(
err
),
storage
.
Is
NodeExist
(
err
)
:
return
errors
.
NewConflict
(
kind
,
name
,
err
)
case
etcdutil
.
IsEtcd
Unreachable
(
err
)
:
case
storage
.
Is
Unreachable
(
err
)
:
return
errors
.
NewServerTimeout
(
kind
,
"update"
,
2
)
// TODO: make configurable or handled at a higher level
default
:
return
err
}
}
// InterpretDeleteError converts a generic e
tcd e
rror on a delete
// InterpretDeleteError converts a generic error on a delete
// operation into the appropriate API error.
func
InterpretDeleteError
(
err
error
,
kind
,
name
string
)
error
{
switch
{
case
etcdutil
.
IsEtcd
NotFound
(
err
)
:
case
storage
.
Is
NotFound
(
err
)
:
return
errors
.
NewNotFound
(
kind
,
name
)
case
etcdutil
.
IsEtcd
Unreachable
(
err
)
:
case
storage
.
Is
Unreachable
(
err
)
:
return
errors
.
NewServerTimeout
(
kind
,
"delete"
,
2
)
// TODO: make configurable or handled at a higher level
default
:
return
err
...
...
pkg/apiserver/errors.go
View file @
0127c453
...
...
@@ -21,7 +21,7 @@ import (
"net/http"
"k8s.io/kubernetes/pkg/api/unversioned"
etcdutil
"k8s.io/kubernetes/pkg/storage/etcd/util
"
"k8s.io/kubernetes/pkg/storage
"
"k8s.io/kubernetes/pkg/util"
)
...
...
@@ -52,7 +52,7 @@ func errToAPIStatus(err error) *unversioned.Status {
status
:=
http
.
StatusInternalServerError
switch
{
//TODO: replace me with NewConflictErr
case
etcdutil
.
IsEtcd
TestFailed
(
err
)
:
case
storage
.
Is
TestFailed
(
err
)
:
status
=
http
.
StatusConflict
}
// Log errors that were not converted to an error status
...
...
pkg/master/master.go
View file @
0127c453
...
...
@@ -836,6 +836,7 @@ func (m *Master) getServersToValidate(c *Config) map[string]apiserver.Server {
addr
=
etcdUrl
.
Host
port
=
4001
}
// TODO: etcd health checking should be abstracted in the storage tier
serversToValidate
[
fmt
.
Sprintf
(
"etcd-%d"
,
ix
)]
=
apiserver
.
Server
{
Addr
:
addr
,
Port
:
port
,
Path
:
"/health"
,
Validate
:
etcdutil
.
EtcdHealthCheck
}
}
return
serversToValidate
...
...
pkg/master/master_test.go
View file @
0127c453
...
...
@@ -47,7 +47,6 @@ import (
etcdstorage
"k8s.io/kubernetes/pkg/storage/etcd"
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
etcdtesting
"k8s.io/kubernetes/pkg/storage/etcd/testing"
etcdutil
"k8s.io/kubernetes/pkg/storage/etcd/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
...
...
@@ -789,7 +788,7 @@ func testInstallThirdPartyAPIDeleteVersion(t *testing.T, version string) {
thirdPartyObj
:=
extensions
.
ThirdPartyResourceData
{}
err
=
master
.
thirdPartyStorage
.
Get
(
context
.
TODO
(),
expectedDeletedKey
,
&
thirdPartyObj
,
false
)
if
!
etcdutil
.
IsEtcd
NotFound
(
err
)
{
if
!
storage
.
Is
NotFound
(
err
)
{
t
.
Errorf
(
"expected deletion didn't happen: %v"
,
err
)
}
}
...
...
@@ -876,7 +875,7 @@ func testInstallThirdPartyResourceRemove(t *testing.T, version string) {
for
_
,
key
:=
range
expectedDeletedKeys
{
thirdPartyObj
:=
extensions
.
ThirdPartyResourceData
{}
err
:=
master
.
thirdPartyStorage
.
Get
(
context
.
TODO
(),
key
,
&
thirdPartyObj
,
false
)
if
!
etcdutil
.
IsEtcd
NotFound
(
err
)
{
if
!
storage
.
Is
NotFound
(
err
)
{
t
.
Errorf
(
"expected deletion didn't happen: %v"
,
err
)
}
}
...
...
pkg/registry/service/allocator/etcd/etcd.go
View file @
0127c453
...
...
@@ -28,7 +28,6 @@ import (
"k8s.io/kubernetes/pkg/registry/service/allocator"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
etcdutil
"k8s.io/kubernetes/pkg/storage/etcd/util"
"golang.org/x/net/context"
)
...
...
@@ -174,7 +173,7 @@ func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
existing
:=
&
api
.
RangeAllocation
{}
if
err
:=
e
.
storage
.
Get
(
context
.
TODO
(),
e
.
baseKey
,
existing
,
false
);
err
!=
nil
{
if
etcdutil
.
IsEtcd
NotFound
(
err
)
{
if
storage
.
Is
NotFound
(
err
)
{
return
nil
,
nil
}
return
nil
,
etcderr
.
InterpretGetError
(
err
,
e
.
kind
,
""
)
...
...
pkg/storage/errors.go
0 → 100644
View file @
0127c453
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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
storage
import
(
etcdutil
"k8s.io/kubernetes/pkg/storage/etcd/util"
)
// IsNotFound returns true if and only if err is "key" not found error.
func
IsNotFound
(
err
error
)
bool
{
// TODO: add alternate storage error here
return
etcdutil
.
IsEtcdNotFound
(
err
)
}
// IsNodeExist returns true if and only if err is an node already exist error.
func
IsNodeExist
(
err
error
)
bool
{
// TODO: add alternate storage error here
return
etcdutil
.
IsEtcdNodeExist
(
err
)
}
// IsUnreachable returns true if and only if err indicates the server could not be reached.
func
IsUnreachable
(
err
error
)
bool
{
// TODO: add alternate storage error here
return
etcdutil
.
IsEtcdUnreachable
(
err
)
}
// IsTestFailed returns true if and only if err is a write conflict.
func
IsTestFailed
(
err
error
)
bool
{
// TODO: add alternate storage error here
return
etcdutil
.
IsEtcdTestFailed
(
err
)
}
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