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
964bc8af
Commit
964bc8af
authored
May 07, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verify namespace is not set on root objects
parent
65cf37ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
builder_test.go
pkg/kubectl/resource/builder_test.go
+34
-0
visitor.go
pkg/kubectl/resource/visitor.go
+3
-0
No files found.
pkg/kubectl/resource/builder_test.go
View file @
964bc8af
...
@@ -147,6 +147,15 @@ func streamYAMLTestData() (io.Reader, *api.PodList, *api.ServiceList) {
...
@@ -147,6 +147,15 @@ func streamYAMLTestData() (io.Reader, *api.PodList, *api.ServiceList) {
return
r
,
pods
,
svc
return
r
,
pods
,
svc
}
}
func
streamTestObject
(
obj
runtime
.
Object
)
io
.
Reader
{
r
,
w
:=
io
.
Pipe
()
go
func
()
{
defer
w
.
Close
()
w
.
Write
([]
byte
(
runtime
.
EncodeOrDie
(
latest
.
Codec
,
obj
)))
}()
return
r
}
type
testVisitor
struct
{
type
testVisitor
struct
{
InjectErr
error
InjectErr
error
Infos
[]
*
Info
Infos
[]
*
Info
...
@@ -617,6 +626,31 @@ func TestSingularObject(t *testing.T) {
...
@@ -617,6 +626,31 @@ func TestSingularObject(t *testing.T) {
}
}
}
}
func
TestSingularRootScopedObject
(
t
*
testing
.
T
)
{
node
:=
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
},
Spec
:
api
.
NodeSpec
{
ExternalID
:
"test"
}}
r
:=
streamTestObject
(
node
)
infos
,
err
:=
NewBuilder
(
latest
.
RESTMapper
,
api
.
Scheme
,
fakeClient
())
.
NamespaceParam
(
"test"
)
.
DefaultNamespace
()
.
Stream
(
r
,
"STDIN"
)
.
Flatten
()
.
Do
()
.
Infos
()
if
err
!=
nil
||
len
(
infos
)
!=
1
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
infos
[
0
]
.
Namespace
!=
""
{
t
.
Errorf
(
"namespace should be empty: %#v"
,
infos
[
0
])
}
n
,
ok
:=
infos
[
0
]
.
Object
.
(
*
api
.
Node
)
if
!
ok
{
t
.
Fatalf
(
"unexpected object: %#v"
,
infos
[
0
]
.
Object
)
}
if
n
.
Name
!=
"test"
||
n
.
Namespace
!=
""
{
t
.
Errorf
(
"unexpected object: %#v"
,
n
)
}
}
func
TestListObject
(
t
*
testing
.
T
)
{
func
TestListObject
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
pods
,
_
:=
testData
()
labelKey
:=
api
.
LabelSelectorQueryParam
(
testapi
.
Version
())
labelKey
:=
api
.
LabelSelectorQueryParam
(
testapi
.
Version
())
...
...
pkg/kubectl/resource/visitor.go
View file @
964bc8af
...
@@ -474,6 +474,9 @@ func FilterNamespace(info *Info) error {
...
@@ -474,6 +474,9 @@ func FilterNamespace(info *Info) error {
// set. If info.Object is set, it will be mutated as well.
// set. If info.Object is set, it will be mutated as well.
func
SetNamespace
(
namespace
string
)
VisitorFunc
{
func
SetNamespace
(
namespace
string
)
VisitorFunc
{
return
func
(
info
*
Info
)
error
{
return
func
(
info
*
Info
)
error
{
if
!
info
.
Namespaced
()
{
return
nil
}
if
len
(
info
.
Namespace
)
==
0
{
if
len
(
info
.
Namespace
)
==
0
{
info
.
Namespace
=
namespace
info
.
Namespace
=
namespace
UpdateObjectNamespace
(
info
)
UpdateObjectNamespace
(
info
)
...
...
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