@@ -38,7 +38,7 @@ const (
3838)
3939
4040// 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 ) {
4242 cc , err := containerd .New (cfg .SocketPath , containerd .WithDefaultNamespace (kubernetesNamespace ))
4343 if err != nil {
4444 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,
5858 cntIdx : make (map [string ]* containerInfo ),
5959 podIdx : make (map [string ]* containerInfo ),
6060 wsiIdx : make (map [string ]* containerInfo ),
61+
62+ registryFacadeHost : registryFacadeHost ,
6163 }
6264 go res .start ()
6365
@@ -73,6 +75,8 @@ type Containerd struct {
7375 podIdx map [string ]* containerInfo
7476 wsiIdx map [string ]* containerInfo
7577 cntIdx map [string ]* containerInfo
78+
79+ registryFacadeHost string
7680}
7781
7882type containerInfo struct {
@@ -476,9 +480,31 @@ func (s *Containerd) ContainerPID(ctx context.Context, id ID) (pid uint64, err e
476480 return uint64 (info .PID ), nil
477481}
478482
479- // ContainerPID returns the PID of the container's namespace root process, e.g. the container shim.
480483func (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
482508}
483509
484510var kubepodsQoSRegexp = regexp .MustCompile (`([^/]+)-([^/]+)-pod` )
0 commit comments