Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove chatty "waiting for pod" msg from kubectl run #37164

Merged
merged 1 commit into from
Dec 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 5 additions & 48 deletions pkg/kubectl/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"io"
"os"
"time"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -382,52 +381,18 @@ func contains(resourcesList map[string]*unversioned.APIResourceList, resource un
return false
}

// waitForPod watches the given pod until the exitCondition is true. Each two seconds
// the tick function is called e.g. for progress output.
func waitForPod(podClient coreclient.PodsGetter, ns, name string, exitCondition watch.ConditionFunc, tick func(*api.Pod)) (*api.Pod, error) {
// waitForPod watches the given pod until the exitCondition is true
func waitForPod(podClient coreclient.PodsGetter, ns, name string, exitCondition watch.ConditionFunc) (*api.Pod, error) {
w, err := podClient.Pods(ns).Watch(api.SingleObject(api.ObjectMeta{Name: name}))
if err != nil {
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)
var result *api.Pod
err = intr.Run(func() error {
ev, err := watch.Until(0, w, func(ev watch.Event) (bool, error) {
c, err := exitCondition(ev)
if c == false && err == nil {
pods <- ev.Object.(*api.Pod) // send to ticker
}
return c, err
return exitCondition(ev)
})
result = ev.Object.(*api.Pod)
return err
Expand All @@ -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) {
pod, err := waitForPod(podClient, ns, name, conditions.PodRunningAndReady, func(pod *api.Pod) {
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)
}
})
pod, err := waitForPod(podClient, ns, name, conditions.PodRunningAndReady)

// fix generic not found error with empty name in PodRunningAndReady
if err != nil && errors.IsNotFound(err) {
Expand All @@ -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) {
pod, err := waitForPod(podClient, ns, name, conditions.PodCompleted, func(pod *api.Pod) {
if !quiet {
fmt.Fprintf(out, "Waiting for pod %s/%s to terminate, status is %s\n", pod.Namespace, pod.Name, pod.Status.Phase)
}
})
pod, err := waitForPod(podClient, ns, name, conditions.PodCompleted)

// fix generic not found error with empty name in PodCompleted
if err != nil && errors.IsNotFound(err) {
Expand Down