/
datadogagentprofile_validation.go
49 lines (44 loc) · 1.63 KB
/
datadogagentprofile_validation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package v1alpha1
import (
"fmt"
)
// ValidateDatadogAgentProfileSpec is used to check if a DatadogAgentProfileSpec is valid
func ValidateDatadogAgentProfileSpec(spec *DatadogAgentProfileSpec) error {
// check that profileAffinity contains a set of requirements
if spec.ProfileAffinity == nil {
return fmt.Errorf("profileAffinity must be defined")
}
if spec.ProfileAffinity.ProfileNodeAffinity == nil {
return fmt.Errorf("profileNodeAffinity must be defined")
}
if len(spec.ProfileAffinity.ProfileNodeAffinity) < 1 {
return fmt.Errorf("profileNodeAffinity must have at least 1 requirement")
}
// validate config
if spec.Config == nil {
return fmt.Errorf("config must be defined")
}
if spec.Config.Override == nil {
return fmt.Errorf("config override must be defined")
}
if spec.Config.Override[NodeAgentComponentName] == nil {
return fmt.Errorf("node agent override must be defined")
}
if spec.Config.Override[NodeAgentComponentName].Containers == nil {
return fmt.Errorf("node agent container must be defined")
}
containsAtLeastOneContainerResourceOverride := false
for _, container := range spec.Config.Override[NodeAgentComponentName].Containers {
if container.Resources != nil {
containsAtLeastOneContainerResourceOverride = true
}
}
if !containsAtLeastOneContainerResourceOverride {
return fmt.Errorf("at least one container resource must be defined")
}
return nil
}