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
a2f943e7
Commit
a2f943e7
authored
Sep 26, 2016
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move panic handler into genericapiserver
parent
69206f53
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
41 deletions
+66
-41
handlers.go
pkg/apiserver/handlers.go
+0
-39
config.go
pkg/genericapiserver/config.go
+2
-2
panics.go
pkg/genericapiserver/filters/panics.go
+64
-0
No files found.
pkg/apiserver/handlers.go
View file @
a2f943e7
...
...
@@ -19,15 +19,11 @@ package apiserver
import
(
"fmt"
"net/http"
"runtime/debug"
"strings"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/auth/authorizer"
"k8s.io/kubernetes/pkg/httplog"
"k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/sets"
)
...
...
@@ -70,41 +66,6 @@ func ReadOnly(handler http.Handler) http.Handler {
})
}
// RecoverPanics wraps an http Handler to recover and log panics.
func
RecoverPanics
(
handler
http
.
Handler
,
resolver
*
RequestInfoResolver
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
defer
runtime
.
HandleCrash
(
func
(
err
interface
{})
{
http
.
Error
(
w
,
"This request caused apisever to panic. Look in log for details."
,
http
.
StatusInternalServerError
)
glog
.
Errorf
(
"APIServer panic'd on %v %v: %v
\n
%s
\n
"
,
req
.
Method
,
req
.
RequestURI
,
err
,
debug
.
Stack
())
})
logger
:=
httplog
.
NewLogged
(
req
,
&
w
)
requestInfo
,
err
:=
resolver
.
GetRequestInfo
(
req
)
if
err
!=
nil
||
requestInfo
.
Verb
!=
"proxy"
{
logger
.
StacktraceWhen
(
httplog
.
StatusIsNot
(
http
.
StatusOK
,
http
.
StatusCreated
,
http
.
StatusAccepted
,
http
.
StatusBadRequest
,
http
.
StatusMovedPermanently
,
http
.
StatusTemporaryRedirect
,
http
.
StatusConflict
,
http
.
StatusNotFound
,
http
.
StatusUnauthorized
,
http
.
StatusForbidden
,
http
.
StatusNotModified
,
errors
.
StatusUnprocessableEntity
,
http
.
StatusSwitchingProtocols
,
),
)
}
defer
logger
.
Log
()
// Dispatch to the internal handler
handler
.
ServeHTTP
(
w
,
req
)
})
}
// RequestAttributeGetter is a function that extracts authorizer.Attributes from an http.Request
type
RequestAttributeGetter
interface
{
GetAttribs
(
req
*
http
.
Request
)
(
attribs
authorizer
.
Attributes
)
...
...
pkg/genericapiserver/config.go
View file @
a2f943e7
...
...
@@ -364,7 +364,7 @@ func (s *GenericAPIServer) buildHandlerChains(c *Config, handler http.Handler) (
// insecure filters
insecure
=
handler
insecure
=
api
.
WithRequestContext
(
insecure
,
c
.
RequestContextMapper
)
insecure
=
apiserver
.
RecoverPanics
(
insecure
,
s
.
NewRequestInfoResolver
())
insecure
=
genericfilters
.
WithPanicRecovery
(
insecure
,
s
.
NewRequestInfoResolver
())
insecure
=
genericfilters
.
WithTimeoutForNonLongRunningRequests
(
insecure
,
longRunningFunc
)
// secure filters
...
...
@@ -375,7 +375,7 @@ func (s *GenericAPIServer) buildHandlerChains(c *Config, handler http.Handler) (
secure
=
audit
.
WithAudit
(
secure
,
attributeGetter
,
s
.
auditWriter
)
// before impersonation to read original user
secure
=
authhandlers
.
WithAuthentication
(
secure
,
c
.
RequestContextMapper
,
c
.
Authenticator
,
authhandlers
.
Unauthorized
(
c
.
SupportsBasicAuth
))
secure
=
api
.
WithRequestContext
(
secure
,
c
.
RequestContextMapper
)
secure
=
apiserver
.
RecoverPanics
(
secure
,
s
.
NewRequestInfoResolver
())
secure
=
genericfilters
.
WithPanicRecovery
(
secure
,
s
.
NewRequestInfoResolver
())
secure
=
genericfilters
.
WithTimeoutForNonLongRunningRequests
(
secure
,
longRunningFunc
)
secure
=
genericfilters
.
WithMaxInFlightLimit
(
secure
,
c
.
MaxRequestsInFlight
,
longRunningFunc
)
...
...
pkg/genericapiserver/filters/panics.go
0 → 100644
View file @
a2f943e7
/*
Copyright 2016 The Kubernetes Authors.
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
filters
import
(
"net/http"
"runtime/debug"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apiserver"
"k8s.io/kubernetes/pkg/httplog"
"k8s.io/kubernetes/pkg/util/runtime"
)
// WithPanicRecovery wraps an http Handler to recover and log panics.
func
WithPanicRecovery
(
handler
http
.
Handler
,
resolver
*
apiserver
.
RequestInfoResolver
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
defer
runtime
.
HandleCrash
(
func
(
err
interface
{})
{
http
.
Error
(
w
,
"This request caused apisever to panic. Look in log for details."
,
http
.
StatusInternalServerError
)
glog
.
Errorf
(
"APIServer panic'd on %v %v: %v
\n
%s
\n
"
,
req
.
Method
,
req
.
RequestURI
,
err
,
debug
.
Stack
())
})
logger
:=
httplog
.
NewLogged
(
req
,
&
w
)
requestInfo
,
err
:=
resolver
.
GetRequestInfo
(
req
)
if
err
!=
nil
||
requestInfo
.
Verb
!=
"proxy"
{
logger
.
StacktraceWhen
(
httplog
.
StatusIsNot
(
http
.
StatusOK
,
http
.
StatusCreated
,
http
.
StatusAccepted
,
http
.
StatusBadRequest
,
http
.
StatusMovedPermanently
,
http
.
StatusTemporaryRedirect
,
http
.
StatusConflict
,
http
.
StatusNotFound
,
http
.
StatusUnauthorized
,
http
.
StatusForbidden
,
http
.
StatusNotModified
,
errors
.
StatusUnprocessableEntity
,
http
.
StatusSwitchingProtocols
,
),
)
}
defer
logger
.
Log
()
// Dispatch to the internal handler
handler
.
ServeHTTP
(
w
,
req
)
})
}
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