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
e87d6301
Unverified
Commit
e87d6301
authored
Apr 12, 2018
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup resources created by run --rm
parent
a71393a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
31 deletions
+37
-31
run.go
pkg/kubectl/cmd/run.go
+37
-31
No files found.
pkg/kubectl/cmd/run.go
View file @
e87d6301
...
@@ -275,6 +275,10 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
...
@@ -275,6 +275,10 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
}
}
if
attach
{
if
attach
{
if
remove
{
defer
removeCreatedObjects
(
f
,
createdObjects
,
cmdOut
)
}
quiet
:=
cmdutil
.
GetFlagBool
(
cmd
,
"quiet"
)
quiet
:=
cmdutil
.
GetFlagBool
(
cmd
,
"quiet"
)
opts
:=
&
AttachOptions
{
opts
:=
&
AttachOptions
{
StreamOptions
:
StreamOptions
{
StreamOptions
:
StreamOptions
{
...
@@ -321,37 +325,6 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
...
@@ -321,37 +325,6 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
}
}
}
}
if
remove
{
for
_
,
obj
:=
range
createdObjects
{
namespace
,
err
=
obj
.
Mapping
.
MetadataAccessor
.
Namespace
(
obj
.
Object
)
if
err
!=
nil
{
return
err
}
var
name
string
name
,
err
=
obj
.
Mapping
.
MetadataAccessor
.
Name
(
obj
.
Object
)
if
err
!=
nil
{
return
err
}
r
:=
f
.
NewBuilder
()
.
Internal
()
.
ContinueOnError
()
.
NamespaceParam
(
namespace
)
.
DefaultNamespace
()
.
ResourceNames
(
obj
.
Mapping
.
Resource
,
name
)
.
Flatten
()
.
Do
()
// Note: we pass in "true" for the "quiet" parameter because
// ReadResult will only print one thing based on the "quiet"
// flag, and that's the "pod xxx deleted" message. If they
// asked for us to remove the pod (via --rm) then telling them
// its been deleted is unnecessary since that's what they asked
// for. We should only print something if the "rm" fails.
err
=
ReapResult
(
r
,
f
,
cmdOut
,
true
,
true
,
0
,
-
1
,
false
,
false
,
true
)
if
err
!=
nil
{
return
err
}
}
}
// after removal is done, return successfully if we are not interested in the exit code
// after removal is done, return successfully if we are not interested in the exit code
if
!
waitForExitCode
{
if
!
waitForExitCode
{
return
nil
return
nil
...
@@ -390,6 +363,39 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
...
@@ -390,6 +363,39 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
return
utilerrors
.
NewAggregate
(
allErrs
)
return
utilerrors
.
NewAggregate
(
allErrs
)
}
}
func
removeCreatedObjects
(
f
cmdutil
.
Factory
,
createdObjects
[]
*
RunObject
,
cmdOut
io
.
Writer
)
error
{
for
_
,
obj
:=
range
createdObjects
{
namespace
,
err
:=
obj
.
Mapping
.
MetadataAccessor
.
Namespace
(
obj
.
Object
)
if
err
!=
nil
{
return
err
}
var
name
string
name
,
err
=
obj
.
Mapping
.
MetadataAccessor
.
Name
(
obj
.
Object
)
if
err
!=
nil
{
return
err
}
r
:=
f
.
NewBuilder
()
.
Internal
()
.
ContinueOnError
()
.
NamespaceParam
(
namespace
)
.
DefaultNamespace
()
.
ResourceNames
(
obj
.
Mapping
.
Resource
,
name
)
.
Flatten
()
.
Do
()
// Note: we pass in "true" for the "quiet" parameter because
// ReadResult will only print one thing based on the "quiet"
// flag, and that's the "pod xxx deleted" message. If they
// asked for us to remove the pod (via --rm) then telling them
// its been deleted is unnecessary since that's what they asked
// for. We should only print something if the "rm" fails.
err
=
ReapResult
(
r
,
f
,
cmdOut
,
true
,
true
,
0
,
-
1
,
false
,
false
,
true
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
// waitForPod watches the given pod until the exitCondition is true
// waitForPod watches the given pod until the exitCondition is true
func
waitForPod
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
exitCondition
watch
.
ConditionFunc
)
(
*
api
.
Pod
,
error
)
{
func
waitForPod
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
exitCondition
watch
.
ConditionFunc
)
(
*
api
.
Pod
,
error
)
{
w
,
err
:=
podClient
.
Pods
(
ns
)
.
Watch
(
metav1
.
SingleObject
(
metav1
.
ObjectMeta
{
Name
:
name
}))
w
,
err
:=
podClient
.
Pods
(
ns
)
.
Watch
(
metav1
.
SingleObject
(
metav1
.
ObjectMeta
{
Name
:
name
}))
...
...
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