Skip to content

Commit

Permalink
[ws-daemon] Change readiness behavior to wait for registry-facade (gi…
Browse files Browse the repository at this point in the history
…tpod-io#19661)

* [ws-daemon] Change readiness behavior to wait for registry-facade

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

Co-authored-by: Christian Weichel <[email protected]>

---------

Co-authored-by: Christian Weichel <[email protected]>
  • Loading branch information
aledbf and csweichel authored Apr 24, 2024
1 parent 7946ea6 commit a2a81e0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
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

0 comments on commit a2a81e0

Please sign in to comment.