fix(pipelinesascode): guard nil Settings in validate - #4065
Conversation
Disabling PipelinesAsCode in TektonConfig, via either
platforms.<kubernetes|openshift>.pipelinesAsCode.enable: false or the
deprecated addon.enablePipelinesAsCode: false, is rejected by the
validating webhook, which panics with "assignment to entry in nil
map" on every attempt. Because the whole object is rejected, this
also blocks unrelated TektonConfig field updates while the disable is
requested.
SetDefaults nils out PACSettings.Settings on the disable path (both
the Kubernetes and OpenShift branches in tektonconfig_defaults.go),
but (*PACSettings).validate unconditionally forwards ps.Settings into
the vendored pipelines-as-code SyncConfig, which writes into that map
unconditionally in getHubCatalogs (default.go:21). A nil map panics
on write.
Guard ps.Settings to an empty map before calling SyncConfig, in
(*PACSettings).validate. This is the single method used by both the
OpenShiftPipelinesAsCode.Validate and TektonConfig.Validate
(Kubernetes and OpenShift branches) entry points, so one guard covers
all three call sites; no other caller of SyncConfig or
PACSettings.validate was found unguarded.
Added TestValidateNilSettings, which reproduces the exact panic
reported in the issue (PACSettings{Settings: nil} through
OpenShiftPipelinesAsCode.Validate) before the fix, and passes after
it. Verified by temporarily reverting only the guard: the test panics
with the same stack (getHubCatalogs -> SyncConfig ->
PACSettings.validate -> OpenShiftPipelinesAsCode.Validate) reported in
the issue; with the guard restored it passes.
Validation:
- go test ./pkg/apis/operator/v1alpha1/... (pass)
- go test -race ./pkg/apis/operator/v1alpha1/... (pass)
- go build ./pkg/apis/... (pass)
- make lint-go PKG=./pkg/apis/operator/v1alpha1/... (0 issues)
- gofmt -l on changed files (clean)
- No API types changed, so codegen is unaffected and was not run.
- A full-repo `go build ./...` could not be completed locally: this
sandbox has very little free disk space, unrelated to this change,
and the build exhausts it while compiling large unrelated
dependency trees. The affected package builds, vets, and tests
cleanly in isolation.
Report: tektoncd#4057
Assisted-by: Claude Sonnet 5
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 #4065 +/- ##
=======================================
Coverage 26.70% 26.71%
=======================================
Files 465 465
Lines 25010 25012 +2
=======================================
+ Hits 6679 6681 +2
Misses 17601 17601
Partials 730 730
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:
|
theakshaypant
left a comment
There was a problem hiding this comment.
@pujitha24 Were you able to verify the nil panic is no longer happening on a live deployment?
Unrelated to the changes, what is a mutex in Go, and when would you use one?
|
No, I haven't run this against a live deployment. What I verified is the regression test ( On the mutex question: |
theakshaypant
left a comment
There was a problem hiding this comment.
@pujitha24 Would be very helpful if you can perform the check deploying your changes, maybe even on kind.
Additionally, can you provide an inline review of the changes in this PR?
Changes
Fix a validating-webhook panic ("assignment to entry in nil map") that is
triggered whenever
TektonConfig.Spec.Platforms.{Kubernetes,OpenShift}.PipelinesAsCodeis disabled, via either
pipelinesAsCode.enable: falseor the deprecatedspec.addon.enablePipelinesAsCode: false.SetDefaultssetsPACSettings.Settingstonilon the disable path (bothplatform branches), but
(*PACSettings).validateunconditionally passesps.Settingsinto the vendoredpipelines-as-codeSyncConfig, whichwrites into that map unconditionally (
getHubCatalogs,default.go:21).A nil map panics on write.
The fix guards
ps.Settingsto an empty map before callingSyncConfig,in
(*PACSettings).validate— the single method used by both theOpenShiftPipelinesAsCode.ValidateandTektonConfig.Validate(Kubernetesand OpenShift branches) entry points, so one guard covers all three call
sites.
A regression test reproduces the exact panic reported in the issue
(
PACSettings{Settings: nil}throughOpenShiftPipelinesAsCode.Validate)and asserts it now returns cleanly.
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 #4057