🌳
pt0/deployF/k8sF/mkJobDeployF.mts
1import type { V1Volume, V1VolumeMount, V1EnvVarSource } from '@kubernetes/client-node'
10import type { KubeResource } from './ctxF/klusterCtxF.mts'
14type MkJobDeployProps = {
15 action: string
16 name: string
17 secretNames?: string[]
18 envConf?: Record<string, string>
19 cluster_name: string
20 taskCmd: string
21 image: string
22 dockreg_host?: string
23 jobType: { kind: string, [k: string]: unknown }
24 appConfig: { monorDataPvcH?: Record<string, unknown>, colocateWithPod?: string, [k: string]: unknown }
25 git_sha: string
26 envLocal: Record<string, string | V1EnvVarSource>
27 getVolMntsForPvc?: (opts: {monorDataPvcH?: Record<string, unknown>}) => Promise<{resources: KubeResource[], volumes: V1Volume[], volumeMounts: V1VolumeMount[]}>
30export const mkJobDeployment = async ({
31 action, name, secretNames, envConf, cluster_name, taskCmd, image, dockreg_host, jobType,
32 appConfig, git_sha, envLocal, getVolMntsForPvc,
33}: MkJobDeployProps) => {
35 let {promises,envConfHash,...volMnts0} = getVolumesForSecrets({secretNames, envConf, cluster_name, name, action} as any)
37 const {monorDataPvcH, colocateWithPod} = appConfig
38 let {resources, ...volMnts1} = getVolMntsForPvc
39 ? await getVolMntsForPvc({monorDataPvcH})
40 : {resources: [] as any[], volumes: [], volumeMounts: []}
41 const {volumes, volumeMounts} = mergeVolsMnts(volMnts0 as any, volMnts1 as any)
43 const hasPvc = resources.length > 0
45 let resource = await resourceForJobType({
46 action, jobType: jobType as any, name, cluster_name, dockreg_host, image, taskCmd, volumes, volumeMounts, git_sha, envLocal,
47 hasPvc, colocateWithPod,
48 })
49 const templateAnnotations = {
50 metadata: {
51 annotations: {
52 envConfHash
53 }
54 }
55 }
56 if (jobType.kind == 'CronJob') {
57 resource = mergeConcatA(resource as object, {
58 spec: {
59 jobTemplate: {
60 spec: {
61 template: templateAnnotations
62 }
63 }
64 }
65 })
66 } else {
67 resource = mergeConcatA(resource as object, {
68 spec: {
69 template: templateAnnotations
70 }
71 })
72 }
74 resources.push(resource as KubeResource)
76 if (isApplyishAction(action)) {
77 const existingJob = await read2Resource({resource: resource as any, cluster_name})
78 if (existingJob && existingJob.kind != resource?.kind) {
79 await resourcesAction({resources: [existingJob as KubeResource], action: 'delete'})
80 }
81 }
83 if (isActionSupported(action)) {
84 promises.push(resourcesAction({resources, action, cluster_name, noDelPvcs: true}))
85 await Promise.all(promises)
86 }
88 if (isApplyishAction(action) && resource?.kind == 'Deployment') {
89 await waitForDeploymentRollout({resource: resource as any, cluster_name})
90 if (action == 'apply') await watchFlogs()
91 }
92 return resource