fix(pruner): ensure enforcedConfigLevel is always defaulted and DeepCopy is correct#3688
Conversation
…opy is correct The SetDefaults change in commit 774867c guarded GlobalConfig.SetDefaults() behind a nil check to allow users to set historyLimit to null without it resetting. However, this meant enforcedConfigLevel was never filled in when a user provided a partial global-config (e.g. only ttlSecondsAfterFinished). The pruner controller then defaulted to the "resource" level internally, which silently ignores all namespace-level selector rules. Additionally, DeepCopyInto for TektonPrunerConfig copied the *GlobalConfig pointer instead of the underlying struct. This caused the Knative defaulting webhook to see no difference between the original and the copy after SetDefaults ran, so the patch was always null and defaults were never applied. Signed-off-by: Shubham Bhardwaj <shubbhar@redhat.com>
d949c0c to
f718bcf
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3688 +/- ##
==========================================
- Coverage 24.49% 24.48% -0.01%
==========================================
Files 470 470
Lines 24919 24924 +5
==========================================
- Hits 6103 6102 -1
- Misses 18122 18126 +4
- Partials 694 696 +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:
|
|
/retest |
|
@infernus01 did we verify the impact on upgrade due to this change? |
|
@anithapriyanatarajan There can be 4 cases for the upgrade scenario: Case 2: User explicitly set enforcedConfigLevel: global Case 3: User never set enforcedConfigLevel, but old operator (<=v0.78.1) filled it in Case 4: User never set enforcedConfigLevel, running v0.79.1+ where it was silently dropped Without explicitly setting enforcedConfigLevel. The broken SetDefaults never filled it in, so it's missing from the ConfigMap. The pruner's fallback is resource level, which happens to check globalSpec.Namespaces["dev"] and finds TTL=30. And this I haven't yet verified will work or not. But after this fix, enforcedConfigLevel: global is filled in and at global level, the pruner only uses root-level settings. The |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pramodbindal 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 |
Changes
enforcedConfigLevelsilently vanishing from the pruner global configwhen a user provides a partial
global-config(e.g. onlyttlSecondsAfterFinished)DeepCopyIntoshallow copy bug that prevented the defaulting webhookfrom detecting changes made by
SetDefaultsProblem
When a user provides any
global-configfield without explicitly settingenforcedConfigLevel, the v0.79.1SetDefaultsskips defaulting entirelybecause
GlobalConfigis non-nil. Combined withomitemptystruct tags inthe vendored pruner,
enforcedConfigLevelis omitted from the ConfigMap.The pruner controller then falls back to the internal default (
resourcelevel), which never consults namespace-level ConfigMaps — all selector-based
pruning rules silently stop working.
On top of this,
DeepCopyIntoforTektonPrunerConfigdoes*out = *in,which copies the
*GlobalConfigpointer instead of the struct. The Knativedefaulting webhook deep-copies the object before calling
SetDefaults, thencompares it with the original to generate a patch. Because both copies share
the same pointer, the webhook always sees no difference (
PatchBytes: null)and never applies the defaults.
Root Cause
Commit 774867c changed
GlobalConfigfrom a value type to a pointer andguarded
SetDefaults()withif p.GlobalConfig == nilto preventhistoryLimitfrom resetting to 100 when set to null. The side effect wasthat
enforcedConfigLevelwas never filled in for partial configs. Theexisting
DeepCopyIntowas not updated for the pointer type change.Fix
tektonpruner_defaults.go: Always fill inenforcedConfigLevelwhennil, without touching other fields:
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