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
7cdb0eb8
Unverified
Commit
7cdb0eb8
authored
Feb 19, 2017
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NamePrinter should not hardcode scheme
parent
19ae89dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
17 deletions
+19
-17
printers_test.go
pkg/printers/internalversion/printers_test.go
+3
-3
name.go
pkg/printers/name.go
+16
-14
No files found.
pkg/printers/internalversion/printers_test.go
View file @
7cdb0eb8
...
@@ -131,7 +131,7 @@ func TestPrinter(t *testing.T) {
...
@@ -131,7 +131,7 @@ func TestPrinter(t *testing.T) {
{
"test jsonpath"
,
"jsonpath"
,
"{.metadata.name}"
,
podTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"foo"
},
{
"test jsonpath"
,
"jsonpath"
,
"{.metadata.name}"
,
podTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"foo"
},
{
"test jsonpath list"
,
"jsonpath"
,
"{.items[*].metadata.name}"
,
podListTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"foo bar"
},
{
"test jsonpath list"
,
"jsonpath"
,
"{.items[*].metadata.name}"
,
podListTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"foo bar"
},
{
"test jsonpath empty list"
,
"jsonpath"
,
"{.items[*].metadata.name}"
,
emptyListTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
""
},
{
"test jsonpath empty list"
,
"jsonpath"
,
"{.items[*].metadata.name}"
,
emptyListTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
""
},
{
"test name"
,
"name"
,
""
,
podTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"pod/foo
\n
"
},
{
"test name"
,
"name"
,
""
,
podTest
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"pod
s
/foo
\n
"
},
{
"emits versioned objects"
,
"template"
,
"{{.kind}}"
,
testapi
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"Pod"
},
{
"emits versioned objects"
,
"template"
,
"{{.kind}}"
,
testapi
,
[]
schema
.
GroupVersion
{
v1
.
SchemeGroupVersion
},
"Pod"
},
}
}
for
_
,
test
:=
range
printerTests
{
for
_
,
test
:=
range
printerTests
{
...
@@ -342,7 +342,7 @@ func TestNamePrinter(t *testing.T) {
...
@@ -342,7 +342,7 @@ func TestNamePrinter(t *testing.T) {
Name
:
"foo"
,
Name
:
"foo"
,
},
},
},
},
"pod/foo
\n
"
},
"pod
s
/foo
\n
"
},
"List"
:
{
"List"
:
{
&
v1
.
List
{
&
v1
.
List
{
TypeMeta
:
metav1
.
TypeMeta
{
TypeMeta
:
metav1
.
TypeMeta
{
...
@@ -357,7 +357,7 @@ func TestNamePrinter(t *testing.T) {
...
@@ -357,7 +357,7 @@ func TestNamePrinter(t *testing.T) {
},
},
},
},
},
},
"pod
/foo
\n
pod
/bar
\n
"
},
"pod
s/foo
\n
pods
/bar
\n
"
},
}
}
printer
,
_
,
_
:=
printers
.
GetStandardPrinter
(
"name"
,
""
,
false
,
false
,
api
.
Registry
.
RESTMapper
(
api
.
Registry
.
EnabledVersions
()
...
),
api
.
Scheme
,
[]
runtime
.
Decoder
{
api
.
Codecs
.
UniversalDecoder
(),
unstructured
.
UnstructuredJSONScheme
})
printer
,
_
,
_
:=
printers
.
GetStandardPrinter
(
"name"
,
""
,
false
,
false
,
api
.
Registry
.
RESTMapper
(
api
.
Registry
.
EnabledVersions
()
...
),
api
.
Scheme
,
[]
runtime
.
Decoder
{
api
.
Codecs
.
UniversalDecoder
(),
unstructured
.
UnstructuredJSONScheme
})
for
name
,
item
:=
range
tests
{
for
name
,
item
:=
range
tests
{
...
...
pkg/printers/name.go
View file @
7cdb0eb8
...
@@ -21,15 +21,15 @@ import (
...
@@ -21,15 +21,15 @@ import (
"io"
"io"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
)
)
// NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object.
// NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object.
type
NamePrinter
struct
{
type
NamePrinter
struct
{
Decoder
runtime
.
Decoder
Decoders
[]
runtime
.
Decoder
Typer
runtime
.
ObjectTyper
Typer
runtime
.
ObjectTyper
Mapper
meta
.
RESTMapper
}
}
func
(
p
*
NamePrinter
)
AfterPrint
(
w
io
.
Writer
,
res
string
)
error
{
func
(
p
*
NamePrinter
)
AfterPrint
(
w
io
.
Writer
,
res
string
)
error
{
...
@@ -44,7 +44,7 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
...
@@ -44,7 +44,7 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
errs
:=
runtime
.
DecodeList
(
items
,
p
.
Decoder
,
unstructured
.
UnstructuredJSONScheme
);
len
(
errs
)
>
0
{
if
errs
:=
runtime
.
DecodeList
(
items
,
p
.
Decoder
s
...
);
len
(
errs
)
>
0
{
return
utilerrors
.
NewAggregate
(
errs
)
return
utilerrors
.
NewAggregate
(
errs
)
}
}
for
_
,
obj
:=
range
items
{
for
_
,
obj
:=
range
items
{
...
@@ -62,22 +62,24 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
...
@@ -62,22 +62,24 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
}
}
}
}
if
kind
:=
obj
.
GetObjectKind
()
.
GroupVersionKind
();
len
(
kind
.
Kind
)
==
0
{
kind
:=
obj
.
GetObjectKind
()
.
GroupVersionKind
()
// this is the old code. It's unnecessary on decoded external objects, but on internal objects
if
len
(
kind
.
Kind
)
==
0
{
// you may have to do it. Tests are definitely calling it with internals and I'm not sure who else
// is
if
gvks
,
_
,
err
:=
p
.
Typer
.
ObjectKinds
(
obj
);
err
==
nil
{
if
gvks
,
_
,
err
:=
p
.
Typer
.
ObjectKinds
(
obj
);
err
==
nil
{
// TODO: this is wrong, it assumes that meta knows about all Kinds - should take a RESTMapper
for
_
,
gvk
:=
range
gvks
{
_
,
resource
:=
meta
.
KindToResource
(
gvks
[
0
])
if
mappings
,
err
:=
p
.
Mapper
.
RESTMappings
(
gvk
.
GroupKind
(),
gvk
.
Version
);
err
==
nil
&&
len
(
mappings
)
>
0
{
fmt
.
Fprintf
(
w
,
"%s/%s
\n
"
,
resource
.
Resource
,
name
)
fmt
.
Fprintf
(
w
,
"%s/%s
\n
"
,
mappings
[
0
]
.
Resource
,
name
)
}
}
}
else
{
}
else
{
fmt
.
Fprintf
(
w
,
"<unknown>/%s
\n
"
,
name
)
fmt
.
Fprintf
(
w
,
"<unknown>/%s
\n
"
,
name
)
}
}
}
else
{
}
else
{
// TODO: this is wrong, it assumes that meta knows about all Kinds - should take a RESTMapper
if
mappings
,
err
:=
p
.
Mapper
.
RESTMappings
(
kind
.
GroupKind
(),
kind
.
Version
);
err
==
nil
&&
len
(
mappings
)
>
0
{
_
,
resource
:=
meta
.
KindToResource
(
kind
)
fmt
.
Fprintf
(
w
,
"%s/%s
\n
"
,
mappings
[
0
]
.
Resource
,
name
)
fmt
.
Fprintf
(
w
,
"%s/%s
\n
"
,
resource
.
Resource
,
name
)
}
else
{
fmt
.
Fprintf
(
w
,
"<unknown>/%s
\n
"
,
name
)
}
}
}
return
nil
return
nil
...
...
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