Skip to content

Revert "Revert "[ws-daemon] Change readiness behavior to wait for registry-facade"" #19669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/ws-daemon/pkg/container/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
32 changes: 29 additions & 3 deletions components/ws-daemon/pkg/container/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -73,6 +75,8 @@ type Containerd struct {
podIdx map[string]*containerInfo
wsiIdx map[string]*containerInfo
cntIdx map[string]*containerInfo

registryFacadeHost string
}

type containerInfo struct {
Expand Down Expand Up @@ -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`)
Expand Down
2 changes: 2 additions & 0 deletions components/ws-daemon/pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions install/installer/pkg/components/ws-daemon/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading