fix(tektonconfig): keep prune-per-resource=false in spec - #3882
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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:
|
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