Skip to content

Commit e84ffc6

Browse files
authored
Revert "Revert "[ws-daemon] Change readiness behavior to wait for registry-fa…" (#19669)
This reverts commit 8838eb9.
1 parent 8838eb9 commit e84ffc6

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

components/ws-daemon/pkg/container/config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type Config struct {
3535

3636
// Containerd contains the containerd CRI config if runtime == RuntimeContainerd
3737
Containerd *ContainerdConfig `json:"containerd,omitempty"`
38+
39+
RegistryFacadeHost string `json:"registryFacadeHost,omitempty"`
3840
}
3941

4042
// RuntimeType lists the supported container runtimes
@@ -63,7 +65,7 @@ func FromConfig(cfg *Config) (rt Runtime, err error) {
6365
if cfg.Containerd == nil {
6466
return nil, xerrors.Errorf("runtime is set to containerd, but not containerd config is provided")
6567
}
66-
return NewContainerd(cfg.Containerd, cfg.Mapping)
68+
return NewContainerd(cfg.Containerd, cfg.Mapping, cfg.RegistryFacadeHost)
6769
default:
6870
return nil, xerrors.Errorf("unknown runtime type: %s", cfg.Runtime)
6971
}

components/ws-daemon/pkg/container/containerd.go

+29-3
Original file line numberDiff line numberDiff line change
@@ -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

7882
type 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.
480483
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
482508
}
483509

484510
var kubepodsQoSRegexp = regexp.MustCompile(`([^/]+)-([^/]+)-pod`)

components/ws-daemon/pkg/daemon/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type Config struct {
3030
OOMScores cgroup.OOMScoreAdjConfig `json:"oomScores"`
3131
DiskSpaceGuard diskguard.Config `json:"disk"`
3232
WorkspaceController WorkspaceControllerConfig `json:"workspaceController"`
33+
34+
RegistryFacadeHost string `json:"registryFacadeHost,omitempty"`
3335
}
3436

3537
type WorkspaceControllerConfig struct {

install/installer/pkg/components/ws-daemon/configmap.go

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
113113

114114
wsdcfg := wsdconfig.Config{
115115
Daemon: daemon.Config{
116+
RegistryFacadeHost: fmt.Sprintf("reg.%s:%d", ctx.Config.Domain, common.RegistryFacadeServicePort),
116117
Runtime: daemon.RuntimeConfig{
117118
KubernetesNamespace: ctx.Namespace,
118119
SecretsNamespace: common.WorkspaceSecretsNamespace,

0 commit comments

Comments
 (0)