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
235678d5
Commit
235678d5
authored
Oct 28, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
always allow decoding of status when returned from the API
parent
37122c26
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
7 deletions
+45
-7
client.go
pkg/client/restclient/client.go
+10
-3
client_test.go
pkg/client/restclient/client_test.go
+25
-4
resource_printer.go
pkg/kubectl/resource_printer.go
+10
-0
No files found.
pkg/client/restclient/client.go
View file @
235678d5
...
...
@@ -173,9 +173,16 @@ func createSerializers(config ContentConfig) (*Serializers, error) {
info
=
mediaTypes
[
0
]
}
internalGV
:=
unversioned
.
GroupVersion
{
Group
:
config
.
GroupVersion
.
Group
,
Version
:
runtime
.
APIVersionInternal
,
internalGV
:=
unversioned
.
GroupVersions
{
{
Group
:
config
.
GroupVersion
.
Group
,
Version
:
runtime
.
APIVersionInternal
,
},
// always include the legacy group as a decoding target to handle non-error `Status` return types
{
Group
:
""
,
Version
:
runtime
.
APIVersionInternal
,
},
}
s
:=
&
Serializers
{
...
...
pkg/client/restclient/client_test.go
View file @
235678d5
...
...
@@ -47,6 +47,26 @@ type TestParam struct {
testBodyErrorIsNotNil
bool
}
// TestSerializer makes sure that you're always able to decode an unversioned API object
func
TestSerializer
(
t
*
testing
.
T
)
{
contentConfig
:=
ContentConfig
{
ContentType
:
"application/json"
,
GroupVersion
:
&
unversioned
.
GroupVersion
{
Group
:
"other"
,
Version
:
runtime
.
APIVersionInternal
},
NegotiatedSerializer
:
api
.
Codecs
,
}
serializer
,
err
:=
createSerializers
(
contentConfig
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// bytes based on actual return from API server when encoding an "unversioned" object
obj
,
err
:=
runtime
.
Decode
(
serializer
.
Decoder
,
[]
byte
(
`{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success"}`
))
t
.
Log
(
obj
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
TestDoRequestSuccess
(
t
*
testing
.
T
)
{
testServer
,
fakeHandler
,
status
:=
testServerEnv
(
t
,
200
)
defer
testServer
.
Close
()
...
...
@@ -162,10 +182,11 @@ func TestBadRequest(t *testing.T) {
}
func
validate
(
testParam
TestParam
,
t
*
testing
.
T
,
body
[]
byte
,
fakeHandler
*
utiltesting
.
FakeHandler
)
{
if
testParam
.
expectingError
{
if
testParam
.
actualError
==
nil
{
t
.
Errorf
(
"Expected error"
)
}
switch
{
case
testParam
.
expectingError
&&
testParam
.
actualError
==
nil
:
t
.
Errorf
(
"Expected error"
)
case
!
testParam
.
expectingError
&&
testParam
.
actualError
!=
nil
:
t
.
Error
(
testParam
.
actualError
)
}
if
!
testParam
.
expCreated
{
if
testParam
.
actualCreated
{
...
...
pkg/kubectl/resource_printer.go
View file @
235678d5
...
...
@@ -489,6 +489,7 @@ var (
clusterRoleColumns
=
[]
string
{
"NAME"
,
"AGE"
}
clusterRoleBindingColumns
=
[]
string
{
"NAME"
,
"AGE"
}
storageClassColumns
=
[]
string
{
"NAME"
,
"TYPE"
}
statusColumns
=
[]
string
{
"STATUS"
,
"REASON"
,
"MESSAGE"
}
// TODO: consider having 'KIND' for third party resource data
thirdPartyResourceDataColumns
=
[]
string
{
"NAME"
,
"LABELS"
,
"DATA"
}
...
...
@@ -591,6 +592,7 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h
.
Handler
(
certificateSigningRequestColumns
,
printCertificateSigningRequestList
)
h
.
Handler
(
storageClassColumns
,
printStorageClass
)
h
.
Handler
(
storageClassColumns
,
printStorageClassList
)
h
.
Handler
(
statusColumns
,
printStatus
)
}
func
(
h
*
HumanReadablePrinter
)
unknown
(
data
[]
byte
,
w
io
.
Writer
)
error
{
...
...
@@ -2114,6 +2116,14 @@ func printStorageClassList(scList *storage.StorageClassList, w io.Writer, option
return
nil
}
func
printStatus
(
status
*
unversioned
.
Status
,
w
io
.
Writer
,
options
PrintOptions
)
error
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\n
"
,
status
.
Status
,
status
.
Reason
,
status
.
Message
);
err
!=
nil
{
return
err
}
return
nil
}
func
AppendLabels
(
itemLabels
map
[
string
]
string
,
columnLabels
[]
string
)
string
{
var
buffer
bytes
.
Buffer
...
...
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