-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Description
Summary
Add support for Helm's fail function in Go template rendering when generating Helm values and policyRefs configurations.
Motivation
Currently, when using Go templates in Sveltos for generating Helm values or policyRefs, there's no way to explicitly fail the rendering process with a custom error message when validation fails or inconsistent states are detected.
The Helm fail function documentation allows template authors to:
- Provide clear, actionable error messages when validation fails
- Prevent deployment in inconsistent or invalid states
- Improve observability by making configuration errors explicit rather than allowing silent failures or unexpected behavior
Proposed Solution
Add the fail function to the available template functions in Sveltos' Go template engine, similar to how Helm provides it.
Use Case Example
{{- if not .Cluster.metadata.labels.environment }}
{{- fail "Cluster must have 'environment' label defined" }}
{{- end }}
{{- if and (eq .Cluster.metadata.labels.environment "production") (not .Cluster.metadata.labels.backup) }}
{{- fail "Production clusters must have 'backup' label set to 'true'" }}
{{- end }}Benefits
- Better error messages: Provide context-specific error messages that help operators quickly identify and fix configuration issues
- Improved observability: Make validation failures explicit and traceable
- Fail-fast behavior: Stop processing early when invariants are violated, preventing partial or inconsistent deployments
- Enhanced safety: Catch configuration errors before they propagate to managed clusters
Metadata
Metadata
Assignees
Labels
No labels