1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package crdboilerplate
16
17 import (
18 "fmt"
19 "strings"
20
21 apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
22 )
23
24 func GetSensitiveFieldSchemaBoilerplate() apiextensions.JSONSchemaProps {
25 return apiextensions.JSONSchemaProps{
26 Type: "object",
27 Properties: map[string]apiextensions.JSONSchemaProps{
28 "valueFrom": {
29 Type: "object",
30 Description: "Source for the field's value. Cannot be used if 'value' is specified.",
31 Properties: map[string]apiextensions.JSONSchemaProps{
32 "secretKeyRef": {
33 Type: "object",
34 Description: "Reference to a value with the given key in the given Secret in the resource's namespace.",
35 Properties: map[string]apiextensions.JSONSchemaProps{
36 "name": {
37 Type: "string",
38 Description: "Name of the Secret to extract a value from.",
39 },
40 "key": {
41 Type: "string",
42 Description: "Key that identifies the value to be extracted.",
43 },
44 },
45 Required: []string{"name", "key"},
46 },
47 },
48 },
49 "value": {
50 Description: "Value of the field. Cannot be used if 'valueFrom' is specified.",
51 Type: "string",
52 },
53 },
54
55
56 OneOf: []apiextensions.JSONSchemaProps{
57 {
58 Required: []string{"value"},
59 Not: &apiextensions.JSONSchemaProps{
60 Required: []string{"valueFrom"},
61 },
62 },
63 {
64 Required: []string{"valueFrom"},
65 Not: &apiextensions.JSONSchemaProps{
66 Required: []string{"value"},
67 },
68 },
69 },
70 }
71 }
72
73 func GetOpenAPIV3SchemaSkeleton() *apiextensions.JSONSchemaProps {
74
75 return &apiextensions.JSONSchemaProps{
76 Type: "object",
77 Properties: map[string]apiextensions.JSONSchemaProps{
78 "apiVersion": {
79 Description: "apiVersion defines the versioned schema of this representation of an object. Servers " +
80 "should convert recognized schemas to the latest internal value, and may reject unrecognized " +
81 "values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
82 Type: "string",
83 },
84 "kind": {
85 Description: "kind is a string value representing the REST resource this object represents. Servers " +
86 "may infer this from the endpoint the client submits requests to. Cannot be updated. In " +
87 "CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#" +
88 "types-kinds",
89 Type: "string",
90 },
91 "metadata": {
92 Type: "object",
93 },
94 "status": {
95 Properties: map[string]apiextensions.JSONSchemaProps{
96 "observedGeneration": {
97 Description: "ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. " +
98 "If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource.",
99 Type: "integer",
100 },
101 "conditions": {
102 Description: "Conditions represent the latest available observation of the resource's " +
103 "current state.",
104 Items: &apiextensions.JSONSchemaPropsOrArray{
105 Schema: &apiextensions.JSONSchemaProps{
106 Type: "object",
107 Properties: map[string]apiextensions.JSONSchemaProps{
108 "lastTransitionTime": {
109 Description: "Last time the condition transitioned from one status to another.",
110 Type: "string",
111 },
112 "message": {
113 Description: "Human-readable message indicating details about last transition.",
114 Type: "string",
115 },
116 "reason": {
117 Description: "Unique, one-word, CamelCase reason for the condition's last " +
118 "transition.",
119 Type: "string",
120 },
121 "status": {
122 Description: "Status is the status of the condition. Can be True, False, " +
123 "Unknown.",
124 Type: "string",
125 },
126 "type": {
127 Description: "Type is the type of the condition.",
128 Type: "string",
129 },
130 },
131 },
132 },
133 Type: "array",
134 },
135 },
136 Type: "object",
137 },
138 },
139 }
140 }
141
142 func GetMultiKindResourceReferenceSchemaBoilerplate(externalRefDescription string, kinds []string) *apiextensions.JSONSchemaProps {
143 return &apiextensions.JSONSchemaProps{
144 Type: "object",
145 Properties: map[string]apiextensions.JSONSchemaProps{
146 "name": {
147 Description: "Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names",
148 Type: "string",
149 },
150 "namespace": {
151 Description: "Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/",
152 Type: "string",
153 },
154 "kind": {
155 Description: fmt.Sprintf("Kind of the referent. Allowed values: %v", strings.Join(kinds, ",")),
156 Type: "string",
157 },
158 "external": {
159 Description: externalRefDescription,
160 Type: "string",
161 },
162 },
163
164
165
166
167 OneOf: []apiextensions.JSONSchemaProps{
168 {
169 Required: []string{"name", "kind"},
170 Not: &apiextensions.JSONSchemaProps{
171 Required: []string{"external"},
172 },
173 },
174 {
175 Required: []string{"external"},
176 Not: &apiextensions.JSONSchemaProps{
177 AnyOf: []apiextensions.JSONSchemaProps{
178 {
179 Required: []string{"name"},
180 },
181 {
182 Required: []string{"namespace"},
183 },
184 {
185 Required: []string{"kind"},
186 },
187 },
188 },
189 },
190 },
191 }
192 }
193
194 func GetResourceReferenceSchemaBoilerplate(externalRefDescription string) *apiextensions.JSONSchemaProps {
195 return &apiextensions.JSONSchemaProps{
196 Type: "object",
197 Properties: map[string]apiextensions.JSONSchemaProps{
198 "name": {
199 Description: "Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names",
200 Type: "string",
201 },
202 "namespace": {
203 Description: "Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/",
204 Type: "string",
205 },
206 "external": {
207 Description: externalRefDescription,
208 Type: "string",
209 },
210 },
211
212
213
214
215 OneOf: []apiextensions.JSONSchemaProps{
216 {
217 Required: []string{"name"},
218 Not: &apiextensions.JSONSchemaProps{
219 Required: []string{"external"},
220 },
221 },
222 {
223 Required: []string{"external"},
224 Not: &apiextensions.JSONSchemaProps{
225 AnyOf: []apiextensions.JSONSchemaProps{
226 {
227 Required: []string{"name"},
228 },
229 {
230 Required: []string{"namespace"},
231 },
232 },
233 },
234 },
235 },
236 }
237 }
238
239 func GetAdditionalPrinterColumns() []apiextensions.CustomResourceColumnDefinition {
240
241 return []apiextensions.CustomResourceColumnDefinition{
242 {
243 Name: "Age",
244 Type: "date",
245 JSONPath: ".metadata.creationTimestamp",
246 },
247 {
248 Name: "Ready",
249 Type: "string",
250 Description: "When 'True', the most recent reconcile of the resource succeeded",
251 JSONPath: ".status.conditions[?(@.type=='Ready')].status",
252 },
253 {
254 Name: "Status",
255 Type: "string",
256 Description: "The reason for the value in 'Ready'",
257 JSONPath: ".status.conditions[?(@.type=='Ready')].reason",
258 },
259 {
260 Name: "Status Age",
261 Type: "date",
262 Description: "The last transition time for the value in 'Status'",
263 JSONPath: ".status.conditions[?(@.type=='Ready')].lastTransitionTime",
264 },
265 }
266 }
267
View as plain text