Skip to content

Commit ff95ae0

Browse files
committed
Continue streaming kubelet logs when runtime is unavailable
Container runtimes are able to run existing containers even when their main CRI server is not available for any reason. The call to the container status RPC happens quite frequently during log parsing, means that a single CRI interruption will also abort streaming the logs. We now check that specific use case and continue following the log streaming if the CRI is unavailable. We still abort the streaming accordingly if the CRI comes back and the container status reports that the workload has exited. Signed-off-by: Sascha Grunert <[email protected]>
1 parent 9d63e57 commit ff95ae0

File tree

1 file changed

+9
-0
lines changed
  • staging/src/k8s.io/cri-client/pkg/logs

1 file changed

+9
-0
lines changed

staging/src/k8s.io/cri-client/pkg/logs/logs.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"time"
3131

3232
"github.com/fsnotify/fsnotify"
33+
"google.golang.org/grpc/codes"
34+
"google.golang.org/grpc/status"
3335

3436
v1 "k8s.io/api/core/v1"
3537
internalapi "k8s.io/cri-api/pkg/apis"
@@ -422,6 +424,13 @@ func ReadLogs(ctx context.Context, logger *klog.Logger, path, containerID string
422424
func isContainerRunning(ctx context.Context, logger *klog.Logger, id string, r internalapi.RuntimeService) (bool, error) {
423425
resp, err := r.ContainerStatus(ctx, id, false)
424426
if err != nil {
427+
// Assume that the container is still running when the runtime is
428+
// unavailable. Most runtimes support that containers can be in running
429+
// state even if their CRI server is not available right now.
430+
if status.Code(err) == codes.Unavailable {
431+
return true, nil
432+
}
433+
425434
return false, err
426435
}
427436
status := resp.GetStatus()

0 commit comments

Comments
 (0)