cmd Transform

Execute an external command and capture its stdout. Use this to integrate with tools like jsonnet, jq, yq, or any custom processor.

Usage

node:
  template:
    from_file: config.jsonnet
  config:
    to_file: config.json
    transform:
      cmd:
        - jsonnet
        - "{{.meta.template.path}}"

Behavior

  • The command is executed with the specified arguments
  • stdout is captured and parsed as YAML/JSON
  • The parsed data is then encoded to the output file format
  • stderr is captured and shown in error messages
  • Non-zero exit codes cause the transform to fail

Note: Command output must be valid YAML or JSON. This allows panconf to:

  1. Re-encode the output to different formats (JSON, YAML, TOML)
  2. Use the output as input for other nodes via {{.nodeName}}

Examples

Jsonnet

template.jsonnet:

{
  name: "app",
  port: 8080,
  replicas: std.parseInt(std.extVar("REPLICAS")),
}

panconf.yaml:

node:
  template:
    from_file: template.jsonnet
  config:
    to_file: config.json
    transform:
      cmd:
        - jsonnet
        - "{{.meta.template.path}}"

jq Processing

node:
  input:
    from_file: data.json
  filtered:
    to_file: filtered.json
    transform:
      cmd:
        - jq
        - ".items | map(select(.active))"
        - "{{.meta.input.path}}"

yq for YAML

node:
  input:
    from_file: data.yaml
  output:
    to_file: output.yaml
    transform:
      cmd:
        - yq
        - ".metadata.name = \"new-name\""
        - "{{.meta.input.path}}"

cat (Simple Pass-through)

transform:
  cmd:
    - cat
    - "{{.meta.source.path}}"

Shell Script

transform:
  cmd:
    - bash
    - "-c"
    - "cat {{.meta.base.path}} {{.meta.override.path}} | jq -s '.[0] * .[1]'"

Multiple Input Files

You can reference multiple inputs:

node:
  base:
    from_file: base.json
  overlay:
    from_file: overlay.json
  merged:
    to_file: merged.json
    transform:
      cmd:
        - jq
        - "-s"
        - ".[0] * .[1]"
        - "{{.meta.base.path}}"
        - "{{.meta.overlay.path}}"

With Environment Variables

Environment variables are expanded in the panconf config, and also available to the command:

node:
  template:
    from_file: template.jsonnet
  config:
    to_file: config.json
    transform:
      cmd:
        - bash
        - "-c"
        - "jsonnet --ext-str env=$ENVIRONMENT {{.meta.template.path}}"

Error Handling

When a command fails:

command failed: exit status 1 stderr: jq: error: syntax error, unexpected IDENT, expecting $end

The error includes:

  • Exit code
  • stderr output