MCPcopy Create free account
hub / github.com/cozystack/talm / extractExtraDocuments

Function extractExtraDocuments

pkg/engine/engine.go:1823–1851  ·  view source on GitHub ↗

extractExtraDocuments separates Talos config patches from other YAML documents. Returns the Talos patches to be processed, extra documents to be appended to output, and any error.

(patches []string)

Source from the content-addressed store, hash-verified

1821// extractExtraDocuments separates Talos config patches from other YAML documents.
1822// Returns the Talos patches to be processed, extra documents to be appended to output, and any error.
1823func extractExtraDocuments(patches []string) ([]string, []string, error) {
1824 var talosPatches, extraDocs []string
1825
1826 for _, patch := range patches {
1827 // Normalize CRLF to LF for consistent splitting
1828 patch = strings.ReplaceAll(patch, "\r\n", "\n")
1829 // Split by YAML document separator (--- at start of line)
1830 docs := yamlDocSeparator.Split(patch, -1)
1831 for _, doc := range docs {
1832 doc = strings.TrimSpace(doc)
1833 if doc == "" {
1834 continue
1835 }
1836
1837 isTalos, parseErr := isTalosConfigPatch(doc)
1838 if parseErr != nil {
1839 return nil, nil, errors.Wrapf(parseErr, "invalid YAML in template output\n\nTemplate output:\n%s", doc)
1840 }
1841
1842 if isTalos {
1843 talosPatches = append(talosPatches, doc)
1844 } else {
1845 extraDocs = append(extraDocs, doc)
1846 }
1847 }
1848 }
1849
1850 return talosPatches, extraDocs, nil
1851}
1852
1853// applyPatchesAndRenderConfig assembles the final Talos config bytes
1854// for the non-Full template path: split out extra documents, run two

Callers 2

Calls 1

isTalosConfigPatchFunction · 0.85

Tested by 1