Skip to content

Commit b4c40b2

Browse files
Remove the use of go.uber.org/zap in entrypoint's dependent packages and uses log/slog
- This patch uses logging with the standard library instead of using zap to ensure that we are not pulling in too many indirect dependencies into the entrypoint through the uber-go/zap module Signed-off-by: PuneetPunamiya <[email protected]>
1 parent cef86d1 commit b4c40b2

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

pkg/entrypoint/entrypointer.go

+16-18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"errors"
2323
"fmt"
2424
"log"
25+
"log/slog"
2526
"os"
2627
"os/exec"
2728
"path/filepath"
@@ -42,7 +43,6 @@ import (
4243
"github.com/tektoncd/pipeline/pkg/termination"
4344

4445
"github.com/google/cel-go/cel"
45-
"go.uber.org/zap"
4646
)
4747

4848
// RFC3339 with millisecond
@@ -180,15 +180,11 @@ type PostWriter interface {
180180
// Go optionally waits for a file, runs the command, and writes a
181181
// post file.
182182
func (e Entrypointer) Go() error {
183-
prod, _ := zap.NewProduction()
184-
logger := prod.Sugar()
185-
186183
output := []result.RunResult{}
187184
defer func() {
188185
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)
190187
}
191-
_ = logger.Sync()
192188
}()
193189

194190
if err := os.MkdirAll(filepath.Join(e.StepMetadataDir, "results"), os.ModePerm); err != nil {
@@ -237,10 +233,10 @@ func (e Entrypointer) Go() error {
237233
var cancel context.CancelFunc
238234
if err == nil {
239235
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))
241237
}
242238
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))
244240
}
245241

246242
ctx, cancel = context.WithCancel(ctx)
@@ -251,7 +247,7 @@ func (e Entrypointer) Go() error {
251247
// start a goroutine to listen for cancellation file
252248
go func() {
253249
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))
255251
}
256252
}()
257253
allowExec, err1 := e.allowExec()
@@ -262,7 +258,7 @@ func (e Entrypointer) Go() error {
262258
case allowExec:
263259
err = e.Runner.Run(ctx, e.Command...)
264260
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.")
266262
output = append(output, e.outputRunResult(pod.TerminationReasonSkipped))
267263
e.WritePostFile(e.PostFile, nil)
268264
e.WriteExitCodeFile(e.StepMetadataDir, "0")
@@ -275,15 +271,15 @@ func (e Entrypointer) Go() error {
275271
case err != nil && errors.Is(err, errDebugBeforeStep):
276272
e.WritePostFile(e.PostFile, err)
277273
case err != nil && errors.Is(err, ErrContextCanceled):
278-
logger.Info("Step was canceling")
274+
slog.Info("Step was canceling")
279275
output = append(output, e.outputRunResult(pod.TerminationReasonCancelled))
280276
e.WritePostFile(e.PostFile, ErrContextCanceled)
281277
e.WriteExitCodeFile(e.StepMetadataDir, syscall.SIGKILL.String())
282278
case errors.Is(err, ErrContextDeadlineExceeded):
283279
e.WritePostFile(e.PostFile, err)
284280
output = append(output, e.outputRunResult(pod.TerminationReasonTimeoutExceeded))
285281
case err != nil && e.BreakpointOnFailure:
286-
logger.Info("Skipping writing to PostFile")
282+
slog.Info("Skipping writing to PostFile")
287283
case e.OnError == ContinueOnError && errors.As(err, &ee):
288284
// with continue on error and an ExitError, write non-zero exit code and a post file
289285
exitCode := strconv.Itoa(ee.ExitCode())
@@ -311,7 +307,9 @@ func (e Entrypointer) Go() error {
311307
resultPath = e.ResultsDirectory
312308
}
313309
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
315313
}
316314
}
317315
if len(e.StepResults) >= 1 && e.StepResults[0] != "" {
@@ -320,12 +318,12 @@ func (e Entrypointer) Go() error {
320318
stepResultPath = e.ResultsDirectory
321319
}
322320
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)
324322
}
325323
}
326324

327325
if e.ResultExtractionMethod == config.ResultExtractionMethodTerminationMessage {
328-
e.appendArtifactOutputs(&output, logger)
326+
e.appendArtifactOutputs(&output)
329327
}
330328

331329
return err
@@ -342,12 +340,12 @@ func readArtifacts(fp string, resultType result.ResultType) ([]result.RunResult,
342340
return []result.RunResult{{Key: fp, Value: string(file), ResultType: resultType}}, nil
343341
}
344342

345-
func (e Entrypointer) appendArtifactOutputs(output *[]result.RunResult, logger *zap.SugaredLogger) {
343+
func (e Entrypointer) appendArtifactOutputs(output *[]result.RunResult) {
346344
// step artifacts
347345
fp := filepath.Join(e.StepMetadataDir, "artifacts", "provenance.json")
348346
artifacts, err := readArtifacts(fp, result.StepArtifactsResultType)
349347
if err != nil {
350-
logger.Fatalf("Error while handling step artifacts: %s", err)
348+
log.Fatalf("Error while handling step artifacts: %s", err)
351349
}
352350
*output = append(*output, artifacts...)
353351

@@ -359,7 +357,7 @@ func (e Entrypointer) appendArtifactOutputs(output *[]result.RunResult, logger *
359357
fp = filepath.Join(artifactsDir, "provenance.json")
360358
artifacts, err = readArtifacts(fp, result.TaskRunArtifactsResultType)
361359
if err != nil {
362-
logger.Fatalf("Error while handling task artifacts: %s", err)
360+
log.Fatalf("Error while handling task artifacts: %s", err)
363361
}
364362
*output = append(*output, artifacts...)
365363
}

0 commit comments

Comments
 (0)