pipe-cd / pipe-cd/pipecd

Prevent event-watcher JSON/HCL replacements from truncating files

Open
#7,394 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug
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:

  1. 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"}
    
  2. Add an application configuration with an event watcher replacement using the documented jsonField option:

    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
    
  3. Register an image-update event with data example/app:2.0.0 and wait for the watcher to process it.

  4. Inspect the commit created by the event watcher. version.json is empty (zero bytes), rather than containing the updated image value.

  5. Repeat with an HCL file and HCLField; it follows the same empty branch and has the same truncation behavior.

Environment:

  • piped version: reproduced from source at 3f7551c96 (please replace with the released image/version used for the report, if applicable)
  • control-plane version: 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.