-
Notifications
You must be signed in to change notification settings - Fork 775
/
crdvalidations.go
422 lines (397 loc) · 15.3 KB
/
crdvalidations.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/*
Copyright 2016 The Fission Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package crd
import (
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
)
var (
// Function validation schema properties
functionSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"spec": {
Type: "object",
Description: "Specification of the desired behaviour of the Function",
Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
"environment": environmentReferenceSchema,
"package": functionPackageRefSchema,
"secrets": secretReferenceSchema,
"configmaps": configMapReferenceSchema,
"resources": {
Type: "object",
Description: "ResourceRequirements describes the compute resource requirements. This is only for newdeploy to set up resource limitation when creating deployment for a function.",
XPreserveUnknownFields: boolPtr(true),
},
"InvokeStrategy": invokeStrategySchema,
"functionTimeout": {
Type: "integer",
Description: " FunctionTimeout provides a maximum amount of duration within which a request for a particular function execution should be complete.\nThis is optional. If not specified default value will be taken as 60s",
},
"idletimeout": {
Type: "integer",
Description: "IdleTimeout specifies the length of time that a function is idle before the function pod(s) are eligible for deletion. If no traffic to the function is detected within the idle timeout, the executor will then recycle the function pod(s) to release resources.",
},
"concurrency": {
Type: "integer",
Description: "Concurrency specifies the maximum number of pods that can be specialized concurrently to serve requests.\n This is optional. If not specified default value will be taken as 5",
},
},
},
}
// Function validation schema
functionSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "A Function is a code and a runtime environment which can be used to execute code",
Properties: functionSchemaProps,
}
// Function validation object
functionValidation = &apiextensionsv1beta1.CustomResourceValidation{
OpenAPIV3Schema: &functionSchema,
}
)
var (
// Environment validation schema properties
environmentSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"spec": {
Type: "object",
Description: "Specification of the desired behaviour of the Environment",
Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
"version": {
Type: "integer",
Description: "Version is the Environment API version",
},
"runtime": runtimeSchema,
"builder": builderSchema,
"allowedFunctionsPerContainer": {
Type: "string",
Description: "Allowed functions per container. Allowed Values: single, multiple",
},
"allowAccessToExternalNetwork": {
Type: "boolean",
Description: "To enable accessibility of external network for builder/function pod, set to 'true'.",
},
"resources": {
Type: "object",
Description: "The request and limit CPU/MEM resource setting for the pods of the function. Can be overridden at Function in case of newdeployment executor type",
XPreserveUnknownFields: boolPtr(true),
},
"poolsize": {
Type: "integer",
Description: "The initial pool size for environment",
},
"terminationGracePeriod": {
Type: "integer",
Format: "int64",
Description: "The grace time for pod to perform connection draining before termination. The unit is in seconds.",
},
"keeparchive": {
Type: "boolean",
Description: "KeepArchive is used by fetcher to determine if the extracted archive should be extracted. For compiled languages such as Java, it should be true",
},
"imagepullsecret": {
Type: "string",
Description: "ImagePullSecret is the secret for Kubernetes to pull an image from a private registry.",
},
},
},
}
// Environment validation schema
environmentSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "Environments are the language-specific runtime parts of Fission. An Environment contains just enough software to build and run a Fission Function.",
Properties: environmentSchemaProps,
}
// Environment validation object
environmentValidation = &apiextensionsv1beta1.CustomResourceValidation{
OpenAPIV3Schema: &environmentSchema,
}
)
var (
// Package validation schema properties
packageSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"spec": {
Type: "object",
Description: "Specification of the desired behaviour of the package.",
Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
"environment": environmentReferenceSchema,
"source": archiveSchema,
"deployment": archiveSchema,
"configmaps": configMapReferenceSchema,
"buildcmd": {
Type: "string",
Description: "BuildCommand is a custom build command that builder uses to build the source archive.",
},
},
},
"status": {
Type: "object",
Description: "PackageStatus contains the build status of a package also the build log for examination.",
Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
"buildstatus": {
Type: "string",
Description: "BuildStatus is the package build status.",
},
"buildlog": {
Type: "string",
Description: "BuildCommand is a custom build command that builder used to build the source archive.",
},
"lastUpdateTimestamp": {
Type: "string",
Nullable: true,
Description: "LastUpdateTimestamp will store the timestamp the package was last updated metav1.Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON.",
},
},
},
}
// Package validation schema
packageSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "A Package is a Fission object containing a Deployment Archive and a Source Archive (if any). A Package also references a certain environment.",
Properties: packageSchemaProps,
}
// Environment validation object
packageValidation = &apiextensionsv1beta1.CustomResourceValidation{
OpenAPIV3Schema: &packageSchema,
}
)
// Children of Package crd schema
var (
archiveSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"type": {
Type: "string",
Description: "Type defines how the package is specified: literal or url.",
},
"literal": {
Type: "string",
Format: "byte",
Description: "Literal contents of the package.",
},
"url": {
Type: "string",
Description: "URL references a package.",
},
"checksum": checksumSchema,
}
archiveSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "Package contains or references a collection of source or binary files.",
Properties: archiveSchemaProps,
}
)
var (
checksumSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"type": {
Type: "string",
Description: "ChecksumType specifies the checksum algorithm, such as sha256, used for a checksum.",
},
"sum": {
Type: "string",
Description: " Sum is hex encoded chechsum value.",
},
}
checksumSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "Checksum of package contents when the contents are stored outside the Package struct. Type is the checksum algorithm; sha256 is the only currently supported one. Sum is hex encoded.",
Properties: checksumSchemaProps,
}
)
// Children of Function crd schema
var (
environmentReferenceSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"namespace": {
Type: "string",
Description: "Namespace for corresponding Environment",
},
"name": {
Type: "string",
Description: "Name of the Environment to use",
},
}
environmentReferenceSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "Reference to Fission Environment type custom resource.",
Properties: environmentReferenceSchemaProps,
}
)
var (
packageRefSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"namespace": {
Type: "string",
Description: "Namespace for corresponding Package",
},
"name": {
Type: "string",
Description: "Name of the Package to use",
},
"resourceversion": {
Type: "string",
Description: "Including resource version in the reference forces the function to be updated on package update, making it possible to cache the function based on its metadata.",
},
}
functionPackageRefSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"packageref": {
Type: "object",
Description: "Package Reference",
Properties: packageRefSchemaProps,
},
"functionName": {
Type: "string",
Description: "FunctionName specifies a specific function within the package using the path and specific function and varies based on language/environment",
},
}
functionPackageRefSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "FunctionPackageRef includes the reference to the package.",
Properties: functionPackageRefSchemaProps,
}
)
var (
secretReferenceSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"namespace": {
Type: "string",
Description: "Namespace for corresponding secret",
},
"name": {
Type: "string",
Description: "Name of the secret to use",
},
}
secretReferenceObjectSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "Reference to a Kubernetes secret.",
Properties: secretReferenceSchemaProps,
}
secretReferenceSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "array",
Nullable: true,
Items: &apiextensionsv1beta1.JSONSchemaPropsOrArray{
Schema: &secretReferenceObjectSchema,
},
}
)
var (
configMapReferenceSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"namespace": {
Type: "string",
Description: "Namespace for corresponding ConfigMap",
},
"name": {
Type: "string",
Description: "Name of the ConfigMap to use",
},
}
configMapReferenceObjectSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "Reference to a Kubernetes ConfigMap.",
Properties: configMapReferenceSchemaProps,
}
configMapReferenceSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "array",
Nullable: true,
Items: &apiextensionsv1beta1.JSONSchemaPropsOrArray{
Schema: &configMapReferenceObjectSchema,
},
}
)
var (
executionStrategySchema = map[string]apiextensionsv1beta1.JSONSchemaProps{
"ExecutorType": {
Type: "string",
Description: "ExecutorType is the executor type of a function used. Defaults to poolmgr. Available value: poolmgr, newdeploy",
},
"MinScale": {
Type: "integer",
Description: "Only for newdeploy executor to set up minimum replicas of deployment.",
},
"MaxScale": {
Type: "integer",
Description: "Only for newdeploy executor to set up maximum replicas of deployment.",
},
"TargetCPUPercent": {
Type: "integer",
Description: "Only for newdeploy executor to set up target CPU utilization of HPA.",
},
"SpecializationTimeout": {
Type: "integer",
Description: "Timeout setting for executor to wait for pod specialization.",
},
}
invokeStrategySchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"ExecutionStrategy": {
Type: "object",
Description: "ExecutionStrategy specifies low-level parameters for function execution, such as the number of instances, scaling strategy etc.",
Properties: executionStrategySchema,
},
"StrategyType": {
Type: "string",
Description: "StrategyType is the strategy type of a function.",
},
}
invokeStrategySchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "InvokeStrategy is a set of controls over how the function executes. It affects the performance and resource usage of the function. An InvokeStrategy is of one of two types: ExecutionStrategy, which controls low-level parameters such as which ExecutorType to use, when to autoscale, minimum and maximum number of running instances, etc.",
Properties: invokeStrategySchemaProps,
}
)
// Children of Environment crd schema
var (
runtimeSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"image": {
Type: "string",
Description: "Image for containing the language runtime.",
},
"container": {
Type: "object",
Description: "(Optional) Container allows the modification of the deployed runtime container using the Kubernetes Container spec. Fission overrides the following fields: Name, Image (set to the Runtime.Image), TerminationMessagePath, ImagePullPolicy\n You can set either PodSpec or Container, but not both.",
XPreserveUnknownFields: boolPtr(true),
},
"podspec": {
Type: "object",
Description: "(Optional) Podspec allows modification of deployed runtime pod with Kubernetes PodSpec.\n You can set either PodSpec or Container, but not both.\n More info for podspec:\n https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#podspec-v1-core",
XPreserveUnknownFields: boolPtr(true),
},
}
runtimeSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "Runtime is configuration for running function, like container image etc.",
Properties: runtimeSchemaProps,
}
)
var (
builderSchemaProps = map[string]apiextensionsv1beta1.JSONSchemaProps{
"image": {
Type: "string",
Description: "Image for containing the language runtime.",
},
"command": {
Type: "string",
Description: "(Optional) Default build command to run for this build environment.",
},
"container": {
Type: "object",
Description: "(Optional) Container allows the modification of the deployed runtime container using the Kubernetes Container spec. Fission overrides the following fields: Name, Image (set to the Runtime.Image), TerminationMessagePath, ImagePullPolicy\n You can set either PodSpec or Container, but not both.",
XPreserveUnknownFields: boolPtr(true),
},
"podspec": {
Type: "object",
Description: "(Optional) Podspec allows modification of deployed runtime pod with Kubernetes PodSpec.\n You can set either PodSpec or Container, but not both.",
XPreserveUnknownFields: boolPtr(true),
},
}
builderSchema = apiextensionsv1beta1.JSONSchemaProps{
Type: "object",
Description: "(Optional) Builder is configuration for builder manager to launch environment builder to build source code into deployable binary.",
Properties: builderSchemaProps,
}
)
func boolPtr(b bool) *bool {
return &b
}