🌳
pt0/deployF/k8sF/genericDeploymentF.mts
4import type { V1Container, V1Volume } from '@kubernetes/client-node'
6type Generic3DeployTmplProps = {
7 name: string
8 spec?: object
9 strategy?: object
10 git_sha?: string
11 jobType?: { replicas?: number }
14export const generic3DeploymentTmpl = ({name, spec, strategy, git_sha, jobType}: Generic3DeployTmplProps) => {
18 const {replicas=1} = jobType || {}
19 return {
20 apiVersion: 'apps/v1',
21 kind: 'Deployment',
22 metadata: {
23 name,
24 },
25 spec: {
26 strategy,
27 replicas,
28 selector: {
29 matchLabels: {
30 name
31 }
32 },
33 template: {
34 metadata: {
35 labels: {
36 name, [deployLabel]: name, git_sha
37 }
38 },
39 spec
40 }
41 }
42 }
45type Generic3DaemonSetTmplProps = {
46 name: string
47 spec?: object
48 updateStrategy?: object
49 git_sha?: string
52export const generic3DaemonSetTmpl = ({name, spec, updateStrategy, git_sha}: Generic3DaemonSetTmplProps) => {
55 return {
56 apiVersion: 'apps/v1',
57 kind: 'DaemonSet',
58 metadata: {
59 name,
60 },
61 spec: {
62 updateStrategy: updateStrategy ?? {type: 'RollingUpdate', rollingUpdate: {maxUnavailable: 1}},
63 selector: {
64 matchLabels: {
65 name
66 }
67 },
68 template: {
69 metadata: {
70 labels: {
71 name, [deployLabel]: name, git_sha
72 }
73 },
74 spec
75 }
76 }
77 }
80type DeployTmplProps = {
81 name: string
82 strategy?: object
83 initContainers?: V1Container[]
84 containers?: V1Container[]
85 volumes?: V1Volume[]
86 annotations?: Record<string, string>
89export const deployTmpl = ({name, strategy, initContainers, containers, volumes, annotations}: DeployTmplProps) => {
90 const base = generic3DeploymentTmpl({
91 name, strategy,
92 spec: {
93 initContainers,
94 containers, volumes
95 }
96 })
97 if (annotations) (base.spec.template.metadata as any).annotations = annotations
98 return base
101type GenericDeployTmplProps = { name: string, volumes?: V1Volume[] } & Record<string, unknown>
103export const genericDeployTmpl = ({volumes, ...props}: GenericDeployTmplProps) => {
104 const {name} = props
105 return deployTmpl({
106 name: name as string,
107 volumes,
108 containers: [props as unknown as V1Container]
109 })