circle-chevron-rightpatchesJSON6902

circle-info

• For similar examples, refer to the Kustomize documentation on patchesJSON6902arrow-up-right.

• Example files are available in the Kompozit GitHub repositoryarrow-up-right.

Kompozit supports JSON Patch (RFC 6902)arrow-up-right to modify resources in a flexible way. The jsonpatcharrow-up-right module is used internally in Kompozit to apply standard operations such as:

  • add: Adds a value to the specified path.

  • remove: Removes the value at the specified path.

  • replace: Replaces the value at the specified path.

This allows you to precisely control how resources are modified in your configurations.

For example, to replace the Docker image for the Traefik service, you can define the following patch in the kompozition file:

```yaml
---
resources:
  - ../../base

patchesJSON6902:
  - patch:
      - op: replace
        path: /services/traefik/image
        value: "traefik:v2"
```

Parameters:

  • op: The operation you want to perform. In this case, it’s replace.

  • path: The JSON path where you want to apply the operation.(Here, it’s /services/traefik/image).

  • value: The value to be used in the replace operation, such as "traefik:v2".

Result After Applying the Patch

Caveat

The patches defined in the kompozition file will be applied to all matching JSON paths across all resources. For example, if multiple docker-compose.yaml files define the same service name (e.g., traefik), the patch will be applied to all instances of that service, even across different files.

Last updated