Skip to content

fix(tektonconfig): keep prune-per-resource=false in spec - #3882

Open
pujitha24 wants to merge 1 commit into
tektoncd:mainfrom
pujitha24:auto/issue-3202
Open

fix(tektonconfig): keep prune-per-resource=false in spec#3882
pujitha24 wants to merge 1 commit into
tektoncd:mainfrom
pujitha24:auto/issue-3202

Conversation

@pujitha24

Copy link
Copy Markdown
Contributor

Changes

Fixes a bug where setting spec.pruner.prune-per-resource to false on a TektonConfig CR caused the field to disappear from the stored spec after being applied.

The PrunePerResource field was tagged json:"prune-per-resource,omitempty". Since Go's zero value for bool is false, omitempty dropped the key whenever the value was false. The operator's Knative-based mutating webhook computes a "round trip patch" before running SetDefaults: it diffs the raw admission request bytes against json.Marshal(json.Unmarshal(bytes)), and any key that disappears in that round trip becomes a JSON Patch "remove" op applied to the admitted object (see vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go, roundTripPatch). An explicit false was therefore stripped from the persisted TektonConfig spec on every apply.

Dropping omitempty fixes the round trip so the field survives. The existing +optional marker above the field keeps it optional in the generated CRD schema (confirmed no diff to config/base/generated-crds or the Helm chart CRDs after regenerating with make generate-crds and hack/sync-helm-crds.sh).

This only changes how the value is persisted: a missing key and an explicit false already decoded to the same Go zero value everywhere PrunePerResource is read (pkg/reconciler/common/prune.go), so there is no separate pruning behavior change beyond the field no longer vanishing from the spec.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Release Notes

Fixed a bug where setting `spec.pruner.prune-per-resource: false` on a `TektonConfig` CR was dropped from the stored spec after being applied.

AI assistance: this change was drafted with Claude Code.

Fixes #3202

Motivation: setting spec.pruner.prune-per-resource to false on a
TektonConfig CR caused the field to disappear from the stored spec
after being applied (visible via kubectl get -o yaml).

Approach: PrunePerResource was tagged
`json:"prune-per-resource,omitempty"`. Go's zero value for bool is
false, so omitempty drops the key whenever the value is false. The
operator's Knative-based mutating webhook computes a "round trip
patch" before running SetDefaults: it diffs the raw admission
request bytes against json.Marshal(json.Unmarshal(bytes)), and any
key that disappears in that round trip becomes a JSON Patch "remove"
op applied to the admitted object (see
vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go,
roundTripPatch). An explicit false is therefore stripped from the
persisted TektonConfig spec on every apply. Dropping omitempty fixes
the round trip so the field survives. The existing +optional marker
above the field keeps it optional in the generated CRD schema
(confirmed: no diff to config/base/generated-crds or the Helm chart
CRDs after regenerating with make generate-crds and
hack/sync-helm-crds.sh).

Note this only changes how the value is persisted: a missing key and
an explicit false already decoded to the same Go zero value
everywhere PrunePerResource is read (pkg/reconciler/common/prune.go),
so there is no separate pruning behavior change beyond the field no
longer vanishing from the spec.

Validation: go build ./...; go test ./... (all packages pass, no
failures); go vet ./pkg/apis/operator/v1alpha1/...; golangci-lint
run ./pkg/apis/operator/v1alpha1/... --modules-download-mode=vendor
(0 issues, run via a manually installed golangci-lint v2.12.2 since
`make lint-go` could not download its pinned binary in this
sandbox). Added TestPrune_PrunePerResourceJSONRoundTrip in
tektonconfig_types_test.go; confirmed it fails with the old
omitempty tag and passes with the fix.

Report: tektoncd#3202
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Aug 9, 2026
@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 enarha after the PR has been reviewed.
You can assign the PR to them by writing /assign @enarha 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 9, 2026
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 26.13%. Comparing base (e18041d) to head (50715f2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3882   +/-   ##
=======================================
  Coverage   26.13%   26.13%           
=======================================
  Files         465      465           
  Lines       24930    24930           
=======================================
  Hits         6516     6516           
  Misses      17694    17694           
  Partials      720      720           
Flag Coverage Δ
unit-tests 26.13% <ø> (ø)

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.

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

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TektonConfig Pruner - prune-per-resource = false, removed when applied

2 participants