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

Function applyPatchesAndRenderConfig

pkg/engine/engine.go:1859–2042  ·  view source on GitHub ↗

applyPatchesAndRenderConfig assembles the final Talos config bytes for the non-Full template path: split out extra documents, run two bundle-rebuild passes (TypeUnknown then resolved machine type), apply patches in dependency order, serialise. nolint:funlen,gocognit,gocyclo,cyclop,nestif,gocritic /

(opts Options, configPatches []string)

Source from the content-addressed store, hash-verified

1857//
1858//nolint:funlen,gocognit,gocyclo,cyclop,nestif,gocritic // single linear pipeline (extract -> hydrate cluster meta -> reinit bundle for the resolved machine type -> serialise -> reattach extra docs); each branch error path wraps with its own context. hugeParam: Options is the public configuration carrier; passing by pointer would propagate across pkg/commands and external consumers.
1859func applyPatchesAndRenderConfig(opts Options, configPatches []string) ([]byte, error) {
1860 // Separate Talos config patches from extra documents (like UserVolumeConfig)
1861 talosPatches, extraDocs, err := extractExtraDocuments(configPatches)
1862 if err != nil {
1863 return nil, err
1864 }
1865
1866 // Generate options for the configuration based on the provided flags
1867 genOptions := []generate.Option{}
1868
1869 if opts.TalosVersion != "" {
1870 versionContract, err := config.ParseContractFromVersion(opts.TalosVersion)
1871 if err != nil {
1872 return nil, errors.Wrap(err, "invalid talos-version")
1873 }
1874
1875 genOptions = append(genOptions, generate.WithVersionContract(versionContract))
1876 }
1877
1878 if opts.WithSecrets != "" {
1879 secretsBundle, err := secrets.LoadBundle(opts.WithSecrets)
1880 if err != nil {
1881 return nil, errors.Wrap(err, "failed to load secrets bundle")
1882 }
1883
1884 genOptions = append(genOptions, generate.WithSecretsBundle(secretsBundle))
1885 }
1886
1887 configBundleOpts := []bundle.Option{
1888 bundle.WithInputOptions(
1889 &bundle.InputOptions{
1890 KubeVersion: strings.TrimPrefix(opts.KubernetesVersion, "v"),
1891 GenOptions: genOptions,
1892 },
1893 ),
1894 bundle.WithVerbose(false),
1895 }
1896
1897 // Load and apply patches to discover the machine type
1898 configBundle, err := bundle.NewBundle(configBundleOpts...)
1899 if err != nil {
1900 return nil, errors.Wrap(err, "creating initial config bundle")
1901 }
1902
1903 patches, err := configpatcher.LoadPatches(talosPatches)
1904 if err != nil {
1905 if opts.Debug {
1906 debugPhase(opts, configPatches, "", "", machine.TypeUnknown)
1907 }
1908
1909 return nil, errors.Wrap(err, "loading patches")
1910 }
1911
1912 err = configBundle.ApplyPatches(patches, true, false)
1913 if err != nil {
1914 if opts.Debug {
1915 debugPhase(opts, configPatches, "", "", machine.TypeUnknown)
1916 }

Callers 1

RenderFunction · 0.85

Calls 7

DiffYAMLsFunction · 0.92
CopyCommentsFunction · 0.92
ApplyCommentsFunction · 0.92
extractExtraDocumentsFunction · 0.85
debugPhaseFunction · 0.85
encodeYAMLNodeIndentedFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected