iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🍣

Escaping Special Characters in PipeCD EventWatcher Replacements

に公開1件

Introduction

This article is about the EventWatcher feature of the deployment tool PipeCD.

https://pipecd.dev/

PipeCD's EventWatcher feature allows it to detect changes in manifests and trigger deployments.
This enables changes made in CI to be communicated to the CD side.

https://pipecd.dev/docs-v0.48.x/user-guide/event-watcher/

To replace values in a PipeCD application manifest, you can specify which file and which field to replace using spec.eventWatcher[].handler.config.replacements[].

A typical use case is when updating the image value of a Deployment, as shown below.

apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
  name: helloworld
  eventWatcher:
    - matcher:
        name: helloworld-image-update
      handler:
        type: GIT_UPDATE
        config:
          replacements:
            - file: deployment.yaml
              yamlField: $.spec.template.spec.containers[0].image

Issues

The issue encountered this time occurred when updating a Deployment as follows to update the version for each deployment in Datadog.
An error occurs if you specify a path containing . or / directly in yamlField.

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: xxx
  name: xxx
  labels:
    tags.datadoghq.com/env: dev
    tags.datadoghq.com/service: xxx
-   tags.datadoghq.com/version: v0.0.0
+   tags.datadoghq.com/version: v0.0.1

Solution

When specifying a path that includes . or / in yamlField, it must be written as follows.
You can perform escaping simply by enclosing the segment in '.

yamlField: $.metadata.labels.'tags.datadoghq.com/version'

Discussion

ren510devren510dev

記事のタイトルが PipeCDD になってますね 😇