diff --git a/components/ws-daemon/pkg/container/config.go b/components/ws-daemon/pkg/container/config.go index d163fe84efcae2..7adfce8c33df15 100644 --- a/components/ws-daemon/pkg/container/config.go +++ b/components/ws-daemon/pkg/container/config.go @@ -35,6 +35,8 @@ type Config struct { // Containerd contains the containerd CRI config if runtime == RuntimeContainerd Containerd *ContainerdConfig `json:"containerd,omitempty"` + + RegistryFacadeHost string `json:"registryFacadeHost,omitempty"` } // RuntimeType lists the supported container runtimes @@ -63,7 +65,7 @@ func FromConfig(cfg *Config) (rt Runtime, err error) { if cfg.Containerd == nil { return nil, xerrors.Errorf("runtime is set to containerd, but not containerd config is provided") } - return NewContainerd(cfg.Containerd, cfg.Mapping) + return NewContainerd(cfg.Containerd, cfg.Mapping, cfg.RegistryFacadeHost) default: return nil, xerrors.Errorf("unknown runtime type: %s", cfg.Runtime) } diff --git a/components/ws-daemon/pkg/container/containerd.go b/components/ws-daemon/pkg/container/containerd.go index 21f55fbbe10449..a156068d86c0ba 100644 --- a/components/ws-daemon/pkg/container/containerd.go +++ b/components/ws-daemon/pkg/container/containerd.go @@ -38,7 +38,7 @@ const ( ) // NewContainerd creates a new containerd adapter -func NewContainerd(cfg *ContainerdConfig, pathMapping PathMapping) (*Containerd, error) { +func NewContainerd(cfg *ContainerdConfig, pathMapping PathMapping, registryFacadeHost string) (*Containerd, error) { cc, err := containerd.New(cfg.SocketPath, containerd.WithDefaultNamespace(kubernetesNamespace)) if err != nil { 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, cntIdx: make(map[string]*containerInfo), podIdx: make(map[string]*containerInfo), wsiIdx: make(map[string]*containerInfo), + + registryFacadeHost: registryFacadeHost, } go res.start() @@ -73,6 +75,8 @@ type Containerd struct { podIdx map[string]*containerInfo wsiIdx map[string]*containerInfo cntIdx map[string]*containerInfo + + registryFacadeHost string } type containerInfo struct { @@ -476,9 +480,31 @@ func (s *Containerd) ContainerPID(ctx context.Context, id ID) (pid uint64, err e return uint64(info.PID), nil } -// ContainerPID returns the PID of the container's namespace root process, e.g. the container shim. func (s *Containerd) IsContainerdReady(ctx context.Context) (bool, error) { - return s.Client.IsServing(ctx) + if len(s.registryFacadeHost) == 0 { + return s.Client.IsServing(ctx) + } + + // check registry facade can reach containerd and returns image not found. + isServing, err := s.Client.IsServing(ctx) + if err != nil { + return false, err + } + + if !isServing { + return false, nil + } + + _, err = s.Client.GetImage(ctx, fmt.Sprintf("%v/not-a-valid-image:latest", s.registryFacadeHost)) + if err != nil { + if errdefs.IsNotFound(err) { + return true, nil + } + + return false, nil + } + + return true, nil } var kubepodsQoSRegexp = regexp.MustCompile(`([^/]+)-([^/]+)-pod`) diff --git a/components/ws-daemon/pkg/daemon/config.go b/components/ws-daemon/pkg/daemon/config.go index cc749654dc7be1..300556f3b236a2 100644 --- a/components/ws-daemon/pkg/daemon/config.go +++ b/components/ws-daemon/pkg/daemon/config.go @@ -30,6 +30,8 @@ type Config struct { OOMScores cgroup.OOMScoreAdjConfig `json:"oomScores"` DiskSpaceGuard diskguard.Config `json:"disk"` WorkspaceController WorkspaceControllerConfig `json:"workspaceController"` + + RegistryFacadeHost string `json:"registryFacadeHost,omitempty"` } type WorkspaceControllerConfig struct { diff --git a/install/installer/pkg/components/ws-daemon/configmap.go b/install/installer/pkg/components/ws-daemon/configmap.go index bd61b3c26da50f..9aed82969a9621 100644 --- a/install/installer/pkg/components/ws-daemon/configmap.go +++ b/install/installer/pkg/components/ws-daemon/configmap.go @@ -113,6 +113,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { wsdcfg := wsdconfig.Config{ Daemon: daemon.Config{ + RegistryFacadeHost: fmt.Sprintf("reg.%s:%d", ctx.Config.Domain, common.RegistryFacadeServicePort), Runtime: daemon.RuntimeConfig{ KubernetesNamespace: ctx.Namespace, SecretsNamespace: common.WorkspaceSecretsNamespace,