Example #1
0
func (hr *HandlerRunner) Run(containerID kubecontainer.ContainerID, pod *api.Pod, container *api.Container, handler *api.Handler) (string, error) {
	switch {
	case handler.Exec != nil:
		var (
			buffer bytes.Buffer
			msg    string
		)
		output := ioutils.WriteCloserWrapper(&buffer)
		err := hr.commandRunner.ExecInContainer(containerID, handler.Exec.Command, nil, output, output, false)
		if err != nil {
			msg := fmt.Sprintf("Exec lifecycle hook (%v) for Container %q in Pod %q failed - %q", handler.Exec.Command, container.Name, format.Pod(pod), buffer.String())
			glog.V(1).Infof(msg)
		}
		return msg, err
	case handler.HTTPGet != nil:
		msg, err := hr.runHTTPHandler(pod, container, handler)
		if err != nil {
			msg := fmt.Sprintf("Http lifecycle hook (%s) for Container %q in Pod %q failed - %q", handler.HTTPGet.Path, container.Name, format.Pod(pod), msg)
			glog.V(1).Infof(msg)
		}
		return msg, err
	default:
		err := fmt.Errorf("Invalid handler: %v", handler)
		msg := fmt.Sprintf("Cannot run handler: %v", err)
		glog.Errorf(msg)
		return msg, err
	}
}
Example #2
0
func (p *prober) newExecInContainer(container api.Container, containerID kubecontainer.ContainerID, cmd []string) exec.Cmd {
	return execInContainer{func() ([]byte, error) {
		var buffer bytes.Buffer
		output := ioutils.WriteCloserWrapper(&buffer)
		err := p.runner.ExecInContainer(containerID, cmd, nil, output, output, false)
		if err != nil {
			return nil, err
		}

		return buffer.Bytes(), nil
	}}
}