@@ -22,6 +22,7 @@ import (
22
22
"errors"
23
23
"fmt"
24
24
"log"
25
+ "log/slog"
25
26
"os"
26
27
"os/exec"
27
28
"path/filepath"
@@ -42,7 +43,6 @@ import (
42
43
"github.com/tektoncd/pipeline/pkg/termination"
43
44
44
45
"github.com/google/cel-go/cel"
45
- "go.uber.org/zap"
46
46
)
47
47
48
48
// RFC3339 with millisecond
@@ -180,15 +180,11 @@ type PostWriter interface {
180
180
// Go optionally waits for a file, runs the command, and writes a
181
181
// post file.
182
182
func (e Entrypointer ) Go () error {
183
- prod , _ := zap .NewProduction ()
184
- logger := prod .Sugar ()
185
-
186
183
output := []result.RunResult {}
187
184
defer func () {
188
185
if wErr := termination .WriteMessage (e .TerminationPath , output ); wErr != nil {
189
- logger .Fatalf ("Error while writing message: %s" , wErr )
186
+ log .Fatalf ("Error while writing message: %s" , wErr )
190
187
}
191
- _ = logger .Sync ()
192
188
}()
193
189
194
190
if err := os .MkdirAll (filepath .Join (e .StepMetadataDir , "results" ), os .ModePerm ); err != nil {
@@ -237,10 +233,10 @@ func (e Entrypointer) Go() error {
237
233
var cancel context.CancelFunc
238
234
if err == nil {
239
235
if err := e .applyStepResultSubstitutions (pipeline .StepsDir ); err != nil {
240
- logger .Error ("Error while substituting step results: " , err )
236
+ slog .Error ("Error while substituting step results: " , slog . Any ( "error" , err ) )
241
237
}
242
238
if err := e .applyStepArtifactSubstitutions (pipeline .StepsDir ); err != nil {
243
- logger .Error ("Error while substituting step artifacts: " , err )
239
+ slog .Error ("Error while substituting step artifacts: " , slog . Any ( "error" , err ) )
244
240
}
245
241
246
242
ctx , cancel = context .WithCancel (ctx )
@@ -251,7 +247,7 @@ func (e Entrypointer) Go() error {
251
247
// start a goroutine to listen for cancellation file
252
248
go func () {
253
249
if err := e .waitingCancellation (ctx , cancel ); err != nil && (! IsContextCanceledError (err ) && ! IsContextDeadlineError (err )) {
254
- logger .Error ("Error while waiting for cancellation" , zap . Error ( err ))
250
+ slog .Error ("Error while waiting for cancellation" , slog . Any ( "error" , err ))
255
251
}
256
252
}()
257
253
allowExec , err1 := e .allowExec ()
@@ -262,7 +258,7 @@ func (e Entrypointer) Go() error {
262
258
case allowExec :
263
259
err = e .Runner .Run (ctx , e .Command ... )
264
260
default :
265
- logger .Info ("Step was skipped due to when expressions were evaluated to false." )
261
+ slog .Info ("Step was skipped due to when expressions were evaluated to false." )
266
262
output = append (output , e .outputRunResult (pod .TerminationReasonSkipped ))
267
263
e .WritePostFile (e .PostFile , nil )
268
264
e .WriteExitCodeFile (e .StepMetadataDir , "0" )
@@ -275,15 +271,15 @@ func (e Entrypointer) Go() error {
275
271
case err != nil && errors .Is (err , errDebugBeforeStep ):
276
272
e .WritePostFile (e .PostFile , err )
277
273
case err != nil && errors .Is (err , ErrContextCanceled ):
278
- logger .Info ("Step was canceling" )
274
+ slog .Info ("Step was canceling" )
279
275
output = append (output , e .outputRunResult (pod .TerminationReasonCancelled ))
280
276
e .WritePostFile (e .PostFile , ErrContextCanceled )
281
277
e .WriteExitCodeFile (e .StepMetadataDir , syscall .SIGKILL .String ())
282
278
case errors .Is (err , ErrContextDeadlineExceeded ):
283
279
e .WritePostFile (e .PostFile , err )
284
280
output = append (output , e .outputRunResult (pod .TerminationReasonTimeoutExceeded ))
285
281
case err != nil && e .BreakpointOnFailure :
286
- logger .Info ("Skipping writing to PostFile" )
282
+ slog .Info ("Skipping writing to PostFile" )
287
283
case e .OnError == ContinueOnError && errors .As (err , & ee ):
288
284
// with continue on error and an ExitError, write non-zero exit code and a post file
289
285
exitCode := strconv .Itoa (ee .ExitCode ())
@@ -311,7 +307,9 @@ func (e Entrypointer) Go() error {
311
307
resultPath = e .ResultsDirectory
312
308
}
313
309
if err := e .readResultsFromDisk (ctx , resultPath , result .TaskRunResultType ); err != nil {
314
- logger .Fatalf ("Error while handling results: %s" , err )
310
+ // log.Fatalf("Error while handling results: %s", err)
311
+ slog .Error ("Error while substituting step artifacts: " , slog .Any ("error" , err ))
312
+ return err
315
313
}
316
314
}
317
315
if len (e .StepResults ) >= 1 && e .StepResults [0 ] != "" {
@@ -320,12 +318,12 @@ func (e Entrypointer) Go() error {
320
318
stepResultPath = e .ResultsDirectory
321
319
}
322
320
if err := e .readResultsFromDisk (ctx , stepResultPath , result .StepResultType ); err != nil {
323
- logger .Fatalf ("Error while handling step results: %s" , err )
321
+ log .Fatalf ("Error while handling step results: %s" , err )
324
322
}
325
323
}
326
324
327
325
if e .ResultExtractionMethod == config .ResultExtractionMethodTerminationMessage {
328
- e .appendArtifactOutputs (& output , logger )
326
+ e .appendArtifactOutputs (& output )
329
327
}
330
328
331
329
return err
@@ -342,12 +340,12 @@ func readArtifacts(fp string, resultType result.ResultType) ([]result.RunResult,
342
340
return []result.RunResult {{Key : fp , Value : string (file ), ResultType : resultType }}, nil
343
341
}
344
342
345
- func (e Entrypointer ) appendArtifactOutputs (output * []result.RunResult , logger * zap. SugaredLogger ) {
343
+ func (e Entrypointer ) appendArtifactOutputs (output * []result.RunResult ) {
346
344
// step artifacts
347
345
fp := filepath .Join (e .StepMetadataDir , "artifacts" , "provenance.json" )
348
346
artifacts , err := readArtifacts (fp , result .StepArtifactsResultType )
349
347
if err != nil {
350
- logger .Fatalf ("Error while handling step artifacts: %s" , err )
348
+ log .Fatalf ("Error while handling step artifacts: %s" , err )
351
349
}
352
350
* output = append (* output , artifacts ... )
353
351
@@ -359,7 +357,7 @@ func (e Entrypointer) appendArtifactOutputs(output *[]result.RunResult, logger *
359
357
fp = filepath .Join (artifactsDir , "provenance.json" )
360
358
artifacts , err = readArtifacts (fp , result .TaskRunArtifactsResultType )
361
359
if err != nil {
362
- logger .Fatalf ("Error while handling task artifacts: %s" , err )
360
+ log .Fatalf ("Error while handling task artifacts: %s" , err )
363
361
}
364
362
* output = append (* output , artifacts ... )
365
363
}
0 commit comments