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
1a23f5a7
Commit
1a23f5a7
authored
Aug 30, 2016
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log useful information on 500's
* include error message in error (!!) * add test verifying error message is correct for service ip allocation
parent
1dfd6ab0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
2 deletions
+66
-2
errors.go
pkg/api/errors/errors.go
+1
-1
apiserver.go
pkg/apiserver/apiserver.go
+7
-1
log.go
pkg/httplog/log.go
+6
-0
master_test.go
test/integration/master/master_test.go
+52
-0
No files found.
pkg/api/errors/errors.go
View file @
1a23f5a7
...
@@ -325,7 +325,7 @@ func NewGenericServerResponse(code int, verb string, qualifiedResource unversion
...
@@ -325,7 +325,7 @@ func NewGenericServerResponse(code int, verb string, qualifiedResource unversion
default
:
default
:
if
code
>=
500
{
if
code
>=
500
{
reason
=
unversioned
.
StatusReasonInternalError
reason
=
unversioned
.
StatusReasonInternalError
message
=
"an error on the server has prevented the request from succeeding"
message
=
fmt
.
Sprintf
(
"an error on the server (%q) has prevented the request from succeeding"
,
serverMessage
)
}
}
}
}
switch
{
switch
{
...
...
pkg/apiserver/apiserver.go
View file @
1a23f5a7
...
@@ -266,7 +266,13 @@ func InstallServiceErrorHandler(s runtime.NegotiatedSerializer, container *restf
...
@@ -266,7 +266,13 @@ func InstallServiceErrorHandler(s runtime.NegotiatedSerializer, container *restf
}
}
func
serviceErrorHandler
(
s
runtime
.
NegotiatedSerializer
,
requestResolver
*
RequestInfoResolver
,
apiVersions
[]
string
,
serviceErr
restful
.
ServiceError
,
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
func
serviceErrorHandler
(
s
runtime
.
NegotiatedSerializer
,
requestResolver
*
RequestInfoResolver
,
apiVersions
[]
string
,
serviceErr
restful
.
ServiceError
,
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
errorNegotiated
(
apierrors
.
NewGenericServerResponse
(
serviceErr
.
Code
,
""
,
api
.
Resource
(
""
),
""
,
""
,
0
,
false
),
s
,
unversioned
.
GroupVersion
{},
response
.
ResponseWriter
,
request
.
Request
)
errorNegotiated
(
apierrors
.
NewGenericServerResponse
(
serviceErr
.
Code
,
""
,
api
.
Resource
(
""
),
""
,
serviceErr
.
Message
,
0
,
false
),
s
,
unversioned
.
GroupVersion
{},
response
.
ResponseWriter
,
request
.
Request
,
)
}
}
// Adds a service to return the supported api versions at the legacy /api.
// Adds a service to return the supported api versions at the legacy /api.
...
...
pkg/httplog/log.go
View file @
1a23f5a7
...
@@ -60,6 +60,8 @@ type respLogger struct {
...
@@ -60,6 +60,8 @@ type respLogger struct {
addedInfo
string
addedInfo
string
startTime
time
.
Time
startTime
time
.
Time
captureErrorOutput
bool
req
*
http
.
Request
req
*
http
.
Request
w
http
.
ResponseWriter
w
http
.
ResponseWriter
...
@@ -175,6 +177,9 @@ func (rl *respLogger) Write(b []byte) (int, error) {
...
@@ -175,6 +177,9 @@ func (rl *respLogger) Write(b []byte) (int, error) {
if
!
rl
.
statusRecorded
{
if
!
rl
.
statusRecorded
{
rl
.
recordStatus
(
http
.
StatusOK
)
// Default if WriteHeader hasn't been called
rl
.
recordStatus
(
http
.
StatusOK
)
// Default if WriteHeader hasn't been called
}
}
if
rl
.
captureErrorOutput
{
rl
.
Addf
(
"logging error output: %q
\n
"
,
string
(
b
))
}
return
rl
.
w
.
Write
(
b
)
return
rl
.
w
.
Write
(
b
)
}
}
...
@@ -213,6 +218,7 @@ func (rl *respLogger) recordStatus(status int) {
...
@@ -213,6 +218,7 @@ func (rl *respLogger) recordStatus(status int) {
stack
:=
make
([]
byte
,
50
*
1024
)
stack
:=
make
([]
byte
,
50
*
1024
)
stack
=
stack
[
:
runtime
.
Stack
(
stack
,
false
)]
stack
=
stack
[
:
runtime
.
Stack
(
stack
,
false
)]
rl
.
statusStack
=
"
\n
"
+
string
(
stack
)
rl
.
statusStack
=
"
\n
"
+
string
(
stack
)
rl
.
captureErrorOutput
=
true
}
else
{
}
else
{
rl
.
statusStack
=
""
rl
.
statusStack
=
""
}
}
...
...
test/integration/master/master_test.go
View file @
1a23f5a7
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net"
"net/http"
"net/http"
"strings"
"strings"
"testing"
"testing"
...
@@ -414,3 +415,54 @@ func TestMasterService(t *testing.T) {
...
@@ -414,3 +415,54 @@ func TestMasterService(t *testing.T) {
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
}
}
func
TestServiceAlloc
(
t
*
testing
.
T
)
{
cfg
:=
framework
.
NewIntegrationTestMasterConfig
()
_
,
cidr
,
err
:=
net
.
ParseCIDR
(
"192.168.0.0/30"
)
if
err
!=
nil
{
t
.
Fatalf
(
"bad cidr: %v"
,
err
)
}
cfg
.
ServiceClusterIPRange
=
cidr
_
,
s
:=
framework
.
RunAMaster
(
cfg
)
defer
s
.
Close
()
client
:=
client
.
NewOrDie
(
&
restclient
.
Config
{
Host
:
s
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
svc
:=
func
(
i
int
)
*
api
.
Service
{
return
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
fmt
.
Sprintf
(
"svc-%v"
,
i
),
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{
{
Port
:
80
},
},
},
}
}
// Make a service.
if
_
,
err
:=
client
.
Services
(
api
.
NamespaceDefault
)
.
Create
(
svc
(
1
));
err
!=
nil
{
t
.
Fatalf
(
"got unexpected error: %v"
,
err
)
}
// Make a second service. It will fail because we're out of cluster IPs
if
_
,
err
:=
client
.
Services
(
api
.
NamespaceDefault
)
.
Create
(
svc
(
2
));
err
!=
nil
{
if
!
strings
.
Contains
(
err
.
Error
(),
"range is full"
)
{
t
.
Errorf
(
"unexpected error text: %v"
,
err
)
}
}
else
{
t
.
Fatalf
(
"unexpected sucess"
)
}
// Delete the first service.
if
err
:=
client
.
Services
(
api
.
NamespaceDefault
)
.
Delete
(
svc
(
1
)
.
ObjectMeta
.
Name
);
err
!=
nil
{
t
.
Fatalf
(
"got unexpected error: %v"
,
err
)
}
// This time creating the second service should work.
if
_
,
err
:=
client
.
Services
(
api
.
NamespaceDefault
)
.
Create
(
svc
(
2
));
err
!=
nil
{
t
.
Fatalf
(
"got unexpected error: %v"
,
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