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
1a908a27
Commit
1a908a27
authored
Jul 23, 2015
by
Vish Kannan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11076 from nikhiljindal/apiError
Updating apiserver to not return 500 when a service without pods is proxied
parents
0a715a72
1517b660
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
3 deletions
+36
-3
frontend-service.yaml
examples/guestbook/frontend-service.yaml
+1
-1
errors.go
pkg/api/errors/errors.go
+10
-0
types.go
pkg/api/types.go
+6
-0
rest.go
pkg/registry/service/rest.go
+2
-2
auth_test.go
test/integration/auth_test.go
+17
-0
No files found.
examples/guestbook/frontend-service.yaml
View file @
1a908a27
...
@@ -10,6 +10,6 @@ spec:
...
@@ -10,6 +10,6 @@ spec:
# type: LoadBalancer
# type: LoadBalancer
ports
:
ports
:
# the port that this service should serve on
# the port that this service should serve on
-
port
:
80
-
port
:
80
selector
:
selector
:
name
:
frontend
name
:
frontend
pkg/api/errors/errors.go
View file @
1a908a27
...
@@ -193,6 +193,16 @@ func NewBadRequest(reason string) error {
...
@@ -193,6 +193,16 @@ func NewBadRequest(reason string) error {
}}
}}
}
}
// NewServiceUnavailable creates an error that indicates that the requested service is unavailable.
func
NewServiceUnavailable
(
reason
string
)
error
{
return
&
StatusError
{
api
.
Status
{
Status
:
api
.
StatusFailure
,
Code
:
http
.
StatusServiceUnavailable
,
Reason
:
api
.
StatusReasonServiceUnavailable
,
Message
:
reason
,
}}
}
// 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
(
kind
,
action
string
)
error
{
func
NewMethodNotSupported
(
kind
,
action
string
)
error
{
return
&
StatusError
{
api
.
Status
{
return
&
StatusError
{
api
.
Status
{
...
...
pkg/api/types.go
View file @
1a908a27
...
@@ -1708,6 +1708,12 @@ const (
...
@@ -1708,6 +1708,12 @@ const (
// "causes" - The original error
// "causes" - The original error
// Status code 500
// Status code 500
StatusReasonInternalError
=
"InternalError"
StatusReasonInternalError
=
"InternalError"
// StatusReasonServiceUnavailable means that the request itself was valid,
// but the requested service is unavailable at this time.
// Retrying the request after some time might succeed.
// Status code 503
StatusReasonServiceUnavailable
StatusReason
=
"ServiceUnavailable"
)
)
// StatusCause provides more information about an api.Status failure, including
// StatusCause provides more information about an api.Status failure, including
...
...
pkg/registry/service/rest.go
View file @
1a908a27
...
@@ -300,7 +300,7 @@ func (rs *REST) ResourceLocation(ctx api.Context, id string) (*url.URL, http.Rou
...
@@ -300,7 +300,7 @@ func (rs *REST) ResourceLocation(ctx api.Context, id string) (*url.URL, http.Rou
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
if
len
(
eps
.
Subsets
)
==
0
{
if
len
(
eps
.
Subsets
)
==
0
{
return
nil
,
nil
,
fmt
.
Errorf
(
"no endpoints available for %q"
,
svcName
)
return
nil
,
nil
,
errors
.
NewServiceUnavailable
(
fmt
.
Sprintf
(
"no endpoints available for service %q"
,
svcName
)
)
}
}
// Pick a random Subset to start searching from.
// Pick a random Subset to start searching from.
ssSeed
:=
rand
.
Intn
(
len
(
eps
.
Subsets
))
ssSeed
:=
rand
.
Intn
(
len
(
eps
.
Subsets
))
...
@@ -320,7 +320,7 @@ func (rs *REST) ResourceLocation(ctx api.Context, id string) (*url.URL, http.Rou
...
@@ -320,7 +320,7 @@ func (rs *REST) ResourceLocation(ctx api.Context, id string) (*url.URL, http.Rou
}
}
}
}
}
}
return
nil
,
nil
,
fmt
.
Errorf
(
"no endpoints available for %q"
,
id
)
return
nil
,
nil
,
errors
.
NewServiceUnavailable
(
fmt
.
Sprintf
(
"no endpoints available for service %q"
,
id
)
)
}
}
// This is O(N), but we expect haystack to be small;
// This is O(N), but we expect haystack to be small;
...
...
test/integration/auth_test.go
View file @
1a908a27
...
@@ -199,6 +199,16 @@ var aBinding string = `
...
@@ -199,6 +199,16 @@ var aBinding string = `
}
}
`
`
var
emptyEndpoints
string
=
`
{
"kind": "Endpoints",
"apiVersion": "v1",
"metadata": {
"name": "a"%s
}
}
`
var
aEndpoints
string
=
`
var
aEndpoints
string
=
`
{
{
"kind": "Endpoints",
"kind": "Endpoints",
...
@@ -243,6 +253,7 @@ var code405 = map[int]bool{405: true}
...
@@ -243,6 +253,7 @@ var code405 = map[int]bool{405: true}
var
code409
=
map
[
int
]
bool
{
409
:
true
}
var
code409
=
map
[
int
]
bool
{
409
:
true
}
var
code422
=
map
[
int
]
bool
{
422
:
true
}
var
code422
=
map
[
int
]
bool
{
422
:
true
}
var
code500
=
map
[
int
]
bool
{
500
:
true
}
var
code500
=
map
[
int
]
bool
{
500
:
true
}
var
code503
=
map
[
int
]
bool
{
503
:
true
}
// To ensure that a POST completes before a dependent GET, set a timeout.
// To ensure that a POST completes before a dependent GET, set a timeout.
func
addTimeoutFlag
(
URLString
string
)
string
{
func
addTimeoutFlag
(
URLString
string
)
string
{
...
@@ -299,8 +310,14 @@ func getTestRequests() []struct {
...
@@ -299,8 +310,14 @@ func getTestRequests() []struct {
{
"GET"
,
path
(
"services"
,
""
,
""
),
""
,
code200
},
{
"GET"
,
path
(
"services"
,
""
,
""
),
""
,
code200
},
{
"GET"
,
path
(
"services"
,
api
.
NamespaceDefault
,
""
),
""
,
code200
},
{
"GET"
,
path
(
"services"
,
api
.
NamespaceDefault
,
""
),
""
,
code200
},
{
"POST"
,
timeoutPath
(
"services"
,
api
.
NamespaceDefault
,
""
),
aService
,
code201
},
{
"POST"
,
timeoutPath
(
"services"
,
api
.
NamespaceDefault
,
""
),
aService
,
code201
},
// Create an endpoint for the service (this is done automatically by endpoint controller
// whenever a service is created, but this test does not run that controller)
{
"POST"
,
timeoutPath
(
"endpoints"
,
api
.
NamespaceDefault
,
""
),
emptyEndpoints
,
code201
},
// Should return service unavailable when endpoint.subset is empty.
{
"GET"
,
pathWithPrefix
(
"proxy"
,
"services"
,
api
.
NamespaceDefault
,
"a"
)
+
"/"
,
""
,
code503
},
{
"PUT"
,
timeoutPath
(
"services"
,
api
.
NamespaceDefault
,
"a"
),
aService
,
code200
},
{
"PUT"
,
timeoutPath
(
"services"
,
api
.
NamespaceDefault
,
"a"
),
aService
,
code200
},
{
"GET"
,
path
(
"services"
,
api
.
NamespaceDefault
,
"a"
),
""
,
code200
},
{
"GET"
,
path
(
"services"
,
api
.
NamespaceDefault
,
"a"
),
""
,
code200
},
{
"DELETE"
,
timeoutPath
(
"endpoints"
,
api
.
NamespaceDefault
,
"a"
),
""
,
code200
},
{
"DELETE"
,
timeoutPath
(
"services"
,
api
.
NamespaceDefault
,
"a"
),
""
,
code200
},
{
"DELETE"
,
timeoutPath
(
"services"
,
api
.
NamespaceDefault
,
"a"
),
""
,
code200
},
// Normal methods on replicationControllers
// Normal methods on replicationControllers
...
...
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