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

fix: not available step logs #101

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions engine/engine_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (k *Kubernetes) Run(ctx context.Context, specv runtime.Spec, stepv runtime.
PodNamespace: podNamespace,
PodName: podId,
KubeClient: k.client,
Period: 20 * time.Second,
Period: 5 * time.Second,
})

log.Trace("PodWatcher started")
Expand Down Expand Up @@ -225,10 +225,9 @@ func (k *Kubernetes) Run(ctx context.Context, specv runtime.Spec, stepv runtime.
return
}

err = k.fetchLogs(ctx, spec, step, output)
if err != nil {
return
}
watcher.WaitContainerReStart(containerId)

k.fetchLogs(ctx, spec, step, output)

type containerResult struct {
code int
Expand Down
5 changes: 3 additions & 2 deletions engine/podwatcher/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ type containerWatchInfo struct {

stepState stepState

exitCode int32
reason string
exitCode int32
reason string
restartCount int

addedAt time.Time
failedAt time.Time
Expand Down
29 changes: 29 additions & 0 deletions engine/podwatcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package podwatcher

import (
"context"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -259,6 +260,8 @@ func (pw *PodWatcher) updateContainers(containers []containerInfo) {
s = stepStateRunning
}

c.restartCount = int(cs.restartCount)

if s == c.stepState && c.reason == cs.reason {
continue // step state unchanged
}
Expand Down Expand Up @@ -418,6 +421,32 @@ func (pw *PodWatcher) WaitContainerStart(containerId string) error {
return pw.waitForEvent(containerId, stepStateRunning)
}

// WaitContainerReStart waits until a container in the pod restarts.
func (pw *PodWatcher) WaitContainerReStart(containerId string) bool {
logrus.
WithField("pod", pw.podName).
WithField("container", containerId).
Debug("PodWatcher: Waiting to be restated")
retries := 0
for retries < 60 {
if pw.containerMap[containerId].stepState != stepStateRunning {
return false
}
if pw.containerMap[containerId].restartCount > 0 {
return true
}
retries++
logrus.
WithField("pod", pw.podName).
WithField("container", containerId).
WithField("restart count", strconv.Itoa(pw.containerMap[containerId].restartCount)).
Debug("PodWatcher: Waiting to be restated")

<-time.After(time.Second * 5)
}
return false
}

// WaitContainerTerminated waits until a container in the pod is terminated.
func (pw *PodWatcher) WaitContainerTerminated(containerId string) (int, error) {
err := pw.waitForEvent(containerId, stepStateFinished)
Expand Down