forked from kelseyhightower/confd
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
area: templateTemplate processingTemplate processingenhancementNew feature or requestNew feature or requestpriority: lowLow priority itemLow priority item
Description
Summary
Enable chaining multiple processing stages for templates: render → transform → validate → output.
Motivation
Complex configurations often require:
- Rendering a template, then formatting the output (e.g., JSON pretty-print)
- Merging multiple templates into a single output
- Post-processing with external tools (jsonnet, yq, envsubst)
- Validation before final output
Currently, this requires external scripting or wrapper tools.
Proposed Implementation
Pipeline Configuration
[template]
src = "config.json.tmpl"
dest = "/etc/app/config.json"
keys = ["/app/*"]
# New: processing pipeline
[[template.pipeline]]
stage = "render"
# Default stage, renders Go template
[[template.pipeline]]
stage = "transform"
cmd = "jq -S '.'" # Sort keys, pretty print
[[template.pipeline]]
stage = "validate"
cmd = "jq empty" # Validate JSON syntax
[[template.pipeline]]
stage = "transform"
cmd = "yq -P" # Convert to YAML (if needed)Built-in Stages
[[template.pipeline]]
stage = "format"
format = "json" # Pretty-print JSON
indent = 2
[[template.pipeline]]
stage = "format"
format = "yaml" # Convert to YAML
[[template.pipeline]]
stage = "minify"
format = "json" # Minify JSON output
[[template.pipeline]]
stage = "merge"
with = "/etc/confd/templates/defaults.json"
strategy = "deep" # deep | shallow | replaceTemplate Merging
Combine multiple templates or static files:
[template]
dest = "/etc/app/config.json"
[[template.sources]]
src = "base.json.tmpl"
keys = ["/app/base/*"]
[[template.sources]]
src = "overrides.json.tmpl"
keys = ["/app/overrides/*"]
[template.merge]
strategy = "deep" # Deep merge JSON objectsExternal Processors
[[template.pipeline]]
stage = "external"
cmd = "jsonnet"
args = ["-"] # Read from stdinPipeline Flow
┌──────────┐ ┌───────────┐ ┌──────────┐ ┌────────┐
│ Render │───▶│ Transform │───▶│ Validate │───▶│ Output │
└──────────┘ └───────────┘ └──────────┘ └────────┘
│ │ │ │
▼ ▼ ▼ ▼
Go template jq/yq/etc Check syntax Write file
Error Handling
- Pipeline stops on first error
- Validation failures prevent output
- Detailed error messages with stage info
- Rollback support (keep previous file on failure)
Use Cases
- JSON config with schema validation
- YAML generation from JSON templates
- Nginx config with syntax check (
nginx -t) - Kubernetes manifests with
kubectl --dry-run - Merged environment-specific configs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: templateTemplate processingTemplate processingenhancementNew feature or requestNew feature or requestpriority: lowLow priority itemLow priority item