MCPcopy Create free account
hub / github.com/buildkite/agent-stack-k8s / mergeConfigFromFile

Function mergeConfigFromFile

cmd/controller/flags.go:261–276  ·  view source on GitHub ↗

mergeConfigFromFile merges file config values into the base config. The keys map indicates which fields were present in the file, allowing zero values (like max-in-flight: 0) to override defaults. Uses reflection to iterate over fields based on their JSON tags.

(base, file *config.Config, keys map[string]struct{})

Source from the content-addressed store, hash-verified

259// zero values (like max-in-flight: 0) to override defaults.
260// Uses reflection to iterate over fields based on their JSON tags.
261func mergeConfigFromFile(base, file *config.Config, keys map[string]struct{}) {
262 baseVal := reflect.ValueOf(base).Elem()
263 fileVal := reflect.ValueOf(file).Elem()
264 baseType := baseVal.Type()
265
266 for i := range baseType.NumField() {
267 field := baseType.Field(i)
268 jsonTag := strings.Split(field.Tag.Get("json"), ",")[0]
269 if jsonTag == "" || jsonTag == "-" {
270 continue
271 }
272 if _, ok := keys[jsonTag]; ok {
273 baseVal.Field(i).Set(fileVal.Field(i))
274 }
275 }
276}
277
278// validateConfig validates the config after all sources have been merged.
279func validateConfig(cfg *config.Config) error {

Callers 1

buildConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected