From 204a67aa959b83bb6e0deb8db6bad097c22b8960 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 3 May 2018 20:07:48 +0200 Subject: [PATCH] Trying to fix the logs + First second of logs can be lost + The code tries to reconnect to pods that are known to be terminated. Signed-off-by: David Gageot --- pkg/skaffold/kubernetes/log.go | 2 +- pkg/skaffold/kubernetes/wait.go | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/skaffold/kubernetes/log.go b/pkg/skaffold/kubernetes/log.go index c36065c90e2..94a2fead2dc 100644 --- a/pkg/skaffold/kubernetes/log.go +++ b/pkg/skaffold/kubernetes/log.go @@ -111,7 +111,7 @@ func (a *LogAggregator) streamLogs(ctx context.Context, client corev1.CoreV1Inte logrus.Infof("Stream logs from pod: %s container: %s", pod.Name, container.Name) - sinceSeconds := int64(time.Since(a.startTime).Seconds()) + sinceSeconds := int64(time.Since(a.startTime).Seconds() + 0.5) // 0s means all the logs if sinceSeconds == 0 { sinceSeconds = 1 diff --git a/pkg/skaffold/kubernetes/wait.go b/pkg/skaffold/kubernetes/wait.go index 7ef15eff820..c82573e0d62 100644 --- a/pkg/skaffold/kubernetes/wait.go +++ b/pkg/skaffold/kubernetes/wait.go @@ -30,23 +30,36 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes" corev1 "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/tools/cache" - - "k8s.io/apimachinery/pkg/util/wait" ) func WaitForPodReady(pods corev1.PodInterface, podName string) error { + logrus.Infof("Waiting for %s to be scheduled", podName) + err := wait.PollImmediate(time.Millisecond*500, time.Second*10, func() (bool, error) { + _, err := pods.Get(podName, meta_v1.GetOptions{ + IncludeUninitialized: true, + }) + if err != nil { + logrus.Infof("Getting pod %s", err) + return false, nil + } + return true, nil + }) + if err != nil { + return err + } + logrus.Infof("Waiting for %s to be ready", podName) return wait.PollImmediate(time.Millisecond*500, time.Minute*10, func() (bool, error) { pod, err := pods.Get(podName, meta_v1.GetOptions{ IncludeUninitialized: true, }) if err != nil { - logrus.Infof("Getting pod %s", err) - return false, nil + return false, fmt.Errorf("not found: %s", podName) } switch pod.Status.Phase { case v1.PodRunning: