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

Function validateConfig

cmd/controller/flags.go:279–312  ·  view source on GitHub ↗

validateConfig validates the config after all sources have been merged.

(cfg *config.Config)

Source from the content-addressed store, hash-verified

277
278// validateConfig validates the config after all sources have been merged.
279func validateConfig(cfg *config.Config) error {
280 if err := validate.Struct(cfg); err != nil {
281 return err
282 }
283
284 if err := validateAgentConfig(cfg.AgentConfig); err != nil {
285 return err
286 }
287
288 if cfg.PodSpecPatch != nil {
289 if err := validatePodSpecPatch(cfg.PodSpecPatch, cfg.AllowPodSpecPatchUnsafeCmdMod); err != nil {
290 return fmt.Errorf("invalid pod spec patch: %w", err)
291 }
292 }
293
294 if _, err := resource.ParseQuantity(cfg.ImageCheckContainerCPULimit); err != nil {
295 return fmt.Errorf("invalid CPU resource limit defined: %s", cfg.ImageCheckContainerCPULimit)
296 }
297
298 if _, err := resource.ParseQuantity(cfg.ImageCheckContainerMemoryLimit); err != nil {
299 return fmt.Errorf("invalid memory resource limit defined: %s", cfg.ImageCheckContainerMemoryLimit)
300 }
301
302 if cfg.DefaultResourceClassName != "" {
303 if cfg.ResourceClasses == nil {
304 return fmt.Errorf("default-resource-class-name %q specified but no resource-classes defined", cfg.DefaultResourceClassName)
305 }
306 if _, exists := cfg.ResourceClasses[cfg.DefaultResourceClassName]; !exists {
307 return fmt.Errorf("default-resource-class-name %q not found in resource-classes", cfg.DefaultResourceClassName)
308 }
309 }
310
311 return nil
312}
313
314func validateAgentConfig(agentConfig *config.AgentConfig) error {
315 if agentConfig == nil {

Callers 1

buildConfigFunction · 0.85

Calls 2

validateAgentConfigFunction · 0.85
validatePodSpecPatchFunction · 0.85

Tested by

no test coverage detected