Skip to content

feat(results): Add unit test for StatefulSet conversion and buckets auto-defaulting parity with Pipeline - #3918

Open
adityavshinde wants to merge 1 commit into
tektoncd:mainfrom
adityavshinde:SRVKP-13094/harden-HA-support
Open

feat(results): Add unit test for StatefulSet conversion and buckets auto-defaulting parity with Pipeline#3918
adityavshinde wants to merge 1 commit into
tektoncd:mainfrom
adityavshinde:SRVKP-13094/harden-HA-support

Conversation

@adityavshinde

@adityavshinde adityavshinde commented Aug 12, 2026

Copy link
Copy Markdown

Summary

For Part 1 of SRVKP-13094 refer this doc.
Hardens the existing Results watcher HA support (Part 2 of SRVKP-13094) by closing two gaps found during investigation:

  • Missing unit test for StatefulSet conversion (2.1): The Chains reconciler has TestUpdateStatefulSetOrdinalsForChains that exercises the full transform pipeline, but Results had no equivalent - the only coverage was an e2e test requiring a live cluster. Added TestUpdateStatefulSetOrdinalsForResults that builds a TektonResult CR with StatefulsetOrdinals=true, runs it through Reconciler.transform() (the production code path), and asserts the watcher Deployment becomes a StatefulSet with the correct serviceName, STATEFUL_CONTROLLER_ORDINAL (via fieldRef: metadata.name), and STATEFUL_SERVICE_NAME env vars.

  • Missing buckets/replicas auto-defaulting (2.2): Pipeline's tektonpipeline_defaults.go auto-sets Buckets = Replicas when StatefulsetOrdinals is enabled and Replicas > 1. Results had no equivalent, forcing users to manually set both fields to matching values or get a validation error. Added the same defaulting logic to Result.setPerformanceDefaults() and wired it into TektonResult.SetDefaults() for direct CR usage.

Changes

