This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push: new 9fccb36 Normalize the Spectrum log messages 9fccb36 is described below commit 9fccb36024c6de5298d89b6c1048a1d142620e2e Author: Otavio Rodolfo Piske <opi...@redhat.com> AuthorDate: Tue May 11 11:30:03 2021 +0200 Normalize the Spectrum log messages Fixes GH issue #2276 --- pkg/builder/spectrum.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go index beb5b25..c193607 100644 --- a/pkg/builder/spectrum.go +++ b/pkg/builder/spectrum.go @@ -18,16 +18,16 @@ limitations under the License. package builder import ( + "bufio" "context" + spectrum "github.com/container-tools/spectrum/pkg/builder" "io/ioutil" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "os" "path" "path/filepath" "strings" - spectrum "github.com/container-tools/spectrum/pkg/builder" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/client" "github.com/apache/camel-k/pkg/util/log" @@ -83,6 +83,15 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus { defer os.RemoveAll(registryConfigDir) } + newStdR, newStdW, pipeErr := os.Pipe() + defer newStdW.Close() + + if pipeErr != nil { + // In the unlikely case of an error, use stdout instead of aborting + log.Errorf(pipeErr, "Unable to remap I/O. Spectrum messages will be displayed on the stdout") + newStdW = os.Stdout + } + options := spectrum.Options{ PullInsecure: pullInsecure, PushInsecure: t.task.Registry.Insecure, @@ -90,12 +99,14 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus { PushConfigDir: registryConfigDir, Base: baseImage, Target: t.task.Image, - Stdout: os.Stdout, - Stderr: os.Stderr, + Stdout: newStdW, + Stderr: newStdW, Recursive: true, } + go readSpectrumLogs(newStdR) digest, err := spectrum.Build(options, libraryPath+":"+path.Join(DeploymentDir, DependenciesDir)) + if err != nil { return status.Failed(err) } @@ -106,6 +117,15 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus { return status } +func readSpectrumLogs(newStdOut *os.File) { + scanner := bufio.NewScanner(newStdOut) + + for scanner.Scan() { + line := scanner.Text() + log.Infof(line) + } +} + func mountSecret(ctx context.Context, c client.Client, namespace, name string) (string, error) { dir, err := ioutil.TempDir("", "spectrum-secret-") if err != nil {