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
2e647044
Unverified
Commit
2e647044
authored
Mar 07, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Mar 07, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #75096 from tnozicka/fix-kubectl-run-watches
Fix kubectl run watches
parents
56c74635
d9e511e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
12 deletions
+34
-12
BUILD
pkg/kubectl/cmd/run/BUILD
+2
-0
run.go
pkg/kubectl/cmd/run/run.go
+32
-12
No files found.
pkg/kubectl/cmd/run/BUILD
View file @
2e647044
...
@@ -23,6 +23,7 @@ go_library(
...
@@ -23,6 +23,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
...
@@ -31,6 +32,7 @@ go_library(
...
@@ -31,6 +32,7 @@ go_library(
"//staging/src/k8s.io/client-go/dynamic:go_default_library",
"//staging/src/k8s.io/client-go/dynamic:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
"//staging/src/k8s.io/client-go/tools/watch:go_default_library",
"//staging/src/k8s.io/client-go/tools/watch:go_default_library",
"//vendor/github.com/docker/distribution/reference:go_default_library",
"//vendor/github.com/docker/distribution/reference:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
...
...
pkg/kubectl/cmd/run/run.go
View file @
2e647044
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/watch"
...
@@ -37,6 +38,7 @@ import (
...
@@ -37,6 +38,7 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes"
corev1client
"k8s.io/client-go/kubernetes/typed/core/v1"
corev1client
"k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
watchtools
"k8s.io/client-go/tools/watch"
watchtools
"k8s.io/client-go/tools/watch"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/attach"
"k8s.io/kubernetes/pkg/kubectl/cmd/attach"
...
@@ -490,18 +492,41 @@ func (o *RunOptions) removeCreatedObjects(f cmdutil.Factory, createdObjects []*R
...
@@ -490,18 +492,41 @@ func (o *RunOptions) removeCreatedObjects(f cmdutil.Factory, createdObjects []*R
// waitForPod watches the given pod until the exitCondition is true
// waitForPod watches the given pod until the exitCondition is true
func
waitForPod
(
podClient
corev1client
.
PodsGetter
,
ns
,
name
string
,
exitCondition
watchtools
.
ConditionFunc
)
(
*
corev1
.
Pod
,
error
)
{
func
waitForPod
(
podClient
corev1client
.
PodsGetter
,
ns
,
name
string
,
exitCondition
watchtools
.
ConditionFunc
)
(
*
corev1
.
Pod
,
error
)
{
w
,
err
:=
podClient
.
Pods
(
ns
)
.
Watch
(
metav1
.
SingleObject
(
metav1
.
ObjectMeta
{
Name
:
name
}))
if
err
!=
nil
{
return
nil
,
err
}
// TODO: expose the timeout
// TODO: expose the timeout
ctx
,
cancel
:=
watchtools
.
ContextWithOptionalTimeout
(
context
.
Background
(),
0
*
time
.
Second
)
ctx
,
cancel
:=
watchtools
.
ContextWithOptionalTimeout
(
context
.
Background
(),
0
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
preconditionFunc
:=
func
(
store
cache
.
Store
)
(
bool
,
error
)
{
_
,
exists
,
err
:=
store
.
Get
(
&
metav1
.
ObjectMeta
{
Namespace
:
ns
,
Name
:
name
})
if
err
!=
nil
{
return
true
,
err
}
if
!
exists
{
// We need to make sure we see the object in the cache before we start waiting for events
// or we would be waiting for the timeout if such object didn't exist.
// (e.g. it was deleted before we started informers so they wouldn't even see the delete event)
return
true
,
errors
.
NewNotFound
(
corev1
.
Resource
(
"pods"
),
name
)
}
return
false
,
nil
}
fieldSelector
:=
fields
.
OneTermEqualSelector
(
"metadata.name"
,
name
)
.
String
()
lw
:=
&
cache
.
ListWatch
{
ListFunc
:
func
(
options
metav1
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
options
.
FieldSelector
=
fieldSelector
return
podClient
.
Pods
(
ns
)
.
List
(
options
)
},
WatchFunc
:
func
(
options
metav1
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
options
.
FieldSelector
=
fieldSelector
return
podClient
.
Pods
(
ns
)
.
Watch
(
options
)
},
}
intr
:=
interrupt
.
New
(
nil
,
cancel
)
intr
:=
interrupt
.
New
(
nil
,
cancel
)
var
result
*
corev1
.
Pod
var
result
*
corev1
.
Pod
err
=
intr
.
Run
(
func
()
error
{
err
:
=
intr
.
Run
(
func
()
error
{
ev
,
err
:=
watchtools
.
UntilWith
outRetry
(
ctx
,
w
,
func
(
ev
watch
.
Event
)
(
bool
,
error
)
{
ev
,
err
:=
watchtools
.
UntilWith
Sync
(
ctx
,
lw
,
&
corev1
.
Pod
{},
preconditionFunc
,
func
(
ev
watch
.
Event
)
(
bool
,
error
)
{
return
exitCondition
(
ev
)
return
exitCondition
(
ev
)
})
})
if
ev
!=
nil
{
if
ev
!=
nil
{
...
@@ -510,11 +535,6 @@ func waitForPod(podClient corev1client.PodsGetter, ns, name string, exitConditio
...
@@ -510,11 +535,6 @@ func waitForPod(podClient corev1client.PodsGetter, ns, name string, exitConditio
return
err
return
err
})
})
// Fix generic not found error.
if
err
!=
nil
&&
errors
.
IsNotFound
(
err
)
{
err
=
errors
.
NewNotFound
(
corev1
.
Resource
(
"pods"
),
name
)
}
return
result
,
err
return
result
,
err
}
}
...
...
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