Skip to content

Add a watcher flag to strip fields before storing - #1531

Open
cvas22 wants to merge 3 commits into
tektoncd:mainfrom
cvas22:feat/1368-strip-fields
Open

cvas22 wants to merge 3 commits into
tektoncd:mainfrom
cvas22:feat/1368-strip-fields

Conversation

@cvas22

@cvas22 cvas22 commented Nov 12, 2026

Copy link
Copy Markdown

Changes

Fixes #1368

Adds an opt-in --strip_fields flag to the watcher. It takes a comma-separated list of dot-separated paths, like metadata.managedFields,status.provenance, and removes them from PipelineRuns, TaskRuns and CustomRuns before they're stored. It's the same idea as the managedFields trimming in tektoncd/pipeline#9316, but here it saves DB space.

The stripping happens before the watcher compares the object with the stored record, so a change that only touches stripped fields (managedFields changes on every status update) doesn't cause an extra UpdateRecord. Paths only go through objects, not lists, and missing paths are ignored. apiVersion, kind, metadata.name, metadata.namespace and metadata.uid, or a parent like metadata, are rejected at startup since the record needs them. Numbers are decoded with UseNumber, so big integers keep their exact value.

I put it in the watcher instead of the API server so the fields aren't sent over the wire either. Happy to move it if you'd rather have it server side.

Tests: TestParseFieldPaths and TestStripFields cover parsing, the protected fields, nested and missing paths, lists and large numbers. TestUpsertRecordStripFields checks that the stored record has no managedFields and that a managedFields-only change doesn't update it. Docs are in docs/watcher/README.md.

/kind feature

Submitter Checklist

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Tested your changes locally
  • Follows the commit message standard
  • Meets the Tekton contributor standards
  • Has a kind label
  • Release notes block below has been updated with any user-facing changes
  • Release notes contain the string "action required" if the change requires additional action from users switching to the new release

Release Notes

The watcher has a new strip_fields flag that removes the listed fields, such as metadata.managedFields, from runs before they are stored.

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Nov 12, 2026
@tekton-robot
tekton-robot requested review from enarha and khrm November 12, 2026 00:07
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign vdemeester after the PR has been reviewed.
You can assign the PR to them by writing /assign @vdemeester in a comment when ready.

The full list of commands accepted by this bot can be found 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 12, 2026
@enarha
enarha requested a balanced review from Copilot November 17, 2026 09:19

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.

🟡 Changes recommended

The no-op comparison still triggers UpdateRecord for managedFields-only updates because resourceVersion also changes, and the new test omits that real-world behavior.

1 open issue
What changed in this PR

Adds opt-in field stripping to the watcher so archived Tekton runs use less database space and send smaller payloads to the Results API.

Changes:

  • Adds --strip_fields configuration with startup validation that protects object identity fields.
  • Removes configured fields before record comparison and storage, preserving numeric precision.
  • Adds parsing, stripping, and record-update tests, plus usage documentation.
File Description
pkg/​watcher/​results/​results.go Applies field stripping before record comparison and storage.
pkg/​watcher/​results/​results_test.go Tests stored field removal and unchanged-record behavior.
pkg/​watcher/​reconciler/​config.go Adds parsed field paths to watcher configuration.
pkg/​watcher/​convert/​strip.go Implements path validation and JSON field removal.
pkg/​watcher/​convert/​strip_test.go Tests parsing, protected fields, traversal, and numeric precision.
docs/​watcher/​README.md Documents flag usage, defaults, and limitations.
cmd/​watcher/​main.go Registers and validates the new watcher flag.

Review effort: Balanced

Comment on lines +375 to +378
if data != nil && len(c.StripFields) > 0 {
// Strip before comparing with the stored data, so that a change
// limited to stripped fields does not cause an update.
if data.Value, err = convert.StripFields(data.Value, c.StripFields); err != nil {

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.

Right, the resourceVersion bump makes it differ. I went with documenting that it has to be stripped too, and added a test for both cases, in 7c9e717.

Records store the whole run object, including fields such as
metadata.managedFields that are rarely useful in the archive but take a
lot of database space.

The new strip_fields flag takes a comma-separated list of dot-separated
field paths that the watcher removes from PipelineRuns, TaskRuns and
CustomRuns before storing them. The fields are stripped before the
comparison with the stored record, so a change limited to stripped
fields does not trigger an update. Fields that identify the object
cannot be stripped. The flag is empty by default, which keeps the
current behavior.

Fixes tektoncd#1368
…only updates

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 force-pushed the feat/1368-strip-fields branch from 7c9e717 to b463575 Compare November 17, 2026 23:36
@adityavshinde

Copy link
Copy Markdown
Contributor

@enarha - Keeping this in the watcher saves network traffic, but records created directly through the Results API will not be filtered. Is watcher-only behavior the intended scope of this feature, or should field stripping be enforced consistently for all Record writers by the API server?

@adityavshinde

Copy link
Copy Markdown
Contributor

Could the main documentation example include both metadata.managedFields and metadata.resourceVersion? Stripping only managedFields reduces storage, but Kubernetes still changes resourceVersion, so the watcher will continue updating the record.

@adityavshinde

Copy link
Copy Markdown
Contributor

How should users strip a specific annotation whose key contains dots, such as kubectl.kubernetes.io/last-applied-configuration? The current parser treats every dot as a path separator. Could escaping or JSON Pointer syntax be supported, or could this limitation be documented?

}

func deletePath(obj map[string]any, path []string) {
for _, key := range path[:len(path)-1] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could StripFields safely ignore or reject empty paths? It is an exported function, and passing something like [][]string{{}} can cause deletePath to panic. A simple length check would make it safer.

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.

Good catch, empty paths are skipped now in 1843522, with a test.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22

cvas22 commented Nov 27, 2026

Copy link
Copy Markdown
Author

Updated the README example to strip resourceVersion together with managedFields. For annotation keys with dots you can now escape them with a backslash, like metadata.annotations.kubectl\.kubernetes\.io/last-applied-configuration, also in 1843522.

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

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Add configurable list of fields to remove from object before storing and reduce DB storage use

4 participants