Skip to content

Commit 89d4020

Browse files
committed
Cleanup unused code and static checks
Signed-off-by: Derek McGowan <[email protected]>
1 parent 931493b commit 89d4020

File tree

15 files changed

+173
-247
lines changed

15 files changed

+173
-247
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
strategy:
2525
matrix:
26-
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest]
26+
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest] # skipping windows-latest for now
2727
exclude:
2828
- os: ${{ github.event.repository.private && 'ubuntu-24.04-arm' || '' }}
2929

@@ -84,7 +84,7 @@ jobs:
8484
# Needed for proto lookup during generation
8585
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8686
with:
87-
repository: github.com/containerd/containerd
87+
repository: containerd/containerd
8888
path: src/github.com/containerd/containerd
8989

9090
- uses: ./src/github.com/containerd/nerdbox/.github/actions/install-go

.golangci.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- copyloopvar # Checks for loop variable copies in Go 1.22+
5+
- depguard # Checks for dependencies that should not be (re)introduced. See "settings" for further details.
6+
- dupword # Checks for duplicate words in the source code
7+
- gosec
8+
- misspell
9+
- nolintlint
10+
- revive
11+
- unconvert
12+
- usetesting
13+
disable:
14+
- errcheck
15+
settings:
16+
depguard:
17+
rules:
18+
main:
19+
deny:
20+
- pkg: github.com/opencontainers/runc
21+
desc: We don't want to depend on runc (libcontainer), unless there is no other option; see https://github.com/opencontainers/runc/issues/3028.
22+
gosec:
23+
# The following issues surfaced when `gosec` linter
24+
# was enabled. They are temporarily excluded to unblock
25+
# the existing workflow, but still to be addressed by
26+
# future works.
27+
excludes:
28+
- G204
29+
- G305
30+
- G306
31+
- G402
32+
- G404
33+
- G115
34+
- G103
35+
- G104
36+
- G301
37+
- G302
38+
- G304
39+
staticcheck:
40+
checks:
41+
- all
42+
- -QF1008 # Excludes QF1008 from staticcheck
43+
- -ST1000
44+
- -ST1003
45+
- -ST1020
46+
- -ST1021
47+
revive:
48+
rules:
49+
- name: package-comments
50+
severity: warning
51+
disabled: true
52+
exclude: [ "" ]
53+
nolintlint:
54+
allow-unused: true
55+
exclusions:
56+
generated: lax
57+
rules:
58+
- linters:
59+
- revive
60+
text: if-return
61+
- linters:
62+
- revive
63+
text: empty-block
64+
- linters:
65+
- revive
66+
text: superfluous-else
67+
- linters:
68+
- revive
69+
text: unused-parameter
70+
- linters:
71+
- revive
72+
text: unreachable-code
73+
- linters:
74+
- revive
75+
text: redefines-builtin-id
76+
paths:
77+
- api
78+
- docs
79+
- releases
80+
- test
81+
issues:
82+
max-issues-per-linter: 0
83+
max-same-issues: 0
84+
formatters:
85+
enable:
86+
- gofmt
87+
- goimports
88+
exclusions:
89+
generated: strict
90+
paths:
91+
- api
92+
- docs
93+
- releases
94+
- test

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $ make
3232
The results will be in the `_output` directory.
3333

3434
> #### macOS Tip
35-
>
35+
>
3636
> On macOS, use these commands:
3737
> ```
3838
> $ make KERNEL_ARCH=arm64 KERNEL_NPROC=12 KERNEL_VERSION=6.12.44
@@ -117,7 +117,7 @@ Install libkrun, erofs-utils, e2fsprogs on your host
117117
> #### macOS Tip
118118
>
119119
> Use brew to install libkrun, erofs-utils, and e2fsprogs
120-
>
120+
>
121121
> ```
122122
> brew tap slp/krunkit
123123
> brew install libkrun-efi erofs-utils e2fsprogs

