forked from ebauman/crder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
83 lines (66 loc) · 1.81 KB
/
version.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
package crder
import (
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/utils/pointer"
)
type Version struct {
columns []apiextv1.CustomResourceColumnDefinition
served bool
stored bool
parent *CRD
object interface{}
version string
deprecated bool
deprecationMessage string
scale *apiextv1.CustomResourceSubresourceScale
status bool
preserveUnknown bool
}
type versionCustomizer func(cv *Version)
func (cv *Version) WithColumn(name string, jsonPath string) *Version {
col := apiextv1.CustomResourceColumnDefinition{
Name: name,
JSONPath: jsonPath,
Type: "string",
Priority: 0,
}
cv.columns = append(cv.columns, col)
return cv
}
func (cv *Version) WithCRDColumns(cols ...apiextv1.CustomResourceColumnDefinition) *Version {
cv.columns = append(cv.columns, cols...)
return cv
}
func (cv *Version) IsServed(served bool) *Version {
cv.served = served
return cv
}
func (cv *Version) IsStored(stored bool) *Version {
cv.stored = stored
return cv
}
func (cv *Version) IsDeprecated(deprecationWarning string) *Version {
cv.deprecated = true
cv.deprecationMessage = deprecationWarning
return cv
}
func (cv *Version) WithObject(obj interface{}) *Version {
cv.object = obj
return cv
}
func (cv *Version) WithScale(labelSelectorPath string, specReplicasPath string, statusReplicaPath string) *Version {
cv.scale = &apiextv1.CustomResourceSubresourceScale{
SpecReplicasPath: specReplicasPath,
StatusReplicasPath: statusReplicaPath,
LabelSelectorPath: pointer.String(labelSelectorPath),
}
return cv
}
func (cv *Version) WithStatus() *Version {
cv.status = true
return cv
}
func (cv *Version) WithPreserveUnknown() *Version {
cv.preserveUnknown = true
return cv
}