@@ -53,6 +53,7 @@ const (
5353 containerTypeLabelSandbox = "sandbox"
5454 containerTypeLabelContainer = "container"
5555 sandboxIDLabelKey = "io.kubernetes.sandbox.id"
56+ containerLogPathLabelKey = "io.kubernetes.container.logpath"
5657
5758 // sandboxContainerName is a string to include in the pouch container so
5859 // that users can easily identify the sandboxes.
@@ -251,8 +252,7 @@ func (c *CriManager) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
251252 return nil , err
252253 }
253254 sandboxMeta := & SandboxMeta {
254- ID : id ,
255- ContainerLogMap : make (map [string ]string ),
255+ ID : id ,
256256 }
257257 if err := c .SandboxStore .Put (sandboxMeta ); err != nil {
258258 return nil , err
@@ -681,6 +681,12 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
681681 labels [containerTypeLabelKey ] = containerTypeLabelContainer
682682 // Write the sandbox ID in the labels.
683683 labels [sandboxIDLabelKey ] = podSandboxID
684+ // Get container log.
685+ var logPath string
686+ if config .GetLogPath () != "" {
687+ logPath = filepath .Join (sandboxConfig .GetLogDirectory (), config .GetLogPath ())
688+ labels [containerLogPathLabelKey ] = logPath
689+ }
684690
685691 image := ""
686692 if iSpec := config .GetImage (); iSpec != nil {
@@ -762,14 +768,7 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
762768 }
763769 }()
764770
765- // Get container log.
766- if config .GetLogPath () != "" {
767- logPath := filepath .Join (sandboxConfig .GetLogDirectory (), config .GetLogPath ())
768- sandboxMeta .ContainerLogMap [containerID ] = logPath
769- if err := c .SandboxStore .Put (sandboxMeta ); err != nil {
770- return nil , err
771- }
772-
771+ if logPath != "" {
773772 if err := c .ContainerMgr .AttachCRILog (ctx , containerID , logPath ); err != nil {
774773 return nil , err
775774 }
@@ -978,15 +977,7 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt
978977 imageRef = imageInfo .RepoDigests [0 ]
979978 }
980979
981- podSandboxID := container .Config .Labels [sandboxIDLabelKey ]
982- res , err := c .SandboxStore .Get (podSandboxID )
983- if err != nil {
984- return nil , fmt .Errorf ("failed to get metadata of %q from SandboxStore: %v" , podSandboxID , err )
985- }
986- sandboxMeta := res .(* SandboxMeta )
987- logDirectory := sandboxMeta .Config .GetLogDirectory ()
988- // TODO: let the container manager handle the log stuff for CRI.
989- logPath := makeupLogPath (logDirectory , metadata )
980+ logPath := labels [containerLogPathLabelKey ]
990981
991982 resources := container .HostConfig .Resources
992983 diskQuota := container .Config .DiskQuota
@@ -1142,23 +1133,9 @@ func (c *CriManager) ReopenContainerLog(ctx context.Context, r *runtime.ReopenCo
11421133 return nil , errors .Wrap (errtypes .ErrPreCheckFailed , "container is not running" )
11431134 }
11441135
1145- // get the container's podSandbox id.
1146- podSandboxID , ok := container .Config .Labels [sandboxIDLabelKey ]
1147- if ! ok {
1148- return nil , fmt .Errorf ("failed to get the sandboxId of container %q" , containerID )
1149- }
1150-
11511136 // get logPath of container
1152- res , err := c .SandboxStore .Get (podSandboxID )
1153- if err != nil {
1154- return nil , fmt .Errorf ("failed to get metadata of %q from SandboxStore: %v" , podSandboxID , err )
1155- }
1156- sandboxMeta , ok := res .(* SandboxMeta )
1157- if ! ok {
1158- return nil , fmt .Errorf ("failed to type asseration for sandboxMeta: %v" , res )
1159- }
1160- logPath , ok := sandboxMeta .ContainerLogMap [containerID ]
1161- if ! ok {
1137+ logPath := container .Config .Labels [containerLogPathLabelKey ]
1138+ if logPath == "" {
11621139 logrus .Warnf ("log path of container: %q is empty" , containerID )
11631140 return & runtime.ReopenContainerLogResponse {}, nil
11641141 }
0 commit comments