Skip to content

Feature Request: Add fail function support in Go template rendering for Helm values and policyRefs #673

@kahirokunn

Description

@kahirokunn

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:

  1. Provide clear, actionable error messages when validation fails
  2. Prevent deployment in inconsistent or invalid states
  3. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions