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
aa504ccd
Unverified
Commit
aa504ccd
authored
Jan 15, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return correct error when submitting patch in unsupported format
parent
037eec3b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
13 deletions
+32
-13
customresource_handler.go
...ensions-apiserver/pkg/apiserver/customresource_handler.go
+5
-1
BUILD
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/BUILD
+1
-0
patch.go
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go
+18
-9
installer.go
staging/src/k8s.io/apiserver/pkg/endpoints/installer.go
+8
-3
No files found.
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go
View file @
aa504ccd
...
...
@@ -227,7 +227,11 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
http
.
Error
(
w
,
fmt
.
Sprintf
(
"%v not allowed while CustomResourceDefinition is terminating"
,
requestInfo
.
Verb
),
http
.
StatusMethodNotAllowed
)
return
}
handler
:=
handlers
.
PatchResource
(
storage
,
requestScope
,
r
.
admission
,
unstructured
.
UnstructuredObjectConverter
{})
supportedTypes
:=
[]
string
{
string
(
types
.
JSONPatchType
),
string
(
types
.
MergePatchType
),
}
handler
:=
handlers
.
PatchResource
(
storage
,
requestScope
,
r
.
admission
,
unstructured
.
UnstructuredObjectConverter
{},
supportedTypes
)
handler
(
w
,
req
)
return
case
"delete"
:
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/BUILD
View file @
aa504ccd
...
...
@@ -71,6 +71,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/proxy:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/admission:go_default_library",
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go
View file @
aa504ccd
...
...
@@ -32,17 +32,34 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/mergepatch"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apiserver/pkg/admission"
"k8s.io/apiserver/pkg/audit"
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
)
// PatchResource returns a function that will handle a resource patch
// TODO: Eventually PatchResource should just use GuaranteedUpdate and this routine should be a bit cleaner
func
PatchResource
(
r
rest
.
Patcher
,
scope
RequestScope
,
admit
admission
.
Interface
,
converter
runtime
.
ObjectConvertor
)
http
.
HandlerFunc
{
func
PatchResource
(
r
rest
.
Patcher
,
scope
RequestScope
,
admit
admission
.
Interface
,
converter
runtime
.
ObjectConvertor
,
patchTypes
[]
string
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
// Do this first, otherwise name extraction can fail for unrecognized content types
// TODO: handle this in negotiation
contentType
:=
req
.
Header
.
Get
(
"Content-Type"
)
// Remove "; charset=" if included in header.
if
idx
:=
strings
.
Index
(
contentType
,
";"
);
idx
>
0
{
contentType
=
contentType
[
:
idx
]
}
patchType
:=
types
.
PatchType
(
contentType
)
// Ensure the patchType is one we support
if
!
sets
.
NewString
(
patchTypes
...
)
.
Has
(
contentType
)
{
scope
.
err
(
negotiation
.
NewUnsupportedMediaTypeError
(
patchTypes
),
w
,
req
)
return
}
// TODO: we either want to remove timeout or document it (if we
// document, move timeout out of this function and declare it in
// api_installer)
...
...
@@ -63,14 +80,6 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
return
}
// TODO: handle this in negotiation
contentType
:=
req
.
Header
.
Get
(
"Content-Type"
)
// Remove "; charset=" if included in header.
if
idx
:=
strings
.
Index
(
contentType
,
";"
);
idx
>
0
{
contentType
=
contentType
[
:
idx
]
}
patchType
:=
types
.
PatchType
(
contentType
)
patchJS
,
err
:=
readBody
(
req
)
if
err
!=
nil
{
scope
.
err
(
err
,
w
,
req
)
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/installer.go
View file @
aa504ccd
...
...
@@ -690,7 +690,12 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if
hasSubresource
{
doc
=
"partially update "
+
subresource
+
" of the specified "
+
kind
}
handler
:=
metrics
.
InstrumentRouteFunc
(
action
.
Verb
,
resource
,
subresource
,
requestScope
,
restfulPatchResource
(
patcher
,
reqScope
,
admit
,
mapping
.
ObjectConvertor
))
supportedTypes
:=
[]
string
{
string
(
types
.
JSONPatchType
),
string
(
types
.
MergePatchType
),
string
(
types
.
StrategicMergePatchType
),
}
handler
:=
metrics
.
InstrumentRouteFunc
(
action
.
Verb
,
resource
,
subresource
,
requestScope
,
restfulPatchResource
(
patcher
,
reqScope
,
admit
,
mapping
.
ObjectConvertor
,
supportedTypes
))
route
:=
ws
.
PATCH
(
action
.
Path
)
.
To
(
handler
)
.
Doc
(
doc
)
.
Param
(
ws
.
QueryParameter
(
"pretty"
,
"If 'true', then the output is pretty printed."
))
.
...
...
@@ -1099,9 +1104,9 @@ func restfulUpdateResource(r rest.Updater, scope handlers.RequestScope, typer ru
}
}
func
restfulPatchResource
(
r
rest
.
Patcher
,
scope
handlers
.
RequestScope
,
admit
admission
.
Interface
,
converter
runtime
.
ObjectConvertor
)
restful
.
RouteFunction
{
func
restfulPatchResource
(
r
rest
.
Patcher
,
scope
handlers
.
RequestScope
,
admit
admission
.
Interface
,
converter
runtime
.
ObjectConvertor
,
supportedTypes
[]
string
)
restful
.
RouteFunction
{
return
func
(
req
*
restful
.
Request
,
res
*
restful
.
Response
)
{
handlers
.
PatchResource
(
r
,
scope
,
admit
,
converter
)(
res
.
ResponseWriter
,
req
.
Request
)
handlers
.
PatchResource
(
r
,
scope
,
admit
,
converter
,
supportedTypes
)(
res
.
ResponseWriter
,
req
.
Request
)
}
}
...
...
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