@@ -38,7 +38,7 @@ const (
38
38
)
39
39
40
40
// NewContainerd creates a new containerd adapter
41
- func NewContainerd (cfg * ContainerdConfig , pathMapping PathMapping ) (* Containerd , error ) {
41
+ func NewContainerd (cfg * ContainerdConfig , pathMapping PathMapping , registryFacadeHost string ) (* Containerd , error ) {
42
42
cc , err := containerd .New (cfg .SocketPath , containerd .WithDefaultNamespace (kubernetesNamespace ))
43
43
if err != nil {
44
44
return nil , xerrors .Errorf ("cannot connect to containerd at %s: %w" , cfg .SocketPath , err )
@@ -58,6 +58,8 @@ func NewContainerd(cfg *ContainerdConfig, pathMapping PathMapping) (*Containerd,
58
58
cntIdx : make (map [string ]* containerInfo ),
59
59
podIdx : make (map [string ]* containerInfo ),
60
60
wsiIdx : make (map [string ]* containerInfo ),
61
+
62
+ registryFacadeHost : registryFacadeHost ,
61
63
}
62
64
go res .start ()
63
65
@@ -73,6 +75,8 @@ type Containerd struct {
73
75
podIdx map [string ]* containerInfo
74
76
wsiIdx map [string ]* containerInfo
75
77
cntIdx map [string ]* containerInfo
78
+
79
+ registryFacadeHost string
76
80
}
77
81
78
82
type containerInfo struct {
@@ -476,9 +480,31 @@ func (s *Containerd) ContainerPID(ctx context.Context, id ID) (pid uint64, err e
476
480
return uint64 (info .PID ), nil
477
481
}
478
482
479
- // ContainerPID returns the PID of the container's namespace root process, e.g. the container shim.
480
483
func (s * Containerd ) IsContainerdReady (ctx context.Context ) (bool , error ) {
481
- return s .Client .IsServing (ctx )
484
+ if len (s .registryFacadeHost ) == 0 {
485
+ return s .Client .IsServing (ctx )
486
+ }
487
+
488
+ // check registry facade can reach containerd and returns image not found.
489
+ isServing , err := s .Client .IsServing (ctx )
490
+ if err != nil {
491
+ return false , err
492
+ }
493
+
494
+ if ! isServing {
495
+ return false , nil
496
+ }
497
+
498
+ _ , err = s .Client .GetImage (ctx , fmt .Sprintf ("%v/not-a-valid-image:latest" , s .registryFacadeHost ))
499
+ if err != nil {
500
+ if errdefs .IsNotFound (err ) {
501
+ return true , nil
502
+ }
503
+
504
+ return false , nil
505
+ }
506
+
507
+ return true , nil
482
508
}
483
509
484
510
var kubepodsQoSRegexp = regexp .MustCompile (`([^/]+)-([^/]+)-pod` )
0 commit comments