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
cc09bd97
Unverified
Commit
cc09bd97
authored
Feb 14, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Feb 14, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74029 from soltysh/explain_nil2
Add missing VisitArbitrary methods in kubectl explain
parents
08d05227
22a3f6de
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
0 deletions
+109
-0
field_lookup.go
pkg/kubectl/explain/field_lookup.go
+4
-0
field_lookup_test.go
pkg/kubectl/explain/field_lookup_test.go
+45
-0
model_printer.go
pkg/kubectl/explain/model_printer.go
+14
-0
model_printer_test.go
pkg/kubectl/explain/model_printer_test.go
+37
-0
test-swagger.json
pkg/kubectl/explain/test-swagger.json
+9
-0
No files found.
pkg/kubectl/explain/field_lookup.go
View file @
cc09bd97
...
...
@@ -89,6 +89,10 @@ func (f *fieldLookup) VisitKind(k *proto.Kind) {
subSchema
.
Accept
(
f
)
}
func
(
f
*
fieldLookup
)
VisitArbitrary
(
a
*
proto
.
Arbitrary
)
{
f
.
Schema
=
a
}
// VisitReference is mostly a passthrough.
func
(
f
*
fieldLookup
)
VisitReference
(
r
proto
.
Reference
)
{
if
f
.
SaveLeafSchema
(
r
)
{
...
...
pkg/kubectl/explain/field_lookup_test.go
View file @
cc09bd97
...
...
@@ -87,3 +87,48 @@ func TestFindField(t *testing.T) {
})
}
}
func
TestCrdFindField
(
t
*
testing
.
T
)
{
schema
:=
resources
.
LookupResource
(
schema
.
GroupVersionKind
{
Group
:
""
,
Version
:
"v1"
,
Kind
:
"CrdKind"
,
})
if
schema
==
nil
{
t
.
Fatal
(
"Counldn't find schema v1.CrdKind"
)
}
tests
:=
[]
struct
{
name
string
path
[]
string
err
string
expectedPath
string
}{
{
name
:
"test1"
,
path
:
[]
string
{},
expectedPath
:
"CrdKind"
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
path
,
err
:=
LookupSchemaForField
(
schema
,
tt
.
path
)
gotErr
:=
""
if
err
!=
nil
{
gotErr
=
err
.
Error
()
}
gotPath
:=
""
if
path
!=
nil
{
gotPath
=
path
.
GetPath
()
.
String
()
}
if
gotErr
!=
tt
.
err
||
gotPath
!=
tt
.
expectedPath
{
t
.
Errorf
(
"LookupSchemaForField(schema, %v) = (path: %q, err: %q), expected (path: %q, err: %q)"
,
tt
.
path
,
gotPath
,
gotErr
,
tt
.
expectedPath
,
tt
.
err
)
}
})
}
}
pkg/kubectl/explain/model_printer.go
View file @
cc09bd97
...
...
@@ -56,10 +56,12 @@ func (m *modelPrinter) PrintDescription(schema proto.Schema) error {
if
err
:=
m
.
Writer
.
Write
(
"DESCRIPTION:"
);
err
!=
nil
{
return
err
}
empty
:=
true
for
i
,
desc
:=
range
append
(
m
.
Descriptions
,
schema
.
GetDescription
())
{
if
desc
==
""
{
continue
}
empty
=
false
if
i
!=
0
{
if
err
:=
m
.
Writer
.
Write
(
""
);
err
!=
nil
{
return
err
...
...
@@ -69,6 +71,9 @@ func (m *modelPrinter) PrintDescription(schema proto.Schema) error {
return
err
}
}
if
empty
{
return
m
.
Writer
.
Indent
(
descriptionIndentLevel
)
.
WriteWrapped
(
"<empty>"
)
}
return
nil
}
...
...
@@ -134,6 +139,15 @@ func (m *modelPrinter) VisitPrimitive(p *proto.Primitive) {
m
.
Error
=
m
.
PrintDescription
(
p
)
}
func
(
m
*
modelPrinter
)
VisitArbitrary
(
a
*
proto
.
Arbitrary
)
{
if
err
:=
m
.
PrintKindAndVersion
();
err
!=
nil
{
m
.
Error
=
err
return
}
m
.
Error
=
m
.
PrintDescription
(
a
)
}
// VisitReference recurses inside the subtype, while collecting the description.
func
(
m
*
modelPrinter
)
VisitReference
(
r
proto
.
Reference
)
{
m
.
Descriptions
=
append
(
m
.
Descriptions
,
r
.
GetDescription
())
...
...
pkg/kubectl/explain/model_printer_test.go
View file @
cc09bd97
...
...
@@ -133,3 +133,40 @@ DESCRIPTION:
}
}
}
func
TestCRDModel
(
t
*
testing
.
T
)
{
gvk
:=
schema
.
GroupVersionKind
{
Group
:
""
,
Version
:
"v1"
,
Kind
:
"CrdKind"
,
}
schema
:=
resources
.
LookupResource
(
gvk
)
if
schema
==
nil
{
t
.
Fatal
(
"Couldn't find schema v1.CrdKind"
)
}
tests
:=
[]
struct
{
path
[]
string
want
string
}{
{
path
:
[]
string
{},
want
:
`KIND: CrdKind
VERSION: v1
DESCRIPTION:
<empty>
`
,
},
}
for
_
,
test
:=
range
tests
{
buf
:=
bytes
.
Buffer
{}
if
err
:=
PrintModelDescription
(
test
.
path
,
&
buf
,
schema
,
gvk
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to PrintModelDescription for path %v: %v"
,
test
.
path
,
err
)
}
got
:=
buf
.
String
()
if
got
!=
test
.
want
{
t
.
Errorf
(
"Got:
\n
%v
\n
Want:
\n
%v
\n
"
,
buf
.
String
(),
test
.
want
)
}
}
}
pkg/kubectl/explain/test-swagger.json
View file @
cc09bd97
...
...
@@ -73,6 +73,15 @@
"$ref"
:
"#/definitions/PrimitiveDef"
}
}
},
"CrdKind"
:
{
"x-kubernetes-group-version-kind"
:
[
{
"group"
:
""
,
"kind"
:
"CrdKind"
,
"version"
:
"v1"
}
]
}
}
}
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