fix(tektonconfig): keep prune-per-resource=false in spec - #3882
Merged
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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
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:
|
Contributor
|
/lgtm |
Member
|
/approve |
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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Fixes a bug where setting
spec.pruner.prune-per-resourcetofalseon aTektonConfigCR caused the field to disappear from the stored spec after being applied.The
PrunePerResourcefield was taggedjson:"prune-per-resource,omitempty". Since Go's zero value forboolisfalse,omitemptydropped the key whenever the value wasfalse. The operator's Knative-based mutating webhook computes a "round trip patch" before runningSetDefaults: it diffs the raw admission request bytes againstjson.Marshal(json.Unmarshal(bytes)), and any key that disappears in that round trip becomes a JSON Patch "remove" op applied to the admitted object (seevendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go,roundTripPatch). An explicitfalsewas therefore stripped from the persistedTektonConfigspec on every apply.Dropping
omitemptyfixes the round trip so the field survives. The existing+optionalmarker above the field keeps it optional in the generated CRD schema (confirmed no diff toconfig/base/generated-crdsor the Helm chart CRDs after regenerating withmake generate-crdsandhack/sync-helm-crds.sh).This only changes how the value is persisted: a missing key and an explicit
falsealready decoded to the same Go zero value everywherePrunePerResourceis 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:
make test lintbefore submitting a PRSee the contribution guide for more details.
Release Notes
AI assistance: this change was drafted with Claude Code.
Fixes #3202