X Tutup
Skip to content

Commit 4eb27a5

Browse files
author
mYmNeo
committed
let user to specify the shim name or path
Signed-off-by: mYmNeo <thomassong@tencent.com>
1 parent 5e5daf2 commit 4eb27a5

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

containerd/main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ var daemonFlags = []cli.Flag{
4848
cli.StringFlag{
4949
Name: "runtime,r",
5050
Value: "runc",
51-
Usage: "name of the OCI compliant runtime to use when executing containers",
51+
Usage: "name or path of the OCI compliant runtime to use when executing containers",
5252
},
5353
cli.StringSliceFlag{
5454
Name: "runtime-args",
5555
Value: &cli.StringSlice{},
5656
Usage: "specify additional runtime args",
5757
},
58+
cli.StringFlag{
59+
Name: "shim",
60+
Value: "containerd-shim",
61+
Usage: "Name or path of shim",
62+
},
5863
cli.StringFlag{
5964
Name: "pprof-address",
6065
Usage: "http address to listen for pprof events",
@@ -86,6 +91,7 @@ func main() {
8691
10,
8792
context.String("runtime"),
8893
context.StringSlice("runtime-args"),
94+
context.String("shim"),
8995
context.Duration("start-timeout"),
9096
); err != nil {
9197
logrus.Fatal(err)
@@ -96,15 +102,15 @@ func main() {
96102
}
97103
}
98104

99-
func daemon(address, stateDir string, concurrency int, runtimeName string, runtimeArgs []string, timeout time.Duration) error {
105+
func daemon(address, stateDir string, concurrency int, runtimeName string, runtimeArgs []string, shimName string, timeout time.Duration) error {
100106
// setup a standard reaper so that we don't leave any zombies if we are still alive
101107
// this is just good practice because we are spawning new processes
102108
s := make(chan os.Signal, 2048)
103109
signal.Notify(s, syscall.SIGCHLD, syscall.SIGTERM, syscall.SIGINT)
104110
if err := osutils.SetSubreaper(1); err != nil {
105111
logrus.WithField("error", err).Error("containerd: set subpreaper")
106112
}
107-
sv, err := supervisor.New(stateDir, runtimeName, runtimeArgs, timeout)
113+
sv, err := supervisor.New(stateDir, runtimeName, shimName, runtimeArgs, timeout)
108114
if err != nil {
109115
return err
110116
}

runtime/container.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type ContainerOpts struct {
8989
Bundle string
9090
Runtime string
9191
RuntimeArgs []string
92+
Shim string
9293
Labels []string
9394
NoPivotRoot bool
9495
Timeout time.Duration
@@ -104,6 +105,7 @@ func New(opts ContainerOpts) (Container, error) {
104105
processes: make(map[string]*process),
105106
runtime: opts.Runtime,
106107
runtimeArgs: opts.RuntimeArgs,
108+
shim: opts.Shim,
107109
noPivotRoot: opts.NoPivotRoot,
108110
timeout: opts.Timeout,
109111
}
@@ -144,6 +146,7 @@ func Load(root, id string) (Container, error) {
144146
labels: s.Labels,
145147
runtime: s.Runtime,
146148
runtimeArgs: s.RuntimeArgs,
149+
shim: s.Shim,
147150
noPivotRoot: s.NoPivotRoot,
148151
processes: make(map[string]*process),
149152
}
@@ -190,6 +193,7 @@ type container struct {
190193
bundle string
191194
runtime string
192195
runtimeArgs []string
196+
shim string
193197
processes map[string]*process
194198
labels []string
195199
oomFds []int

runtime/container_linux.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
ocs "github.com/opencontainers/specs/specs-go"
1818
)
1919

20-
var shimBinary = os.Args[0] + "-shim"
21-
2220
func getRootIDs(s *specs.Spec) (int, int, error) {
2321
if s == nil {
2422
return 0, 0, nil
@@ -145,7 +143,7 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
145143
if err := os.Mkdir(processRoot, 0755); err != nil {
146144
return nil, err
147145
}
148-
cmd := exec.Command(shimBinary,
146+
cmd := exec.Command(c.shim,
149147
c.id, c.bundle, c.runtime,
150148
)
151149
cmd.Dir = processRoot
@@ -185,7 +183,7 @@ func (c *container) Exec(pid string, pspec specs.ProcessSpec, s Stdio) (pp Proce
185183
c.RemoveProcess(pid)
186184
}
187185
}()
188-
cmd := exec.Command(shimBinary,
186+
cmd := exec.Command(c.shim,
189187
c.id, c.bundle, c.runtime,
190188
)
191189
cmd.Dir = processRoot
@@ -219,7 +217,7 @@ func (c *container) startCmd(pid string, cmd *exec.Cmd, p *process) error {
219217
if err := cmd.Start(); err != nil {
220218
if exErr, ok := err.(*exec.Error); ok {
221219
if exErr.Err == exec.ErrNotFound || exErr.Err == os.ErrNotExist {
222-
return fmt.Errorf("%s not installed on system", shimBinary)
220+
return fmt.Errorf("%s not installed on system", c.shim)
223221
}
224222
}
225223
return err

runtime/runtime.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type state struct {
6161
Stderr string `json:"stderr"`
6262
Runtime string `json:"runtime"`
6363
RuntimeArgs []string `json:"runtimeArgs"`
64+
Shim string `json:"shim"`
6465
NoPivotRoot bool `json:"noPivotRoot"`
6566
}
6667

supervisor/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func (s *Supervisor) start(t *StartTask) error {
2727
Bundle: t.BundlePath,
2828
Runtime: s.runtime,
2929
RuntimeArgs: s.runtimeArgs,
30+
Shim: s.shim,
3031
Labels: t.Labels,
3132
NoPivotRoot: t.NoPivotRoot,
3233
Timeout: s.timeout,

supervisor/supervisor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
)
1919

2020
// New returns an initialized Process supervisor.
21-
func New(stateDir string, runtimeName string, runtimeArgs []string, timeout time.Duration) (*Supervisor, error) {
21+
func New(stateDir string, runtimeName, shimName string, runtimeArgs []string, timeout time.Duration) (*Supervisor, error) {
2222
startTasks := make(chan *startTask, 10)
2323
if err := os.MkdirAll(stateDir, 0755); err != nil {
2424
return nil, err
@@ -41,6 +41,7 @@ func New(stateDir string, runtimeName string, runtimeArgs []string, timeout time
4141
monitor: monitor,
4242
runtime: runtimeName,
4343
runtimeArgs: runtimeArgs,
44+
shim: shimName,
4445
timeout: timeout,
4546
}
4647
if err := setupEventLog(s); err != nil {
@@ -109,6 +110,7 @@ type Supervisor struct {
109110
// name of the OCI compatible runtime used to execute containers
110111
runtime string
111112
runtimeArgs []string
113+
shim string
112114
containers map[string]*containerInfo
113115
startTasks chan *startTask
114116
// we need a lock around the subscribers map only because additions and deletions from

0 commit comments

Comments
 (0)
X Tutup