Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 73016ca

Browse files
authored
Merge pull request #491 from gao-feng/process
introduce api.Process
2 parents 078f160 + 6dfc45c commit 73016ca

File tree

4 files changed

+139
-75
lines changed

4 files changed

+139
-75
lines changed

api/descriptions.pb.go

Lines changed: 85 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/descriptions.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ message Rlimit {
9898
string type = 1;
9999
uint64 hard = 2;
100100
uint64 soft = 3;
101+
}
102+
103+
message Process {
104+
string Container = 1;
105+
string Id = 2;
106+
string User = 3;
107+
string Group = 4;
108+
repeated string AdditionalGroup = 5;
109+
bool Terminal = 6;
110+
repeated string Args = 7;
111+
repeated string Envs = 8;
112+
string Workdir = 9;
101113
}

hypervisor/vm.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,13 @@ func (vm *Vm) HyperstartExecSync(cmd []string, stdin []byte) (stdout, stderr []b
396396
return nil, nil, err
397397
}
398398

399-
err = vm.AddProcess(hyperstartapi.HYPERSTART_EXEC_CONTAINER, execId, false, cmd, []string{}, "/", tty)
399+
err = vm.AddProcess(&api.Process{
400+
Container: hyperstartapi.HYPERSTART_EXEC_CONTAINER,
401+
Id: execId,
402+
Terminal: false,
403+
Args: cmd,
404+
Envs: []string{},
405+
Workdir: "/"}, tty)
400406
if err != nil {
401407
return nil, nil, err
402408
}
@@ -435,7 +441,13 @@ func (vm *Vm) HyperstartExec(cmd string, tty *TtyIO) (int, error) {
435441
return -1, err
436442
}
437443

438-
err := vm.AddProcess(hyperstartapi.HYPERSTART_EXEC_CONTAINER, execID, false, command, []string{}, "/", tty)
444+
err := vm.AddProcess(&api.Process{
445+
Container: hyperstartapi.HYPERSTART_EXEC_CONTAINER,
446+
Id: execID,
447+
Terminal: false,
448+
Args: command,
449+
Envs: []string{},
450+
Workdir: "/"}, tty)
439451
if err != nil {
440452
return -1, err
441453
}
@@ -461,17 +473,23 @@ func (vm *Vm) Exec(container, execId, cmd string, terminal bool, tty *TtyIO) err
461473
if err := json.Unmarshal([]byte(cmd), &command); err != nil {
462474
return err
463475
}
464-
return vm.AddProcess(container, execId, terminal, command, []string{}, "/", tty)
476+
return vm.AddProcess(&api.Process{
477+
Container: container,
478+
Id: execId,
479+
Terminal: terminal,
480+
Args: command,
481+
Envs: []string{},
482+
Workdir: "/"}, tty)
465483
}
466484

467-
func (vm *Vm) AddProcess(container, execId string, terminal bool, args []string, env []string, workdir string, tty *TtyIO) error {
485+
func (vm *Vm) AddProcess(process *api.Process, tty *TtyIO) error {
468486
if !vm.ctx.IsRunning() {
469487
return NewNotReadyError(vm.Id)
470488
}
471489

472490
envs := []hyperstartapi.EnvironmentVar{}
473491

474-
for _, v := range env {
492+
for _, v := range process.Envs {
475493
if eqlIndex := strings.Index(v, "="); eqlIndex > 0 {
476494
envs = append(envs, hyperstartapi.EnvironmentVar{
477495
Env: v[:eqlIndex],
@@ -480,24 +498,26 @@ func (vm *Vm) AddProcess(container, execId string, terminal bool, args []string,
480498
}
481499
}
482500

483-
stdinPipe, stdoutPipe, stderrPipe, err := vm.ctx.hyperstart.AddProcess(container, &hyperstartapi.Process{
484-
Id: execId,
485-
Terminal: terminal,
486-
Args: args,
501+
stdinPipe, stdoutPipe, stderrPipe, err := vm.ctx.hyperstart.AddProcess(process.Container, &hyperstartapi.Process{
502+
Id: process.Id,
503+
Terminal: process.Terminal,
504+
Args: process.Args,
487505
Envs: envs,
488-
Workdir: workdir,
506+
Workdir: process.Workdir,
507+
User: process.User,
508+
Group: process.Group,
489509
})
490510

491511
if err != nil {
492-
return fmt.Errorf("exec command %v failed: %v", args, err)
512+
return fmt.Errorf("exec command %v failed: %v", process.Args, err)
493513
}
494514

495515
go streamCopy(tty, stdinPipe, stdoutPipe, stderrPipe)
496516
go func() {
497-
status := vm.ctx.hyperstart.WaitProcess(container, execId)
498-
vm.ctx.DeleteExec(execId)
517+
status := vm.ctx.hyperstart.WaitProcess(process.Container, process.Id)
518+
vm.ctx.DeleteExec(process.Id)
499519
vm.ctx.reportProcessFinished(types.E_EXEC_FINISHED, &types.ProcessFinished{
500-
Id: execId, Code: uint8(status), Ack: make(chan bool, 1),
520+
Id: process.Id, Code: uint8(status), Ack: make(chan bool, 1),
501521
})
502522
}()
503523
return nil

supervisor/container.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,14 @@ func (c *Container) addProcess(processId, stdin, stdout, stderr string, spec *sp
252252
)
253253
reschan := c.ownerPod.vm.WaitProcess(false, []string{processId}, -1)
254254

255-
err := c.ownerPod.vm.AddProcess(c.Id, processId, spec.Terminal, spec.Args, spec.Env, spec.Cwd, p.stdio)
255+
err := c.ownerPod.vm.AddProcess(&api.Process{
256+
Container: c.Id,
257+
Id: processId,
258+
Terminal: spec.Terminal,
259+
Args: spec.Args,
260+
Envs: spec.Env,
261+
Workdir: spec.Cwd}, p.stdio)
262+
256263
if err != nil {
257264
glog.V(1).Infof("add process to container failed: %v\n", err)
258265
} else {

0 commit comments

Comments
 (0)