File What
pkg/reconciler/common/testdata/test-convert-result-deployment-to-statefulset.yaml New fixture YAML (mirrors Chain's equivalent)
pkg/reconciler/kubernetes/tektonresult/transform_test.go TestUpdateStatefulSetOrdinalsForResults - exercises Reconciler.transform() with CR-gated StatefulsetOrdinals check
pkg/apis/operator/v1alpha1/tektonresult_defaults.go setPerformanceDefaults() - auto-sets Buckets = Replicas when ordinals enabled; wired into SetDefaults()
pkg/apis/operator/v1alpha1/tektonresult_defaults_test.go 9 test cases: webhook-level defaulting + 6 sub-tests for buckets auto-defaulting coverage
docs/TektonResult.md Documents the new auto-defaulting behavior for buckets

Design decisions

  1. SetDefaults() only wires performance defaults, not route defaults. Previously TektonResult.SetDefaults() never called Result.setDefaults(). Calling the full setDefaults() would also trigger route defaults (RouteEnabled=true on OpenShift), which could change behavior for direct TektonResult CRs that previously left RouteEnabled unset. To avoid this out-of-scope side effect, only setPerformanceDefaults() is wired into SetDefaults(). Route defaults continue to fire through TektonConfig.SetDefaults() to Result.setDefaults(), which is the primary usage path.

  2. Chain has the same missing auto-defaulting. tektonchain_defaults.go has no equivalent buckets auto-defaulting either. This is intentionally left for a separate ticket to keep this PR focused on Results parity.

Known limitations

  • replicas=1 + statefulset-ordinals=true + no buckets set still results in a validation error. This matches Pipeline's behavior - auto-defaulting only fires for replicas > 1.
  • When buckets is explicitly set to a value different from replicas, the defaulting silently overrides it to match replicas. This is intentional parity with Pipeline.

Test plan

  • TestUpdateStatefulSetOrdinalsForResults - full Reconciler.transform() pipeline with StatefulsetOrdinals=true
  • TestTektonResult_SetDefaults - 3 sub-tests including buckets auto-defaulting on the webhook path
  • TestResult_SetDefaultsBucketsAutoDefaulting - 6 sub-tests:
    • ordinals=true, replicas=3, no buckets - buckets defaults to 3
    • ordinals=false - buckets not auto-set
    • ordinals=true, replicas=1 - buckets not auto-set
    • ordinals=nil - buckets not auto-set
    • ordinals=true, replicas=nil - buckets not auto-set (nil safety)
    • ordinals=true, replicas=3, buckets=5 - buckets overridden to 3 (parity with Pipeline)
  • All existing tests in both packages pass
  • gofmt and go vet clean

/kind feature

Release Note

Add buckets auto-defaulting for Results watcher when StatefulSet ordinals are enabled.

@tekton-robot tekton-robot added kind/feature Categorizes issue or PR as related to a new feature. release-note-none Denotes a PR that doesnt merit a release note. labels Aug 12, 2026
@tekton-robot
tekton-robot requested review from enarha and jkhelil August 12, 2026 09:07
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 26.34%. Comparing base (477cc0c) to head (8b85936).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3918      +/-   ##
==========================================
+ Coverage   26.14%   26.34%   +0.20%     
==========================================
  Files         465      465              
  Lines       24936    24947      +11     
==========================================
+ Hits         6519     6572      +53     
+ Misses      17697    17657      -40     
+ Partials      720      718       -2     
Flag Coverage Δ
unit-tests 26.34% <ø> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adityavshinde

adityavshinde commented Aug 12, 2026

Copy link
Copy Markdown
Author

/agentic_review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Tekton Results watcher HA support by adding (1) unit coverage for converting the watcher Deployment into a StatefulSet when statefulset-ordinals is enabled, and (2) defaulting logic so buckets automatically matches replicas (for replicas > 1) to mirror Tekton Pipeline behavior and avoid validation failures.

Changes:

  • Added a Results-specific unit test (and YAML fixture) that exercises the production Reconciler.transform() pipeline and asserts correct StatefulSet conversion + required env vars.
  • Implemented Results performance defaulting so buckets = replicas when statefulset-ordinals=true and replicas>1, and added unit tests for the new defaulting behavior.
  • Updated TektonResult documentation to describe the new buckets auto-defaulting behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/reconciler/kubernetes/tektonresult/transform_test.go Adds a new unit test validating watcher Deployment→StatefulSet conversion via transform().
pkg/reconciler/common/testdata/test-convert-result-deployment-to-statefulset.yaml New fixture manifest used by the StatefulSet conversion test.
pkg/apis/operator/v1alpha1/tektonresult_defaults.go Adds Results performance defaulting to auto-set buckets from replicas when ordinals are enabled.
pkg/apis/operator/v1alpha1/tektonresult_defaults_test.go Adds/extends defaulting tests to cover buckets auto-defaulting and override semantics.
docs/TektonResult.md Documents the new buckets auto-defaulting behavior for Results watcher performance config.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/TektonResult.md Outdated
Comment on lines +299 to +302
These fields are optional. If user passes them, operator will include most of fields into the deployment `tekton-results-watcher` under the container `watcher` as arguments(duplicate name? No, container and deployment has the same name), otherwise result watcher controller's default values will be considered. and `buckets` field is updated into `tekton-results-config-leader-election` config-map under the namespace `tekton-pipelines`.

* `disable-ha` - enable or disable ha feature, defaults in results watcher controller is `disable-ha=false`
* `buckets` - buckets is the number of buckets used to partition key space of each reconciler. If this number is M and the replica number of the controller is N, the N replicas will compete for the M buckets. The owner of a bucket will take care of the reconciling for the keys partitioned into that bucket. The maximum value of `buckets` at this time is `10`. default value in pipeline controller is `1`
* `buckets` - buckets is the number of buckets used to partition key space of each reconciler. If this number is M and the replica number of the controller is N, the N replicas will compete for the M buckets. The owner of a bucket will take care of the reconciling for the keys partitioned into that bucket. The maximum value of `buckets` at this time is `10`. default value in pipeline controller is `1`. When `statefulset-ordinals` is enabled and `replicas` is greater than 1, `buckets` is automatically defaulted to match `replicas` (consistent with Pipeline's behavior).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

…parity with Pipeline

Signed-off-by: Aditya Shinde <adishind@redhat.com>
@adityavshinde
adityavshinde force-pushed the SRVKP-13094/harden-HA-support branch from 9b40b52 to 8b85936 Compare August 13, 2026 07:52
@jkhelil

jkhelil commented Aug 13, 2026

Copy link
Copy Markdown
Member

@adityavshinde Add release note please

@adityavshinde

Copy link
Copy Markdown
Author

@adityavshinde Add release note please

Thank you, done.

@jkhelil

jkhelil commented Aug 13, 2026

Copy link
Copy Markdown
Member

/approve

@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jkhelil

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. release-note-none Denotes a PR that doesnt merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants