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)
| 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. |
| 1823 | func 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 |