github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/cluster/calcium/hook.go (about) 1 package calcium 2 3 import ( 4 "bytes" 5 "context" 6 7 "github.com/projecteru2/core/engine" 8 ) 9 10 func (c *Calcium) doHook( 11 ctx context.Context, 12 ID, user string, 13 cmds, env []string, 14 cmdForce, privileged, force bool, 15 engine engine.API, 16 ) ([]*bytes.Buffer, error) { 17 outputs := []*bytes.Buffer{} 18 for _, cmd := range cmds { 19 output, err := c.execuateInside(ctx, engine, ID, cmd, user, env, privileged) 20 if err != nil { 21 // 执行 hook 的过程中,如果 cmdForce 为真并且不忽略 hook 就输出错误 22 outputs = append(outputs, bytes.NewBufferString(err.Error())) 23 if cmdForce && !force { 24 return outputs, err 25 } 26 continue 27 } 28 outputs = append(outputs, bytes.NewBuffer(output)) 29 } 30 return outputs, nil 31 }