mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Remove chatty "waiting for pod" msg from kubectl run
Attacking #28695 one step at a time Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
parent
238459b092
commit
c5387eebe4
@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@ -382,52 +381,18 @@ func contains(resourcesList map[string]*unversioned.APIResourceList, resource un
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForPod watches the given pod until the exitCondition is true. Each two seconds
|
// waitForPod watches the given pod until the exitCondition is true
|
||||||
// the tick function is called e.g. for progress output.
|
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, tick func(*api.Pod)) (*api.Pod, error) {
|
|
||||||
w, err := podClient.Pods(ns).Watch(api.SingleObject(api.ObjectMeta{Name: name}))
|
w, err := podClient.Pods(ns).Watch(api.SingleObject(api.ObjectMeta{Name: name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pods := make(chan *api.Pod) // observed pods passed to the exitCondition
|
|
||||||
defer close(pods)
|
|
||||||
|
|
||||||
// wait for the first event, then start the 2 sec ticker and loop
|
|
||||||
go func() {
|
|
||||||
pod := <-pods
|
|
||||||
if pod == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tick(pod)
|
|
||||||
|
|
||||||
t := time.NewTicker(2 * time.Second)
|
|
||||||
defer t.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case pod = <-pods:
|
|
||||||
if pod == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case _, ok := <-t.C:
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tick(pod)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
intr := interrupt.New(nil, w.Stop)
|
intr := interrupt.New(nil, w.Stop)
|
||||||
var result *api.Pod
|
var result *api.Pod
|
||||||
err = intr.Run(func() error {
|
err = intr.Run(func() error {
|
||||||
ev, err := watch.Until(0, w, func(ev watch.Event) (bool, error) {
|
ev, err := watch.Until(0, w, func(ev watch.Event) (bool, error) {
|
||||||
c, err := exitCondition(ev)
|
return exitCondition(ev)
|
||||||
if c == false && err == nil {
|
|
||||||
pods <- ev.Object.(*api.Pod) // send to ticker
|
|
||||||
}
|
|
||||||
return c, err
|
|
||||||
})
|
})
|
||||||
result = ev.Object.(*api.Pod)
|
result = ev.Object.(*api.Pod)
|
||||||
return err
|
return err
|
||||||
@ -436,11 +401,7 @@ func waitForPod(podClient coreclient.PodsGetter, ns, name string, exitCondition
|
|||||||
}
|
}
|
||||||
|
|
||||||
func waitForPodRunning(podClient coreclient.PodsGetter, ns, name string, out io.Writer, quiet bool) (*api.Pod, error) {
|
func waitForPodRunning(podClient coreclient.PodsGetter, ns, name string, out io.Writer, quiet bool) (*api.Pod, error) {
|
||||||
pod, err := waitForPod(podClient, ns, name, conditions.PodRunningAndReady, func(pod *api.Pod) {
|
pod, err := waitForPod(podClient, ns, name, conditions.PodRunningAndReady)
|
||||||
if !quiet {
|
|
||||||
fmt.Fprintf(out, "Waiting for pod %s/%s to be running, status is %s, pod ready: false\n", pod.Namespace, pod.Name, pod.Status.Phase)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// fix generic not found error with empty name in PodRunningAndReady
|
// fix generic not found error with empty name in PodRunningAndReady
|
||||||
if err != nil && errors.IsNotFound(err) {
|
if err != nil && errors.IsNotFound(err) {
|
||||||
@ -451,11 +412,7 @@ func waitForPodRunning(podClient coreclient.PodsGetter, ns, name string, out io.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func waitForPodTerminated(podClient coreclient.PodsGetter, ns, name string, out io.Writer, quiet bool) (*api.Pod, error) {
|
func waitForPodTerminated(podClient coreclient.PodsGetter, ns, name string, out io.Writer, quiet bool) (*api.Pod, error) {
|
||||||
pod, err := waitForPod(podClient, ns, name, conditions.PodCompleted, func(pod *api.Pod) {
|
pod, err := waitForPod(podClient, ns, name, conditions.PodCompleted)
|
||||||
if !quiet {
|
|
||||||
fmt.Fprintf(out, "Waiting for pod %s/%s to terminate, status is %s\n", pod.Namespace, pod.Name, pod.Status.Phase)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// fix generic not found error with empty name in PodCompleted
|
// fix generic not found error with empty name in PodCompleted
|
||||||
if err != nil && errors.IsNotFound(err) {
|
if err != nil && errors.IsNotFound(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user