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
37903834
Unverified
Commit
37903834
authored
Apr 06, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove need for server connections for dry-run create
parent
d371be33
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
30 deletions
+31
-30
test-cmd-util.sh
hack/make-rules/test-cmd-util.sh
+3
-2
create.go
pkg/kubectl/cmd/create.go
+28
-28
No files found.
hack/make-rules/test-cmd-util.sh
View file @
37903834
...
@@ -2387,11 +2387,12 @@ run_secrets_test() {
...
@@ -2387,11 +2387,12 @@ run_secrets_test() {
create_and_use_new_namespace
create_and_use_new_namespace
kube::log::status
"Testing secrets"
kube::log::status
"Testing secrets"
# Ensure dry run succeeds and includes kind, apiVersion and data
# Ensure dry run succeeds and includes kind, apiVersion and data
, and doesn't require a server connection
output_message
=
$(
kubectl create secret generic
test
--from-literal
=
key1
=
value1
--dry-run
-o
yaml
)
output_message
=
$(
kubectl create secret generic
test
--from-literal
=
key1
=
value1
--dry-run
-o
yaml
--server
=
example.com
--v
=
6
)
kube::test::if_has_string
"
${
output_message
}
"
'kind: Secret'
kube::test::if_has_string
"
${
output_message
}
"
'kind: Secret'
kube::test::if_has_string
"
${
output_message
}
"
'apiVersion: v1'
kube::test::if_has_string
"
${
output_message
}
"
'apiVersion: v1'
kube::test::if_has_string
"
${
output_message
}
"
'key1: dmFsdWUx'
kube::test::if_has_string
"
${
output_message
}
"
'key1: dmFsdWUx'
kube::test::if_has_not_string
"
${
output_message
}
"
'example.com'
### Create a new namespace
### Create a new namespace
# Pre-condition: the test-secrets namespace does not exist
# Pre-condition: the test-secrets namespace does not exist
...
...
pkg/kubectl/cmd/create.go
View file @
37903834
...
@@ -315,34 +315,34 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
...
@@ -315,34 +315,34 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
return
err
return
err
}
}
mapper
,
typer
:=
f
.
Object
()
mapper
,
typer
:=
f
.
Object
()
gvks
,
_
,
err
:=
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
return
err
}
gvk
:=
gvks
[
0
]
mapping
,
err
:=
mapper
.
RESTMapping
(
schema
.
GroupKind
{
Group
:
gvk
.
Group
,
Kind
:
gvk
.
Kind
},
gvk
.
Version
)
if
err
!=
nil
{
return
err
}
client
,
err
:=
f
.
ClientForMapping
(
mapping
)
if
err
!=
nil
{
return
err
}
resourceMapper
:=
&
resource
.
Mapper
{
ObjectTyper
:
typer
,
RESTMapper
:
mapper
,
ClientMapper
:
resource
.
ClientMapperFunc
(
f
.
ClientForMapping
),
}
info
,
err
:=
resourceMapper
.
InfoForObject
(
obj
,
nil
)
if
err
!=
nil
{
return
err
}
if
err
:=
kubectl
.
CreateOrUpdateAnnotation
(
cmdutil
.
GetFlagBool
(
cmd
,
cmdutil
.
ApplyAnnotationsFlag
),
info
,
cmdutil
.
InternalVersionJSONEncoder
());
err
!=
nil
{
return
err
}
obj
=
info
.
Object
if
!
options
.
DryRun
{
if
!
options
.
DryRun
{
gvks
,
_
,
err
:=
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
return
err
}
gvk
:=
gvks
[
0
]
mapping
,
err
:=
mapper
.
RESTMapping
(
schema
.
GroupKind
{
Group
:
gvk
.
Group
,
Kind
:
gvk
.
Kind
},
gvk
.
Version
)
if
err
!=
nil
{
return
err
}
client
,
err
:=
f
.
ClientForMapping
(
mapping
)
if
err
!=
nil
{
return
err
}
resourceMapper
:=
&
resource
.
Mapper
{
ObjectTyper
:
typer
,
RESTMapper
:
mapper
,
ClientMapper
:
resource
.
ClientMapperFunc
(
f
.
ClientForMapping
),
}
info
,
err
:=
resourceMapper
.
InfoForObject
(
obj
,
nil
)
if
err
!=
nil
{
return
err
}
if
err
:=
kubectl
.
CreateOrUpdateAnnotation
(
cmdutil
.
GetFlagBool
(
cmd
,
cmdutil
.
ApplyAnnotationsFlag
),
info
,
cmdutil
.
InternalVersionJSONEncoder
());
err
!=
nil
{
return
err
}
obj
=
info
.
Object
obj
,
err
=
resource
.
NewHelper
(
client
,
mapping
)
.
Create
(
namespace
,
false
,
info
.
Object
)
obj
,
err
=
resource
.
NewHelper
(
client
,
mapping
)
.
Create
(
namespace
,
false
,
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -354,7 +354,7 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
...
@@ -354,7 +354,7 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
}
}
if
useShortOutput
:=
options
.
OutputFormat
==
"name"
;
useShortOutput
||
len
(
options
.
OutputFormat
)
==
0
{
if
useShortOutput
:=
options
.
OutputFormat
==
"name"
;
useShortOutput
||
len
(
options
.
OutputFormat
)
==
0
{
cmdutil
.
PrintSuccess
(
useShortOutput
,
out
,
info
.
Object
,
options
.
DryRun
,
"created"
)
cmdutil
.
PrintSuccess
(
useShortOutput
,
out
,
obj
,
options
.
DryRun
,
"created"
)
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