Prevent event-watcher JSON/HCL replacements from truncating files
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.4k
- Forks
- 364
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 84
Description
What happened:
The pipedv1 event watcher accepts jsonField and HCLField in an event replacement. When a matching event is handled, it does not modify that format; instead, it writes an empty byte slice to the configured file and commits the change. This truncates the JSON or HCL file to zero bytes.
commitFiles in pkg/app/pipedv1/eventwatcher/eventwatcher.go has empty jsonField and HCLField branches. After either branch, newContent is nil and upToDate is false, so the following os.WriteFile call overwrites the file with empty content.
What you expected to happen:
Either PipeCD should update only the configured JSON/HCL field with the event value, or it should reject the configuration/return an explicit unsupported-format error without changing the file. It must never truncate a repository file.
How to reproduce it:
-
Configure a pipedv1 Piped to watch the repository and create a repository file named
version.json:{"image":"example/app:1.0.0","keep":"this value"} -
Add an application configuration with an event watcher replacement using the documented
jsonFieldoption:apiVersion: pipecd.dev/v1beta1 kind: Application spec: name: event-watcher-repro plugins: kubernetes: {} eventWatcher: - matcher: name: image-update handler: type: GIT_UPDATE config: replacements: - file: version.json jsonField: $.image -
Register an
image-updateevent with dataexample/app:2.0.0and wait for the watcher to process it. -
Inspect the commit created by the event watcher.
version.jsonis empty (zero bytes), rather than containing the updatedimagevalue. -
Repeat with an HCL file and
HCLField; it follows the same empty branch and has the same truncation behavior.
Environment:
pipedversion: reproduced from source at3f7551c96(please replace with the released image/version used for the report, if applicable)control-planeversion: not version-specific; the faulty write is in the pipedv1 event-watcher code path- Others: pipedv1 application configuration; Git update event watcher handler; JSON or HCL replacement target
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pkg/app/pipedv1/eventwatcher/eventwatcher.go at commitFiles and inspect the empty jsonField and HCLField branches together with the following os.WriteFile call. Reproduce the JSON and HCL configurations described in the issue, then verify that each replacement either updates its configured field or returns an explicit unsupported-format error without truncating the file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100