Verified Commit 9e07b069 authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Extend debug logging for k8s executor

parent a2c4246a
......@@ -147,6 +147,8 @@ func (b *Build) StartBuild(rootDir, cacheDir string, sharedDir bool) {
func (b *Build) executeStage(ctx context.Context, buildStage BuildStage, executor Executor) error {
b.CurrentStage = buildStage
b.Log().WithField("build_stage", buildStage).Debug("Executing build stage")
shell := executor.Shell()
if shell == nil {
return errors.New("No shell defined")
......
......@@ -23,9 +23,10 @@ import (
"io"
"net/url"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
api "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
restclient "k8s.io/client-go/rest"
......@@ -45,6 +46,15 @@ func (*DefaultRemoteExecutor) Execute(method string, url *url.URL, config *restc
if err != nil {
return err
}
runtime.ErrorHandlers = append(runtime.ErrorHandlers, func(err error) {
logrus.WithError(err).Error("K8S stream error")
})
runtime.PanicHandlers = append(runtime.PanicHandlers, func(r interface{}) {
logrus.Errorf("K8S stream panic: %v", r)
})
return exec.Stream(remotecommand.StreamOptions{
Stdin: stdin,
Stdout: stdout,
......@@ -84,7 +94,7 @@ func (p *ExecOptions) Run() error {
containerName := p.ContainerName
if len(containerName) == 0 {
log.Infof("defaulting container name to '%s'", pod.Spec.Containers[0].Name)
logrus.Infof("defaulting container name to '%s'", pod.Spec.Containers[0].Name)
containerName = pod.Spec.Containers[0].Name
}
......
......@@ -143,8 +143,16 @@ func (s *executor) Run(cmd common.ExecutorCommand) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s.Debugln(fmt.Sprintf(
"Starting in container %q the command %q with script: %s",
containerName,
containerCommand,
cmd.Script,
))
select {
case err := <-s.runInContainer(ctx, containerName, containerCommand, cmd.Script):
s.Debugln(fmt.Sprintf("Container %q exited with error: %v", containerName, err))
if err != nil && strings.Contains(err.Error(), "command terminated with exit code") {
return &common.BuildError{Inner: err}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment