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

Function FullConfigProcess

pkg/engine/engine.go:136–194  ·  view source on GitHub ↗

FullConfigProcess handles the full process of creating and updating the Bundle. The function performs no I/O that would respect a context; the ctx parameter that callers used to pass in was always discarded inside. Dropping the parameter makes the contract honest. If a future caller needs cancellat

(opts Options, patches []string)

Source from the content-addressed store, hash-verified

134//
135//nolint:gocritic // hugeParam: Options is the package's public facing configuration carrier; converting this to a pointer would propagate the change across every caller in pkg/commands and break the API for external consumers.
136func FullConfigProcess(opts Options, patches []string) (*bundle.Bundle, machine.Type, error) {
137 configBundle, err := InitializeConfigBundle(opts)
138 if err != nil {
139 return nil, machine.TypeUnknown, errors.Wrap(err, "initial config bundle error")
140 }
141
142 loadedPatches, err := configpatcher.LoadPatches(patches)
143 if err != nil {
144 if opts.Debug {
145 debugPhase(opts, patches, "", "", machine.TypeUnknown)
146 }
147
148 return nil, machine.TypeUnknown, errors.Wrap(err, "loading patches")
149 }
150
151 err = configBundle.ApplyPatches(loadedPatches, true, false)
152 if err != nil {
153 if opts.Debug {
154 debugPhase(opts, patches, "", "", machine.TypeUnknown)
155 }
156
157 return nil, machine.TypeUnknown, errors.Wrap(err, "apply initial patches error")
158 }
159
160 // Updating parameters after applying patches
161 machineType := configBundle.ControlPlaneCfg.Machine().Type()
162 clusterName := configBundle.ControlPlaneCfg.Cluster().Name()
163 clusterEndpoint := configBundle.ControlPlaneCfg.Cluster().Endpoint()
164
165 if machineType == machine.TypeUnknown {
166 machineType = machine.TypeWorker
167 }
168
169 if opts.Debug {
170 debugPhase(opts, patches, clusterName, clusterEndpoint.String(), machineType)
171 }
172
173 // Reinitializing the configuration bundle with updated parameters
174 updatedOpts := Options{
175 TalosVersion: opts.TalosVersion,
176 WithSecrets: opts.WithSecrets,
177 KubernetesVersion: opts.KubernetesVersion,
178 ClusterName: clusterName,
179 Endpoint: clusterEndpoint.String(),
180 }
181
182 configBundle, err = InitializeConfigBundle(updatedOpts)
183 if err != nil {
184 return nil, machineType, errors.Wrap(err, "reinit config bundle error")
185 }
186
187 // Applying updated patches
188 err = configBundle.ApplyPatches(loadedPatches, (machineType == machine.TypeControlPlane), (machineType == machine.TypeWorker))
189 if err != nil {
190 return nil, machineType, errors.Wrap(err, "apply updated patches error")
191 }
192
193 return configBundle, machineType, nil

Calls 3

InitializeConfigBundleFunction · 0.85
debugPhaseFunction · 0.85
StringMethod · 0.80