Skip to content
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

Simplify ws-daemon #18690

Merged
merged 1 commit into from
Sep 11, 2023
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
7 changes: 1 addition & 6 deletions components/ws-daemon/pkg/container/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ func FromConfig(cfg *Config) (rt Runtime, err error) {
return
}

mounts, err := NewNodeMountsLookup(&cfg.Mounts)
if err != nil {
return nil, err
}

switch cfg.Runtime {
case RuntimeContainerd:
if cfg.Containerd == nil {
return nil, xerrors.Errorf("runtime is set to containerd, but not containerd config is provided")
}
return NewContainerd(cfg.Containerd, mounts, cfg.Mapping)
return NewContainerd(cfg.Containerd, cfg.Mapping)
default:
return nil, xerrors.Errorf("unknown runtime type: %s", cfg.Runtime)
}
Expand Down
21 changes: 5 additions & 16 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, mounts *NodeMountsLookup, pathMapping PathMapping) (*Containerd, error) {
func NewContainerd(cfg *ContainerdConfig, pathMapping PathMapping) (*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 @@ -52,7 +52,6 @@ func NewContainerd(cfg *ContainerdConfig, mounts *NodeMountsLookup, pathMapping

res := &Containerd{
Client: cc,
Mounts: mounts,
Mapping: pathMapping,

cond: sync.NewCond(&sync.Mutex{}),
Expand All @@ -68,7 +67,6 @@ func NewContainerd(cfg *ContainerdConfig, mounts *NodeMountsLookup, pathMapping
// Containerd implements the ws-daemon CRI for containerd
type Containerd struct {
Client *containerd.Client
Mounts *NodeMountsLookup
Mapping PathMapping

cond *sync.Cond
Expand Down Expand Up @@ -440,27 +438,18 @@ func (s *Containerd) ContainerExists(ctx context.Context, id ID) (exists bool, e

// ContainerRootfs finds the workspace container's rootfs.
func (s *Containerd) ContainerRootfs(ctx context.Context, id ID, opts OptsContainerRootfs) (loc string, err error) {
info, ok := s.cntIdx[string(id)]
_, ok := s.cntIdx[string(id)]
if !ok {
return "", ErrNotFound
}

// TODO(cw): make this less brittle
// We can't get the rootfs location on the node from containerd somehow.
// As a workaround we'll look at the node's mount table using the snapshotter key.
// This feels brittle and we should keep looking for a better way.
mnt, err := s.Mounts.GetMountpoint(func(mountPoint string) bool {
return strings.Contains(mountPoint, info.SnapshotKey)
})
if err != nil {
return
}
rootfs := fmt.Sprintf("/run/containerd/io.containerd.runtime.v2.task/k8s.io/%v/rootfs", id)

if opts.Unmapped {
return mnt, nil
return rootfs, nil
}

return s.Mapping.Translate(mnt)
return s.Mapping.Translate(rootfs)
}

// ContainerCGroupPath finds the container's cgroup path suffix
Expand Down
91 changes: 0 additions & 91 deletions components/ws-daemon/pkg/container/mounts.go

This file was deleted.