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
3d75e990
Commit
3d75e990
authored
Dec 05, 2017
by
Zhenguo Niu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Kubectl] Update RunCreate to follow more conventions
parent
21751996
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
33 deletions
+44
-33
create.go
pkg/kubectl/cmd/create.go
+44
-33
No files found.
pkg/kubectl/cmd/create.go
View file @
3d75e990
...
...
@@ -42,6 +42,8 @@ type CreateOptions struct {
Selector
string
EditBeforeCreate
bool
Raw
string
Out
io
.
Writer
ErrOut
io
.
Writer
}
var
(
...
...
@@ -62,7 +64,10 @@ var (
)
func
NewCmdCreate
(
f
cmdutil
.
Factory
,
out
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
var
options
CreateOptions
options
:=
&
CreateOptions
{
Out
:
out
,
ErrOut
:
errOut
,
}
cmd
:=
&
cobra
.
Command
{
Use
:
"create -f FILENAME"
,
...
...
@@ -76,7 +81,7 @@ func NewCmdCreate(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
return
}
cmdutil
.
CheckErr
(
options
.
ValidateArgs
(
cmd
,
args
))
cmdutil
.
CheckErr
(
RunCreate
(
f
,
cmd
,
out
,
errOut
,
&
options
))
cmdutil
.
CheckErr
(
options
.
RunCreate
(
f
,
cmd
))
},
}
...
...
@@ -143,36 +148,15 @@ func (o *CreateOptions) ValidateArgs(cmd *cobra.Command, args []string) error {
return
nil
}
func
RunCreate
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
out
,
errOut
io
.
Writer
,
options
*
CreateOptions
)
error
{
func
(
o
*
CreateOptions
)
RunCreate
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
// raw only makes sense for a single file resource multiple objects aren't likely to do what you want.
// the validator enforces this, so
if
len
(
options
.
Raw
)
>
0
{
restClient
,
err
:=
f
.
RESTClient
()
if
err
!=
nil
{
return
err
}
var
data
io
.
ReadCloser
if
options
.
FilenameOptions
.
Filenames
[
0
]
==
"-"
{
data
=
os
.
Stdin
}
else
{
data
,
err
=
os
.
Open
(
options
.
FilenameOptions
.
Filenames
[
0
])
if
err
!=
nil
{
return
err
}
}
// TODO post content with stream. Right now it ignores body content
bytes
,
err
:=
restClient
.
Post
()
.
RequestURI
(
options
.
Raw
)
.
Body
(
data
)
.
DoRaw
()
if
err
!=
nil
{
return
err
}
fmt
.
Fprintf
(
out
,
"%v"
,
string
(
bytes
))
return
nil
if
len
(
o
.
Raw
)
>
0
{
return
o
.
raw
(
f
)
}
if
o
ptions
.
EditBeforeCreate
{
return
RunEditOnCreate
(
f
,
o
ut
,
errOut
,
cmd
,
&
options
.
FilenameOptions
)
if
o
.
EditBeforeCreate
{
return
RunEditOnCreate
(
f
,
o
.
Out
,
o
.
ErrOut
,
cmd
,
&
o
.
FilenameOptions
)
}
schema
,
err
:=
f
.
Validator
(
cmdutil
.
GetFlagBool
(
cmd
,
"validate"
))
if
err
!=
nil
{
...
...
@@ -189,8 +173,8 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
Schema
(
schema
)
.
ContinueOnError
()
.
NamespaceParam
(
cmdNamespace
)
.
DefaultNamespace
()
.
FilenameParam
(
enforceNamespace
,
&
o
ptions
.
FilenameOptions
)
.
LabelSelectorParam
(
o
ptions
.
Selector
)
.
FilenameParam
(
enforceNamespace
,
&
o
.
FilenameOptions
)
.
LabelSelectorParam
(
o
.
Selector
)
.
Flatten
()
.
Do
()
err
=
r
.
Err
()
...
...
@@ -227,13 +211,13 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
shortOutput
:=
output
==
"name"
if
len
(
output
)
>
0
&&
!
shortOutput
{
return
f
.
PrintResourceInfoForCommand
(
cmd
,
info
,
out
)
return
f
.
PrintResourceInfoForCommand
(
cmd
,
info
,
o
.
O
ut
)
}
if
!
shortOutput
{
f
.
PrintObjectSpecificMessage
(
info
.
Object
,
out
)
f
.
PrintObjectSpecificMessage
(
info
.
Object
,
o
.
O
ut
)
}
f
.
PrintSuccess
(
mapper
,
shortOutput
,
out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
dryRun
,
"created"
)
f
.
PrintSuccess
(
mapper
,
shortOutput
,
o
.
O
ut
,
info
.
Mapping
.
Resource
,
info
.
Name
,
dryRun
,
"created"
)
return
nil
})
if
err
!=
nil
{
...
...
@@ -245,6 +229,33 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
return
nil
}
// raw makes a simple HTTP request to the provided path on the server using the default
// credentials.
func
(
o
*
CreateOptions
)
raw
(
f
cmdutil
.
Factory
)
error
{
restClient
,
err
:=
f
.
RESTClient
()
if
err
!=
nil
{
return
err
}
var
data
io
.
ReadCloser
if
o
.
FilenameOptions
.
Filenames
[
0
]
==
"-"
{
data
=
os
.
Stdin
}
else
{
data
,
err
=
os
.
Open
(
o
.
FilenameOptions
.
Filenames
[
0
])
if
err
!=
nil
{
return
err
}
}
// TODO post content with stream. Right now it ignores body content
bytes
,
err
:=
restClient
.
Post
()
.
RequestURI
(
o
.
Raw
)
.
Body
(
data
)
.
DoRaw
()
if
err
!=
nil
{
return
err
}
fmt
.
Fprintf
(
o
.
Out
,
"%v"
,
string
(
bytes
))
return
nil
}
func
RunEditOnCreate
(
f
cmdutil
.
Factory
,
out
,
errOut
io
.
Writer
,
cmd
*
cobra
.
Command
,
options
*
resource
.
FilenameOptions
)
error
{
editOptions
:=
&
editor
.
EditOptions
{
EditMode
:
editor
.
EditBeforeCreateMode
,
...
...
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