forked from ebauman/crder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.go
95 lines (68 loc) · 1.84 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package crder
import (
v1 "k8s.io/api/admissionregistration/v1"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type Validation struct {
name string
service v1.ServiceReference
caBundle string
url string
rules []v1.RuleWithOperations
namespaceSelector v12.LabelSelector
objectSelector v12.LabelSelector
matchPolicy v1.MatchPolicyType
versions []string
sideEffect v1.SideEffectClass
}
func (v *Validation) defaults() {
v.SideEffectNone()
}
type validationCustomizer func(vv *Validation)
func (vv *Validation) MatchPolicyExact() *Validation {
vv.matchPolicy = v1.Exact
return vv
}
func (vv *Validation) MatchPolicyEquivalent() *Validation {
vv.matchPolicy = v1.Equivalent
return vv
}
func (vv *Validation) SideEffectNone() *Validation {
vv.sideEffect = v1.SideEffectClassNone
return vv
}
func (vv *Validation) SideEffectNoneOnDryRun() *Validation {
vv.sideEffect = v1.SideEffectClassNoneOnDryRun
return vv
}
func (vv *Validation) WithVersions(versions ...string) *Validation {
vv.versions = versions
return vv
}
func (vv *Validation) WithCABundle(bundle string) *Validation {
vv.caBundle = bundle
return vv
}
func (vv *Validation) WithService(service v1.ServiceReference) *Validation {
vv.service = service
return vv
}
func (vv *Validation) WithURL(url string) *Validation {
vv.url = url
return vv
}
func (vv *Validation) AddRules(rules ...v1.RuleWithOperations) *Validation {
if len(vv.rules) == 0 {
vv.rules = []v1.RuleWithOperations{}
}
vv.rules = append(vv.rules, rules...)
return vv
}
func (vv *Validation) SetNamespaceSelector(selector v12.LabelSelector) *Validation {
vv.namespaceSelector = selector
return vv
}
func (vv *Validation) SetObjectSelector(selector v12.LabelSelector) *Validation {
vv.objectSelector = selector
return vv
}