Skip to content

Commit cd7dc44

Browse files
authored
Simplify ws-daemon (#18690)
1 parent 3771afc commit cd7dc44

File tree

3 files changed

+6
-113
lines changed

3 files changed

+6
-113
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,12 @@ func FromConfig(cfg *Config) (rt Runtime, err error) {
5858
return
5959
}
6060

61-
mounts, err := NewNodeMountsLookup(&cfg.Mounts)
62-
if err != nil {
63-
return nil, err
64-
}
65-
6661
switch cfg.Runtime {
6762
case RuntimeContainerd:
6863
if cfg.Containerd == nil {
6964
return nil, xerrors.Errorf("runtime is set to containerd, but not containerd config is provided")
7065
}
71-
return NewContainerd(cfg.Containerd, mounts, cfg.Mapping)
66+
return NewContainerd(cfg.Containerd, cfg.Mapping)
7267
default:
7368
return nil, xerrors.Errorf("unknown runtime type: %s", cfg.Runtime)
7469
}

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

Lines changed: 5 additions & 16 deletions
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, mounts *NodeMountsLookup, pathMapping PathMapping) (*Containerd, error) {
41+
func NewContainerd(cfg *ContainerdConfig, pathMapping PathMapping) (*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)
@@ -52,7 +52,6 @@ func NewContainerd(cfg *ContainerdConfig, mounts *NodeMountsLookup, pathMapping
5252

5353
res := &Containerd{
5454
Client: cc,
55-
Mounts: mounts,
5655
Mapping: pathMapping,
5756

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

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

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

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

459448
if opts.Unmapped {
460-
return mnt, nil
449+
return rootfs, nil
461450
}
462451

463-
return s.Mapping.Translate(mnt)
452+
return s.Mapping.Translate(rootfs)
464453
}
465454

466455
// ContainerCGroupPath finds the container's cgroup path suffix

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

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)