feat(results): Add unit test for StatefulSet conversion and buckets auto-defaulting parity with Pipeline - #3918
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/agentic_review |
There was a problem hiding this comment.
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 = replicaswhenstatefulset-ordinals=trueandreplicas>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.
| 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). |
…parity with Pipeline Signed-off-by: Aditya Shinde <adishind@redhat.com>
9b40b52 to
8b85936
Compare
|
@adityavshinde Add release note please |
Thank you, done. |
|
/approve |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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
TestUpdateStatefulSetOrdinalsForChainsthat exercises the full transform pipeline, but Results had no equivalent - the only coverage was an e2e test requiring a live cluster. AddedTestUpdateStatefulSetOrdinalsForResultsthat builds aTektonResultCR withStatefulsetOrdinals=true, runs it throughReconciler.transform()(the production code path), and asserts the watcher Deployment becomes a StatefulSet with the correctserviceName,STATEFUL_CONTROLLER_ORDINAL(viafieldRef: metadata.name), andSTATEFUL_SERVICE_NAMEenv vars.Missing buckets/replicas auto-defaulting (2.2): Pipeline's
tektonpipeline_defaults.goauto-setsBuckets = ReplicaswhenStatefulsetOrdinalsis enabled andReplicas > 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 toResult.setPerformanceDefaults()and wired it intoTektonResult.SetDefaults()for direct CR usage.Changes
pkg/reconciler/common/testdata/test-convert-result-deployment-to-statefulset.yamlpkg/reconciler/kubernetes/tektonresult/transform_test.goTestUpdateStatefulSetOrdinalsForResults- exercisesReconciler.transform()with CR-gatedStatefulsetOrdinalscheckpkg/apis/operator/v1alpha1/tektonresult_defaults.gosetPerformanceDefaults()- auto-setsBuckets = Replicaswhen ordinals enabled; wired intoSetDefaults()pkg/apis/operator/v1alpha1/tektonresult_defaults_test.godocs/TektonResult.mdbucketsDesign decisions
SetDefaults()only wires performance defaults, not route defaults. PreviouslyTektonResult.SetDefaults()never calledResult.setDefaults(). Calling the fullsetDefaults()would also trigger route defaults (RouteEnabled=trueon OpenShift), which could change behavior for directTektonResultCRs that previously leftRouteEnabledunset. To avoid this out-of-scope side effect, onlysetPerformanceDefaults()is wired intoSetDefaults(). Route defaults continue to fire throughTektonConfig.SetDefaults()toResult.setDefaults(), which is the primary usage path.Chain has the same missing auto-defaulting.
tektonchain_defaults.gohas 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+ nobucketsset still results in a validation error. This matches Pipeline's behavior - auto-defaulting only fires forreplicas > 1.bucketsis explicitly set to a value different fromreplicas, the defaulting silently overrides it to matchreplicas. This is intentional parity with Pipeline.Test plan
TestUpdateStatefulSetOrdinalsForResults- fullReconciler.transform()pipeline withStatefulsetOrdinals=trueTestTektonResult_SetDefaults- 3 sub-tests including buckets auto-defaulting on the webhook pathTestResult_SetDefaultsBucketsAutoDefaulting- 6 sub-tests:ordinals=true, replicas=3, no buckets- buckets defaults to 3ordinals=false- buckets not auto-setordinals=true, replicas=1- buckets not auto-setordinals=nil- buckets not auto-setordinals=true, replicas=nil- buckets not auto-set (nil safety)ordinals=true, replicas=3, buckets=5- buckets overridden to 3 (parity with Pipeline)gofmtandgo vetclean/kind feature
Release Note