-
Notifications
You must be signed in to change notification settings - Fork 56
/
properties.go
59 lines (46 loc) · 1.59 KB
/
properties.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
50
51
52
53
54
55
56
57
58
59
package v1
import (
"strconv"
"k8s.io/apimachinery/pkg/util/validation/field"
)
type LinstorControllerProperty struct {
// Name of the property to set.
//+kubebuilder:validation:MinLength=1
//+kubebuilder:validation:Required
Name string `json:"name"`
// Value to set the property to.
Value string `json:"value,omitempty"`
}
type LinstorNodeProperty struct {
// Name of the property to set.
//+kubebuilder:validation:MinLength=1
//+kubebuilder:validation:Required
Name string `json:"name"`
// Value to set the property to.
//+kubebuilder:validation:Optional
Value string `json:"value,omitempty"`
// ValueFrom sets the value from an existing resource.
//+kubebuilder:validation:Optional
ValueFrom *LinstorNodePropertyValueFrom `json:"valueFrom,omitempty"`
// Optional values are only set if they have a non-empty value
//+kubebuilder:validation:Optional
Optional bool `json:"optional,omitempty"`
}
type LinstorNodePropertyValueFrom struct {
// Select a field of the node. Supports `metadata.name`, `metadata.labels['<KEY>']`, `metadata.annotations['<KEY>']`.
//+kubebuilder:validation:MinLength=1
//+kubebuilder:validation:Required
NodeFieldRef string `json:"nodeFieldRef,omitempty"`
}
func ValidateNodeProperties(props []LinstorNodeProperty, path *field.Path) field.ErrorList {
var result field.ErrorList
for i := range props {
p := &props[i]
valSet := p.Value != ""
fromSet := p.ValueFrom != nil
if valSet == fromSet {
result = append(result, field.Invalid(path.Child(strconv.Itoa(i)), p, "Expected exactly one of 'value' and 'valueFrom' to be set"))
}
}
return result
}