Skip to content

Commit

Permalink
Trying to fix the logs
Browse files Browse the repository at this point in the history
 + 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 <[email protected]>
  • Loading branch information
dgageot committed May 14, 2018
1 parent f5422a6 commit 204a67a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/skaffold/kubernetes/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions pkg/skaffold/kubernetes/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 204a67a

Please sign in to comment.