diff --git a/examples/v1/pipelineruns/alpha/pipelinerun-large-results.yaml b/examples/v1/pipelineruns/alpha/pipelinerun-large-results.yaml index bd453b78a2e..031b0241012 100644 --- a/examples/v1/pipelineruns/alpha/pipelinerun-large-results.yaml +++ b/examples/v1/pipelineruns/alpha/pipelinerun-large-results.yaml @@ -7,39 +7,149 @@ spec: - name: result1 - name: result2 - name: result3 + type: array + description: The Array results - name: result4 - name: result5 + type: object + description: The object results + properties: + url: + type: string + digest: + type: string steps: - name: step1 image: alpine script: | - cat /dev/urandom | head -c 2500 | base64 | tee $(results.result1.path); - cat /dev/urandom | head -c 2500 | base64 | tee $(results.result2.path); - cat /dev/urandom | head -c 2500 | base64 | tee $(results.result3.path); - cat /dev/urandom | head -c 2500 | base64 | tee $(results.result4.path); - cat /dev/urandom | head -c 2500 | base64 | tee $(results.result5.path); + # produce a result - a random string with 2,500 characters - result1 + tr -dc A-Za-z0-9 maxResultLimit { - return runResult, ErrSizeExceeded - } - var res SidecarLogResult if err := json.Unmarshal(resultBytes, &res); err != nil { - return runResult, fmt.Errorf("Invalid result %w", err) + return runResult, fmt.Errorf("invalid result \"%s\": %w", res.Name, err) + } + if len(resultBytes) > maxResultLimit { + return runResult, fmt.Errorf("invalid result \"%s\": %w of %d", res.Name, ErrSizeExceeded, maxResultLimit) } runResult = result.RunResult{ Key: res.Name, diff --git a/internal/sidecarlogresults/sidecarlogresults_test.go b/internal/sidecarlogresults/sidecarlogresults_test.go index 9a5c85f1b42..7e078e26040 100644 --- a/internal/sidecarlogresults/sidecarlogresults_test.go +++ b/internal/sidecarlogresults/sidecarlogresults_test.go @@ -248,6 +248,7 @@ func TestParseResults(t *testing.T) { } func TestParseResults_Failure(t *testing.T) { + maxResultLimit := 4096 result := SidecarLogResult{ Name: "result2", Value: strings.Repeat("k", 4098), @@ -256,12 +257,12 @@ func TestParseResults_Failure(t *testing.T) { res2, _ := json.Marshal(&result) podLogs := []string{string(res1), string(res2)} want := []string{ - "Invalid result json: cannot unmarshal string into Go value of type sidecarlogresults.SidecarLogResult", - ErrSizeExceeded.Error(), + "invalid result \"\": json: cannot unmarshal string into Go value of type sidecarlogresults.SidecarLogResult", + fmt.Sprintf("invalid result \"%s\": %s of %d", result.Name, ErrSizeExceeded.Error(), maxResultLimit), } got := []string{} for _, plog := range podLogs { - _, err := parseResults([]byte(plog), 4096) + _, err := parseResults([]byte(plog), maxResultLimit) got = append(got, err.Error()) } if d := cmp.Diff(want, got); d != "" { diff --git a/pkg/pod/status_test.go b/pkg/pod/status_test.go index 59a701832f6..77c0176399a 100644 --- a/pkg/pod/status_test.go +++ b/pkg/pod/status_test.go @@ -125,7 +125,7 @@ func TestSetTaskRunStatusBasedOnStepStatus_sidecar_logs(t *testing.T) { }, { desc: "test result with sidecar logs bad format", maxResultSize: 4096, - wantErr: fmt.Errorf("%s", "Invalid result invalid character 'k' in literal false (expecting 'l')"), + wantErr: fmt.Errorf("%s", "invalid result \"\": invalid character 'k' in literal false (expecting 'l')"), }} { t.Run(c.desc, func(t *testing.T) { tr := v1.TaskRun{ diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index 76c0338e3cd..5a9a891fc2a 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -196,7 +196,7 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, tr *v1.TaskRun) pkgrecon logger.Errorf("Reconcile: %v", err.Error()) if errors.Is(err, sidecarlogresults.ErrSizeExceeded) { cfg := config.FromContextOrDefaults(ctx) - message := fmt.Sprintf("TaskRun %q failed: results exceeded size limit %d bytes", tr.Name, cfg.FeatureFlags.MaxResultSize) + message := fmt.Sprintf("TaskRun \"%q\" failed: results exceeded size limit %d bytes", tr.Name, cfg.FeatureFlags.MaxResultSize) err := c.failTaskRun(ctx, tr, v1.TaskRunReasonResultLargerThanAllowedLimit, message) return c.finishReconcileUpdateEmitEvents(ctx, tr, before, err) }