@@ -3,20 +3,22 @@ package daemon
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "encoding/json"
6
7
"fmt"
7
8
"os"
8
9
"path/filepath"
9
10
"strconv"
10
11
"strings"
11
12
"time"
12
13
14
+ "github.com/containerd/containerd/namespaces"
13
15
criutil "github.com/containerd/cri/pkg/containerd/util"
14
- "github.com/rancher/k3c/pkg/defaults"
15
-
16
+ "github.com/containerd/cri/pkg/server"
16
17
"github.com/golang/protobuf/jsonpb"
17
18
"github.com/pkg/errors"
18
19
"github.com/rancher/k3c/pkg/client"
19
20
"github.com/rancher/k3c/pkg/daemon/volume"
21
+ "github.com/rancher/k3c/pkg/defaults"
20
22
"github.com/rancher/k3c/pkg/log"
21
23
"github.com/rancher/k3c/pkg/remote/apis/k3c/v1alpha1"
22
24
"github.com/sirupsen/logrus"
@@ -76,6 +78,7 @@ func (c *Daemon) LogContainer(ctx context.Context, containerID string, opts *v1.
76
78
opts = & v1.PodLogOptions {}
77
79
}
78
80
81
+ ctx = criutil .WithUnlisted (namespaces .WithNamespace (ctx , defaults .PublicNamespace ), defaults .PrivateNamespace )
79
82
_ , _ , containerID , err := c .GetContainer (ctx , containerID )
80
83
if err != nil {
81
84
return nil , err
@@ -483,10 +486,21 @@ func boolPointer(priv bool) *bool {
483
486
return nil
484
487
}
485
488
486
- func toContainer (mappings []* pb.PortMapping , volumes []v1.Volume , data * containerData ) ([]v1.Volume , v1.Container , error ) {
489
+ func ( c * Daemon ) toContainer (ctx context. Context , mappings []* pb.PortMapping , volumes []v1.Volume , data * containerData ) ([]v1.Volume , v1.Container , error ) {
487
490
containerConfig , _ , err := getContainerConfig (data .container )
488
491
if err != nil {
489
- return nil , v1.Container {}, err
492
+ var (
493
+ req = & pb.ContainerStatusRequest {ContainerId : data .container .Id , Verbose : true }
494
+ res * pb.ContainerStatusResponse
495
+ )
496
+ if res , err = c .crt .ContainerStatus (ctx , req ); err != nil {
497
+ return nil , v1.Container {}, err
498
+ }
499
+ var info server.ContainerInfo
500
+ if err = json .Unmarshal ([]byte (res .Info ["info" ]), & info ); err != nil {
501
+ return nil , v1.Container {}, err
502
+ }
503
+ containerConfig = info .Config
490
504
}
491
505
492
506
var (
@@ -510,10 +524,9 @@ func toContainer(mappings []*pb.PortMapping, volumes []v1.Volume, data *containe
510
524
}
511
525
ports = append (ports , cp )
512
526
}
513
-
514
- return volumes , v1.Container {
527
+ container := v1.Container {
515
528
Name : data .container .Metadata .Name ,
516
- Image : data .container .Image .Image ,
529
+ Image : data .status .Image .Image ,
517
530
Command : containerConfig .Command ,
518
531
Args : containerConfig .Args ,
519
532
WorkingDir : containerConfig .WorkingDir ,
@@ -541,7 +554,8 @@ func toContainer(mappings []*pb.PortMapping, volumes []v1.Volume, data *containe
541
554
Stdin : containerConfig .GetStdin (),
542
555
StdinOnce : containerConfig .GetStdinOnce (),
543
556
TTY : containerConfig .GetTty (),
544
- }, nil
557
+ }
558
+ return volumes , container , nil
545
559
}
546
560
547
561
func addMount (volumes []v1.Volume , mounts []v1.VolumeMount , mount * pb.Mount ) ([]v1.Volume , []v1.VolumeMount ) {
0 commit comments