Skip to content

feat: add a name to operations and keep the operation output in the report - #2774

Open
ergoz wants to merge 1 commit into
kyverno:mainfrom
ergoz:feat/report-operation-name-and-output
Open

ergoz wants to merge 1 commit into
kyverno:mainfrom
ergoz:feat/report-operation-name-and-output

Conversation

@ergoz

@ergoz ergoz commented Oct 23, 2026 •

Copy link
Copy Markdown

Explanation

This PR adds two things to the test report. This is an addition. Existing tests and existing report files stay valid.

  1. Each operation gets an optional name field. The report uses the name of an operation as its name. When an operation has no name, the report uses its description. When an operation has neither, the report uses operation <number>, as before. Before this PR, each operation in the report had the name operation <number>. Thus, a JUnit report with the JUNIT-OPERATION format showed my-step / operation 1, and the reader did not know which check failed.
  2. The report keeps the log of each operation. Before this PR, the log was only in the console output, and the JUnit reports had no system-out element. Thus, a tool that reads JUnit reports had no log of the operation. For example, Allure showed an empty test body, and the unit test report of GitLab CI got no system-out of the test case. GitLab CI reads the system-out element of a test case (see Unit test reports).

Related issue

There is no issue for this change.

Proposed Changes

  • OperationBase gets the optional field name. A step already has a name for the report and a description for the reader. With this PR, an operation has the same two fields.
  • runOperation gives the name of the operation to runAction: the name, else the description. runAction writes it to the operation report. When an operation has more than one resource, the name ends with the number of the resource, for example apply-resources (2/3).
  • A new function logging.WithRecorder writes each log entry to a writer as plain text without colors. It also sends the entry to the logger that was in the context before. Thus, the console output does not change.
  • runAction and the cleaner record the log of each operation that goes to the report. The new field OperationReport.Output keeps this log.
  • In the JUNIT-OPERATION format, the log of an operation goes to the system-out element of its test case.
  • In the JUNIT-STEP format, the logs of all operations of a step go to the system-out element of the step test case.
  • In the JSON format, the log of an operation goes to the new output field.
  • The documentation of the operations and of the reporting options tells about the name and the output.
  • make codegen updated the CRDs, the JSON schemas and the API reference for the new field.

Example. The step below:

- name: normal-kernel-panic
  try:
  - name: check-kernel-panic
    description: kernel.panic of the test node has the expected value
    assert:
      resource:
        apiVersion: v1
        kind: Pod
        metadata:
          name: e2e-kernel-panic-normal
        status:
          phase: Succeeded

Before this PR, JUNIT-OPERATION:

<testcase name="normal-kernel-panic / operation 1" classname="assert" time="3.213"></testcase>

After this PR:

<testcase name="normal-kernel-panic / check-kernel-panic" classname="assert" time="3.018">
  <system-out><![CDATA[ASSERT | RUN | v1/Pod @ chainsaw-ns/e2e-kernel-panic-normal
ASSERT | DONE | v1/Pod @ chainsaw-ns/e2e-kernel-panic-normal
]]></system-out>
</testcase>

Proof: a real run of a e2e test with the changed Chainsaw. The test has a name on each operation. The JUnit report has 91 test cases, and each of them has a system-out element. Part of the report (the namespace name is replaced):

<testcase name="normal-kernel-panic / check-kernel-panic" classname="assert" time="3.024693">
      <system-out><![CDATA[ASSERT | RUN | v1/Pod @ chainsaw-ns/e2e-kernel-panic-normal
ASSERT | DONE | v1/Pod @ chainsaw-ns/e2e-kernel-panic-normal
]]></system-out>
    </testcase>

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

This is not a bug fix. The PR adds unit tests for the new behavior:

  • pkg/logging/recorder_test.go: the recorder writes the entry without colors and sends it to the next logger. It also works when the context has no logger.
  • pkg/runner/operation_report_test.go: the report name of an operation is the name, else the description, else operation <number>, with the resource number when there is more than one resource. runOperation takes the name from the operation of the test. The operation report keeps the log of the operation.
  • pkg/cleanup/cleaner/cleaner_test.go: the operation report of a cleanup delete keeps the log of the delete.
  • pkg/report/output_test.go: the JUNIT-OPERATION, JUNIT-STEP and JSON reports contain the names and the output. An operation without output has no system-out element and no output field.

Further Comments

The operations of catch, finally and cleanup do not go to the report. This PR does not change that. They use runCatch, which gives no step report to runAction. It is possible to add them to the report in a different PR. For the same reason, the operations of catch and finally do not get the name field: they use the type CatchFinally, and their names do not go to a report.

The log in the report has no time stamps. The console output has them, and the report has the start time and the end time of each operation.

make codegen installs genref@latest. The current version of genref also changes parts of website/docs/reference/apis/ that this PR does not touch, for example the Clusters, Compiler and DefaultTimeouts sections of v1alpha2. The same change occurs when make codegen-api-docs runs on main. This PR keeps these generated changes, because make verify-codegen fails without them.

@ergoz
ergoz requested a review from a team as a code owner October 23, 2026 12:41
…eport

Signed-off-by: Sergey Morozov <sergey.morozov@flant.com>
@ergoz
ergoz force-pushed the feat/report-operation-name-and-output branch from dde9ad5 to e6f00e3 Compare October 23, 2026 12:44
@ergoz

ergoz commented Nov 22, 2026

Copy link
Copy Markdown
Author

Is there any chance to get review for this PR? :)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant