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
2fae80c2
Commit
2fae80c2
authored
Apr 30, 2019
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preserve existing namespace when using kubectl set --local
parent
306740f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
1 deletion
+60
-1
set_env_test.go
pkg/kubectl/cmd/set/set_env_test.go
+37
-0
visitor.go
staging/src/k8s.io/cli-runtime/pkg/resource/visitor.go
+6
-1
namespaced-resource.yaml
test/fixtures/pkg/kubectl/cmd/set/namespaced-resource.yaml
+17
-0
No files found.
pkg/kubectl/cmd/set/set_env_test.go
View file @
2fae80c2
...
...
@@ -78,6 +78,43 @@ func TestSetEnvLocal(t *testing.T) {
}
}
func
TestSetEnvLocalNamespace
(
t
*
testing
.
T
)
{
tf
:=
cmdtesting
.
NewTestFactory
()
.
WithNamespace
(
"test"
)
defer
tf
.
Cleanup
()
tf
.
Client
=
&
fake
.
RESTClient
{
GroupVersion
:
schema
.
GroupVersion
{
Version
:
""
},
NegotiatedSerializer
:
scheme
.
Codecs
.
WithoutConversion
(),
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
t
.
Fatalf
(
"unexpected request: %s %#v
\n
%#v"
,
req
.
Method
,
req
.
URL
,
req
)
return
nil
,
nil
}),
}
tf
.
ClientConfigVal
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Version
:
""
}}}
outputFormat
:=
"yaml"
streams
,
_
,
buf
,
bufErr
:=
genericclioptions
.
NewTestIOStreams
()
opts
:=
NewEnvOptions
(
streams
)
opts
.
PrintFlags
=
genericclioptions
.
NewPrintFlags
(
""
)
.
WithDefaultOutput
(
outputFormat
)
.
WithTypeSetter
(
scheme
.
Scheme
)
opts
.
FilenameOptions
=
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../../test/fixtures/pkg/kubectl/cmd/set/namespaced-resource.yaml"
},
}
opts
.
Local
=
true
err
:=
opts
.
Complete
(
tf
,
NewCmdEnv
(
tf
,
streams
),
[]
string
{
"env=prod"
})
assert
.
NoError
(
t
,
err
)
err
=
opts
.
Validate
()
assert
.
NoError
(
t
,
err
)
err
=
opts
.
RunEnv
()
assert
.
NoError
(
t
,
err
)
if
bufErr
.
Len
()
>
0
{
t
.
Errorf
(
"unexpected error: %s"
,
string
(
bufErr
.
String
()))
}
if
!
strings
.
Contains
(
buf
.
String
(),
"namespace: existing-ns"
)
{
t
.
Errorf
(
"did not set env: %s"
,
buf
.
String
())
}
}
func
TestSetMultiResourcesEnvLocal
(
t
*
testing
.
T
)
{
tf
:=
cmdtesting
.
NewTestFactory
()
.
WithNamespace
(
"test"
)
defer
tf
.
Cleanup
()
...
...
staging/src/k8s.io/cli-runtime/pkg/resource/visitor.go
View file @
2fae80c2
...
...
@@ -169,7 +169,12 @@ func (i *Info) String() string {
// Namespaced returns true if the object belongs to a namespace
func
(
i
*
Info
)
Namespaced
()
bool
{
return
i
.
Mapping
!=
nil
&&
i
.
Mapping
.
Scope
.
Name
()
==
meta
.
RESTScopeNameNamespace
if
i
.
Mapping
!=
nil
{
// if we have RESTMapper info, use it
return
i
.
Mapping
.
Scope
.
Name
()
==
meta
.
RESTScopeNameNamespace
}
// otherwise, use the presence of a namespace in the info as an indicator
return
len
(
i
.
Namespace
)
>
0
}
// Watch returns server changes to this object after it was retrieved.
...
...
test/fixtures/pkg/kubectl/cmd/set/namespaced-resource.yaml
0 → 100644
View file @
2fae80c2
apiVersion
:
v1
kind
:
ReplicationController
metadata
:
name
:
namespaced-rc
namespace
:
existing-ns
spec
:
replicas
:
1
selector
:
app
:
mock
template
:
metadata
:
labels
:
app
:
mock
spec
:
containers
:
-
name
:
mock-container
image
:
k8s.gcr.io/pause:3.1
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