forked from openshift/cert-manager-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.go
More file actions
54 lines (46 loc) · 2.7 KB
/
Copy pathvalidation.go
File metadata and controls
54 lines (46 loc) · 2.7 KB
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
50
51
52
53
54
package common
import (
"unsafe"
corev1 "k8s.io/api/core/v1"
apivalidation "k8s.io/apimachinery/pkg/api/validation"
metav1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/apis/core"
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
)
// ValidateNodeSelectorConfig validates the NodeSelector configuration using
// the Kubernetes label validation rules.
func ValidateNodeSelectorConfig(nodeSelector map[string]string, fldPath *field.Path) error {
return metav1validation.ValidateLabels(nodeSelector, fldPath.Child("nodeSelector")).ToAggregate()
}
// ValidateTolerationsConfig validates the Tolerations configuration using
// the Kubernetes core toleration validation rules.
func ValidateTolerationsConfig(tolerations []corev1.Toleration, fldPath *field.Path) error {
// convert corev1.Tolerations to core.Tolerations, required for validation.
convTolerations := *(*[]core.Toleration)(unsafe.Pointer(&tolerations))
return corevalidation.ValidateTolerations(convTolerations, fldPath.Child("tolerations")).ToAggregate()
}
// ValidateResourceRequirements validates the ResourceRequirements configuration
// using the Kubernetes core resource requirements validation rules.
func ValidateResourceRequirements(requirements corev1.ResourceRequirements, fldPath *field.Path) error {
// convert corev1.ResourceRequirements to core.ResourceRequirements, required for validation.
convRequirements := *(*core.ResourceRequirements)(unsafe.Pointer(&requirements))
return corevalidation.ValidateContainerResourceRequirements(&convRequirements, nil, fldPath.Child("resources"), corevalidation.PodValidationOptions{}).ToAggregate()
}
// ValidateAffinityRules validates the Affinity configuration using
// the Kubernetes core affinity validation rules.
func ValidateAffinityRules(affinity *corev1.Affinity, fldPath *field.Path) error {
// convert corev1.Affinity to core.Affinity, required for validation.
convAffinity := (*core.Affinity)(unsafe.Pointer(affinity))
return validateAffinity(convAffinity, corevalidation.PodValidationOptions{}, fldPath.Child("affinity")).ToAggregate()
}
// ValidateLabelsConfig validates label keys and values using the Kubernetes
// metadata validation rules.
func ValidateLabelsConfig(labels map[string]string, fldPath *field.Path) error {
return metav1validation.ValidateLabels(labels, fldPath.Child("labels")).ToAggregate()
}
// ValidateAnnotationsConfig validates annotation keys and sizes using the
// Kubernetes metadata validation rules.
func ValidateAnnotationsConfig(annotations map[string]string, fldPath *field.Path) error {
return apivalidation.ValidateAnnotations(annotations, fldPath.Child("annotations")).ToAggregate()
}