-
Notifications
You must be signed in to change notification settings - Fork 1k
/
container_reopen_log.go
36 lines (29 loc) · 1.02 KB
/
container_reopen_log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package server
import (
"errors"
"fmt"
"github.com/cri-o/cri-o/internal/log"
"github.com/cri-o/cri-o/internal/oci"
"golang.org/x/net/context"
types "k8s.io/cri-api/pkg/apis/runtime/v1"
)
// ReopenContainerLog reopens the containers log file
func (s *Server) ReopenContainerLog(ctx context.Context, req *types.ReopenContainerLogRequest) (*types.ReopenContainerLogResponse, error) {
ctx, span := log.StartSpan(ctx)
defer span.End()
c, err := s.GetContainerFromShortID(ctx, req.ContainerId)
if err != nil {
return nil, fmt.Errorf("could not find container %s: %w", req.ContainerId, err)
}
if err := s.ContainerServer.Runtime().UpdateContainerStatus(ctx, c); err != nil {
return nil, err
}
cState := c.State()
if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) {
return nil, errors.New("container is not created or running")
}
if err := s.ContainerServer.Runtime().ReopenContainerLog(ctx, c); err != nil {
return nil, err
}
return &types.ReopenContainerLogResponse{}, nil
}