feat: upstream enterprise preview (#1841)

feat: upstream enterprise preview

---------

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Co-authored-by: CorentinPtrl <pitrel.corentin@gmail.com>
This commit is contained in:
Oliver Bähler
2026-05-28 00:58:58 +02:00
committed by GitHub
co-authored by CorentinPtrl
parent 7a65ab7afc
commit cc4fb45d70
462 changed files with 48456 additions and 10529 deletions
+19 -2
View File
@@ -8,10 +8,13 @@ import (
"errors"
"fmt"
"io"
"strings"
"text/template"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
kyaml "k8s.io/apimachinery/pkg/util/yaml"
"github.com/projectcapsule/capsule/pkg/template/functions"
)
// RenderUnstructuredItems attempts to render a given string template into a list of unstructured resources.
@@ -20,7 +23,7 @@ func RenderUnstructuredItems(
key MissingKeyOption,
tplString string,
) (items []*unstructured.Unstructured, err error) {
tmpl, err := template.New("tpl").Option("missingkey=" + key.String()).Funcs(ExtraFuncMap()).Parse(tplString)
tmpl, err := template.New("tpl").Option("missingkey=" + key.String()).Funcs(functions.ExtraFuncMap()).Parse(tplString)
if err != nil {
return
}
@@ -42,7 +45,7 @@ func RenderUnstructuredItems(
}
// Skip pure whitespace/--- separators that decode to nil/empty.
return nil, fmt.Errorf("decode yaml: %w", err)
return nil, fmt.Errorf("decode yaml: %w\nrendered template:\n%s", err, withLineNumbers(rendered.String()))
}
if len(obj) == 0 {
@@ -59,3 +62,17 @@ func RenderUnstructuredItems(
return out, nil
}
func withLineNumbers(s string) string {
lines := strings.Split(s, "\n")
width := len(fmt.Sprintf("%d", len(lines)))
var b strings.Builder
for i, line := range lines {
fmt.Fprintf(&b, "%*d | %s\n", width, i+1, line)
}
return b.String()
}