cmd/vminitd/main.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,3 @@ func New(ctx context.Context, config ServiceConfig) (Runnable, error) {
359359
func (s *service) Run(ctx context.Context) error {
360360
return s.server.Serve(ctx, s.l)
361361
}
362-
363-
func newTTRPCServer() (*ttrpc.Server, error) {
364-
return ttrpc.NewServer(
365-
ttrpc.WithUnaryServerInterceptor(otelttrpc.UnaryServerInterceptor()),
366-
)
367-
}

docs/ctr-networking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Containers can be connected to networks the VM that have been defined via the
88
Each `io.containerd.nerdbox.ctr.network` annotation describes a single network
99
connection.
1010

11-
- `vmmac` (required): MAC address of the VM's interface, identifies the network.
11+
- `vmmac` (required): MAC address of the VM's interface, identifies the network.
1212
- `mac` (optional): A MAC address to assign to the container's network interface.
1313
- `addr` (optional, can be repeated): IP address with subnet mask (CIDR notation)
1414
for the container's interface.

internal/shim/task/io.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ import (
3434
"github.com/containerd/log"
3535
)
3636

37-
type processIO struct {
38-
//io runc.IO
39-
40-
uri *url.URL
41-
copy bool
42-
stdio stdio.Stdio
43-
}
44-
4537
type streamCreator interface {
4638
StartStream(ctx context.Context) (uint32, net.Conn, error)
4739
}

internal/shim/task/mount.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func transformMounts(ctx context.Context, vmi vm.Instance, id string, ms []*type
7272
disks++
7373
case "overlay", "format/overlay", "format/mkdir/overlay":
7474
var (
75-
wdi int = -1
76-
udi int = -1
75+
wdi = -1
76+
udi = -1
7777
)
7878
for i, opt := range m.Options {
7979
if strings.Contains(opt, "{{") {

internal/shim/task/service.go

Lines changed: 5 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
taskAPI "github.com/containerd/containerd/api/runtime/task/v3"
3131
"github.com/containerd/containerd/api/types"
32-
"github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/process"
3332
"github.com/containerd/containerd/v2/core/runtime"
3433
"github.com/containerd/containerd/v2/pkg/namespaces"
3534
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
@@ -59,7 +58,7 @@ func NewTaskService(ctx context.Context, vmm vm.Manager, publisher shim.Publishe
5958
s := &service{
6059
context: ctx,
6160
vmm: vmm,
62-
events: make(chan interface{}, 128),
61+
events: make(chan any, 128),
6362
containers: make(map[string]*container),
6463
initiateShutdown: sd.Shutdown,
6564
}
@@ -94,9 +93,8 @@ type service struct {
9493
// vm is the VM instance used to run the container
9594
vm vm.Instance
9695

97-
context context.Context
98-
events chan interface{}
99-
platform stdio.Platform
96+
context context.Context
97+
events chan any
10098

10199
containers map[string]*container
102100

@@ -138,11 +136,6 @@ func (s *service) shutdown(ctx context.Context) error {
138136
return errors.Join(errs...)
139137
}
140138

141-
type containerProcess struct {
142-
//Container *runc.Container
143-
Process process.Process
144-
}
145-
146139
// transformBindMounts transforms bind mounts
147140
func transformBindMounts(ctx context.Context, b *bundle.Bundle) error {
148141
for i, m := range b.Spec.Mounts {
@@ -292,8 +285,8 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
292285
return nil, errgrpc.ToGRPC(err)
293286
}
294287

295-
// setupTime is the total time to setup the VM and everything neeeded
296-
// to proxy the create task request. This measures the the overall
288+
// setupTime is the total time to setup the VM and everything needed
289+
// to proxy the create task request. This measures the overall
297290
// overhead of creating the container inside the VM.
298291
setupTime := time.Since(presetup)
299292

@@ -640,47 +633,6 @@ func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.
640633
return tc.Stats(ctx, r)
641634
}
642635

643-
/*
644-
func (s *service) processExits() {
645-
for e := range s.ec {
646-
// While unlikely, it is not impossible for a container process to exit
647-
// and have its PID be recycled for a new container process before we
648-
// have a chance to process the first exit. As we have no way to tell
649-
// for sure which of the processes the exit event corresponds to (until
650-
// pidfd support is implemented) there is no way for us to handle the
651-
// exit correctly in that case.
652-
653-
s.lifecycleMu.Lock()
654-
// Inform any concurrent s.Start() calls so they can handle the exit
655-
// if the PID belongs to them.
656-
for subscriber := range s.exitSubscribers {
657-
(*subscriber)[e.Pid] = append((*subscriber)[e.Pid], e)
658-
}
659-
// Handle the exit for a created/started process. If there's more than
660-
// one, assume they've all exited. One of them will be the correct
661-
// process.
662-
var cps []containerProcess
663-
for _, cp := range s.running[e.Pid] {
664-
_, init := cp.Process.(*process.Init)
665-
if init {
666-
s.containerInitExit[cp.Container] = e
667-
}
668-
cps = append(cps, cp)
669-
}
670-
delete(s.running, e.Pid)
671-
s.lifecycleMu.Unlock()
672-
673-
for _, cp := range cps {
674-
if ip, ok := cp.Process.(*process.Init); ok {
675-
s.handleInitExit(e, cp.Container, ip)
676-
} else {
677-
s.handleProcessExit(e, cp.Container, cp.Process)
678-
}
679-
}
680-
}
681-
}
682-
*/
683-
684636
func (s *service) send(evt interface{}) {
685637
s.events <- evt
686638
}
@@ -710,119 +662,3 @@ func (s *service) forward(ctx context.Context, publisher shim.Publisher) {
710662
log.G(ctx).WithField("event", e).Error("ignored event after shutdown")
711663
}
712664
}
713-
714-
/*
715-
// handleInitExit processes container init process exits.
716-
// This is handled separately from non-init exits, because there
717-
// are some extra invariants we want to ensure in this case, namely:
718-
// - for a given container, the init process exit MUST be the last exit published
719-
// This is achieved by:
720-
// - killing all running container processes (if the container has a shared pid
721-
// namespace, otherwise all other processes have been reaped already).
722-
// - waiting for the container's running exec counter to reach 0.
723-
// - finally, publishing the init exit.
724-
func (s *service) handleInitExit(e runcC.Exit, c *runc.Container, p *process.Init) {
725-
// kill all running container processes
726-
if runc.ShouldKillAllOnExit(s.context, c.Bundle) {
727-
if err := p.KillAll(s.context); err != nil {
728-
log.G(s.context).WithError(err).WithField("id", p.ID()).
729-
Error("failed to kill init's children")
730-
}
731-
}
732-
733-
s.lifecycleMu.Lock()
734-
numRunningExecs := s.runningExecs[c]
735-
if numRunningExecs == 0 {
736-
delete(s.runningExecs, c)
737-
s.lifecycleMu.Unlock()
738-
s.handleProcessExit(e, c, p)
739-
return
740-
}
741-
742-
events := make(chan int, numRunningExecs)
743-
s.execCountSubscribers[c] = events
744-
745-
s.lifecycleMu.Unlock()
746-
747-
go func() {
748-
defer func() {
749-
s.lifecycleMu.Lock()
750-
defer s.lifecycleMu.Unlock()
751-
delete(s.execCountSubscribers, c)
752-
delete(s.runningExecs, c)
753-
}()
754-
755-
// wait for running processes to exit
756-
for {
757-
if runningExecs := <-events; runningExecs == 0 {
758-
break
759-
}
760-
}
761-
762-
// all running processes have exited now, and no new
763-
// ones can start, so we can publish the init exit
764-
s.handleProcessExit(e, c, p)
765-
}()
766-
}
767-
768-
func (s *service) handleProcessExit(e runcC.Exit, c *runc.Container, p process.Process) {
769-
p.SetExited(e.Status)
770-
s.send(&eventstypes.TaskExit{
771-
ContainerID: c.ID,
772-
ID: p.ID(),
773-
Pid: uint32(e.Pid),
774-
ExitStatus: uint32(e.Status),
775-
ExitedAt: protobuf.ToTimestamp(p.ExitedAt()),
776-
})
777-
if _, init := p.(*process.Init); !init {
778-
s.lifecycleMu.Lock()
779-
s.runningExecs[c]--
780-
if ch, ok := s.execCountSubscribers[c]; ok {
781-
ch <- s.runningExecs[c]
782-
}
783-
s.lifecycleMu.Unlock()
784-
}
785-
}
786-
787-
func (s *service) getContainerPids(ctx context.Context, container *runc.Container) ([]uint32, error) {
788-
p, err := container.Process("")
789-
if err != nil {
790-
return nil, errgrpc.ToGRPC(err)
791-
}
792-
ps, err := p.(*process.Init).Runtime().Ps(ctx, container.ID)
793-
if err != nil {
794-
return nil, err
795-
}
796-
pids := make([]uint32, 0, len(ps))
797-
for _, pid := range ps {
798-
pids = append(pids, uint32(pid))
799-
}
800-
return pids, nil
801-
}
802-
803-
804-
func (s *service) getContainer(id string) (*runc.Container, error) {
805-
s.mu.Lock()
806-
container := s.containers[id]
807-
s.mu.Unlock()
808-
if container == nil {
809-
return nil, errgrpc.ToGRPCf(errdefs.ErrNotFound, "container not created")
810-
}
811-
return container, nil
812-
}
813-
814-
// initialize a single epoll fd to manage our consoles. `initPlatform` should
815-
// only be called once.
816-
func (s *service) initPlatform() error {
817-
if s.platform != nil {
818-
return nil
819-
}
820-
p, err := runc.NewPlatform()
821-
if err != nil {
822-
return err
823-
}
824-
s.platform = p
825-
s.shutdown.RegisterCallback(func(context.Context) error { return s.platform.Close() })
826-
return nil
827-
}
828-
*/

0 commit comments

Comments
 (0)