1+ import regex
2+
3+ schema Container:
4+ """ Container describes how the Application's tasks are expected to be run. Depending on
5+ the replicas parameter 1 or more containers can be created from each template.
6+
7+ Attributes
8+ ----------
9+ image: str, default is Undefined, required.
10+ Image refers to the Docker image name to run for this container.
11+ More info: https://kubernetes.io/docs/concepts/containers/images
12+ command: [str], default is Undefined, optional.
13+ Entrypoint array. Not executed within a shell.
14+ Command will overwrite the ENTRYPOINT value set in the Dockfile, otherwise the Docker
15+ image's ENTRYPOINT is used if this is not provided.
16+ args: [str], default is Undefined, optional.
17+ Arguments to the entrypoint.
18+ Args will overwrite the CMD value set in the Dockfile, otherwise the Docker
19+ image's CMD is used if this is not provided.
20+ env: {str:str}, default is Undefined, optional.
21+ List of environment variables to set in the container.
22+ The value of the environment variable may be static text or a value from a secret.
23+ workingDir: str, default is Undefined, optional.
24+ The working directory of the running process defined in entrypoint.
25+ Default container runtime will be used if this is not specified.
26+ resources: {str:str}, default is Undefined, optional.
27+ Map of resource requirements the container should run with.
28+ The resources parameter is a dict with the key being the resource name and the value being
29+ the resource value.
30+ files: {str:FileSpec}, default is Undefined, optional.
31+ List of files to create in the container.
32+ The files parameter is a dict with the key being the file name in the container and the value
33+ being the target file specification.
34+ dirs: {str:str}, default is Undefined, optional.
35+ Collection of volumes mount into the container's filesystem.
36+ The dirs parameter is a dict with the key being the folder name in the container and the value
37+ being the referenced volume.
38+ livenessProbe: Probe, default is Undefined, optional.
39+ LivenessProbe indicates if a running process is healthy.
40+ Container will be restarted if the probe fails.
41+ readinessProbe: Probe, default is Undefined, optional.
42+ ReadinessProbe indicates whether an application is available to handle requests.
43+ startupProbe: Probe, default is Undefined, optional.
44+ StartupProbe indicates that the container has started for the first time.
45+ Container will be restarted if the probe fails.
46+ lifecycle: Lifecycle, default is Undefined, optional.
47+ Lifecycle refers to actions that the management system should take in response to container lifecycle events.
48+
49+ Examples
50+ --------
51+ import kam.core.v1 as v1
52+
53+ web = v1.Container {
54+ image: "nginx:latest"
55+ command: ["/bin/sh", "-c", "echo hi"]
56+ env: {
57+ "name": "value"
58+ }
59+ resources: {
60+ "cpu": "2"
61+ "memory": "4Gi"
62+ }
63+ }
64+ """
65+
66+ # Image to run for this container.
67+ image: str
68+
69+ # Entrypoint array.
70+ # The image's ENTRYPOINT is used if this is not provided.
71+ command?: [str ]
72+ # Arguments to the entrypoint.
73+ # The image's CMD is used if this is not provided.
74+ args?: [str ]
75+ # Collection of environment variables to set in the container.
76+ # The value of environment variable may be static text or a value from a secret.
77+ env?: {str :str }
78+ # The current working directory of the running process defined in entrypoint.
79+ workingDir?: str
80+
81+ # Resource requirements for this container.
82+ resources?: {str :str }
83+
84+ # Files configures one or more files to be created in the container.
85+ files?: {str :FileSpec}
86+ # Dirs configures one or more volumes to be mounted to the specified folder.
87+ dirs?: {str :str }
88+
89+ # Liveness probe for this container.
90+ # Liveness probe indicates if a running process is healthy.
91+ livenessProbe?: Probe
92+ # Readiness probe for this container.
93+ # Readiness probe indicates whether an application is available to handle requests.
94+ readinessProbe?: Probe
95+ # Startup probe for this container.
96+ # Startup probe indicates that the container has started for the first time.
97+ startupProbe?: Probe
98+
99+ # Lifecycle configures actions which should be taken response to container lifecycle
100+ # events.
101+ lifecycle?: Lifecycle
102+
103+ check :
104+ all e in env {
105+ regex.match(e, r"^[-._a-zA-Z][-._a-zA-Z0-9]*$" )
106+ } if env, "a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit"
107+
108+ schema FileSpec:
109+ """ FileSpec defines the target file in a Container.
110+
111+ Attributes
112+ ----------
113+ content: str, default is Undefined, optional.
114+ File content in plain text.
115+ contentFrom: str, default is Undefined, optional.
116+ Source for the file content, reference to a secret of configmap value.
117+ mode: str, default is Undefined, optional.
118+ Mode bits used to set permissions on this file, must be an octal value
119+ between 0000 and 0777 or a decimal value between 0 and 511
120+
121+ Examples
122+ --------
123+ import kam.core.v1 as v1
124+
125+ tmpFile = v1.FileSpec {
126+ content: "some file contents"
127+ mode: "0777"
128+ }
129+ """
130+
131+ # The content of target file in plain text.
132+ content?: str
133+
134+ # Source for the file content, might be a reference to a secret value.
135+ contentFrom?: str
136+
137+ # Mode bits used to set permissions on this file.
138+ # Defaults to 0644.
139+ mode: str = "0644"
140+
141+ check :
142+ not content or not contentFrom, "content and contentFrom are mutually exclusive"
143+ regex.match(mode, r"^[0-7]{3,4}$" ), "valid mode must between 0000 and 0777, both inclusive"
144+
145+ schema Probe:
146+ """ Probe describes a health check to be performed against a container to determine whether it is
147+ alive or ready to receive traffic. There are three probe types: readiness, liveness, and startup.
148+
149+ Attributes
150+ ----------
151+ probeHandler: Exec | Http | Tcp, default is Undefined, required.
152+ The action taken to determine the alive or health of a container
153+ initialDelaySeconds: int, default is Undefined, optional.
154+ The number of seconds before health checking is activated.
155+ More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
156+ timeoutSeconds: int, default is Undefined, optional.
157+ The number of seconds after which the probe times out.
158+ More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
159+ periodSeconds: int, default is Undefined, optional.
160+ How often (in seconds) to perform the probe.
161+ successThreshold: int, default is Undefined, optional.
162+ Minimum consecutive successes for the probe to be considered successful after having failed.
163+ failureThreshold: int, default is Undefined, optional.
164+ Minimum consecutive failures for the probe to be considered failed after having succeeded.
165+ terminationGracePeriod: int, default is Undefined, optional.
166+ Duration in seconds before terminate gracefully upon probe failure.
167+
168+ Examples
169+ --------
170+ import kam.core.v1 as v1
171+
172+ probe = v1.Probe {
173+ probeHandler: v1.Http {
174+ path: "/healthz"
175+ }
176+ initialDelaySeconds: 10
177+ }
178+ """
179+
180+ # The action taken to determine the health of a container
181+ probeHandler: Exec | Http | Tcp
182+
183+ # Number of seconds after the container has started before liveness probes are initiated.
184+ initialDelaySeconds?: int
185+
186+ # Number of seconds after which the probe times out.
187+ timeoutSeconds?: int
188+
189+ # How often (in seconds) to perform the probe.
190+ periodSeconds?: int
191+
192+ # Minimum consecutive successes for the probe to be considered successful after having failed.
193+ successThreshold?: int
194+
195+ # Minimum consecutive failures for the probe to be considered failed after having succeeded.
196+ failureThreshold?: int
197+
198+ # Duration in seconds before terminate gracefully upon probe failure.
199+ terminationGracePeriod?: int
200+
201+ check :
202+ initialDelaySeconds >= 0 if initialDelaySeconds, "initialDelaySeconds must be greater than or equal to 0"
203+ timeoutSeconds >= 0 if timeoutSeconds, "timeoutSeconds must be greater than or equal to 0"
204+ periodSeconds >= 0 if periodSeconds, "periodSeconds must be greater than or equal to 0"
205+ successThreshold >= 0 if successThreshold, "successThreshold must be greater than or equal to 0"
206+ failureThreshold >= 0 if failureThreshold, "failureThreshold must be greater than or equal to 0"
207+ terminationGracePeriod >= 0 if terminationGracePeriod, "terminationGracePeriod must be greater than or equal to 0"
208+
209+ schema Exec:
210+ """ Exec describes a "run in container" action.
211+
212+ Attributes
213+ ----------
214+ command: [str], default is Undefined, required.
215+ The command line to execute inside the container.
216+
217+ Examples
218+ --------
219+ import kam.core.v1 as v1
220+
221+ execProbe = v1.Exec {
222+ command: ["probe.sh"]
223+ }
224+ """
225+
226+ # The command line to execute inside the container.
227+ # Exit status of 0 is treated as live/healthy and non-zero is unhealthy.
228+ command: [str ]
229+
230+ check :
231+ len(command) > 0, "command must be specified"
232+
233+ schema Http:
234+ """ Http describes an action based on HTTP Get requests.
235+
236+ Attributes
237+ ----------
238+ url: str, default is Undefined, required.
239+ The full qualified url to send HTTP requests.
240+ headers: {str:str}, default is Undefined, optional.
241+ Collection of custom headers to set in the request
242+
243+ Examples
244+ --------
245+ import kam.core.v1 as v1
246+
247+ httpProbe = v1.Http {
248+ url: "http://localhost:80"
249+ headers: {
250+ "X-HEADER": "VALUE"
251+ }
252+ }
253+ """
254+
255+ # The full qualified url to send HTTP requests.
256+ url: str
257+
258+ # Custom headers to set in the request.
259+ headers?: {str :str }
260+
261+ check :
262+ all header in headers {
263+ regex.match(header, r"^[-A-Za-z0-9]+$" )
264+ } if headers, "a valid HTTP header must consist of alphanumeric characters or '-' e.g X-Header-Name"
265+
266+ schema Tcp:
267+ """ Tcp describes an action based on opening a socket.
268+
269+ Attributes
270+ ----------
271+ url: str, default is Undefined, required.
272+ The full qualified url to open a socket.
273+
274+ Examples
275+ --------
276+ import kam.core.v1 as v1
277+
278+ tcpProbe = v1.Tcp {
279+ url: "tcp://localhost:1234"
280+ }
281+ """
282+
283+ # The full qualified url to open a socket.
284+ url: str
285+
286+ schema Lifecycle:
287+ """ Lifecycle describes actions that the management system should take in response
288+ to container lifecycle events.
289+
290+ Attributes
291+ ----------
292+ preStop: p.Exec | p.Http, default is Undefined, optional.
293+ The action to be taken before a container is terminated due to an API request or
294+ management event such as liveness/startup probe failure, preemption, resource contention, etc.
295+ More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
296+ postStart: p.Exec | p.Http, default is Undefined, optional.
297+ The action to be taken after a container is created.
298+ More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
299+
300+ Examples
301+ --------
302+ import kam.core.v1 as v1
303+
304+ lifecycleHook = v1.Lifecycle {
305+ preStop: v1.Exec {
306+ command: ["preStop.sh"]
307+ }
308+ postStart: v1.Http {
309+ url: "http://localhost:80"
310+ }
311+ }
312+ """
313+
314+ # The action to be taken before a container is terminated.
315+ preStop?: Exec | Http
316+
317+ # The action to be taken after a container is created.
318+ postStart?: Exec | Http
0 commit comments