1import { assertDefined } from "../../sharedF/assertsF/assertDefinedF.mts"2import { captureSaveExampleMeta } from '../cliF/saveExampleMetaAI.mts'3import { deployLabel } from './kubeLabelsF.mts'4import type { V1Container, V1Volume } from '@kubernetes/client-node'6type Generic3DeployTmplProps = {7 name: string8 spec?: object9 strategy?: object10 git_sha?: string11 jobType?: { replicas?: number }12}14export const generic3DeploymentTmpl = ({name, spec, strategy, git_sha, jobType}: Generic3DeployTmplProps) => {15 assertDefined(name)16 captureSaveExampleMeta({name})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 name31 }32 },33 template: {34 metadata: {35 labels: {36 name, [deployLabel]: name, git_sha37 }38 },39 spec40 }41 }42 }43}45type Generic3DaemonSetTmplProps = {46 name: string47 spec?: object48 updateStrategy?: object49 git_sha?: string50}52export const generic3DaemonSetTmpl = ({name, spec, updateStrategy, git_sha}: Generic3DaemonSetTmplProps) => {53 assertDefined(name)54 captureSaveExampleMeta({name})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 name66 }67 },68 template: {69 metadata: {70 labels: {71 name, [deployLabel]: name, git_sha72 }73 },74 spec75 }76 }77 }78}80type DeployTmplProps = {81 name: string82 strategy?: object83 initContainers?: V1Container[]84 containers?: V1Container[]85 volumes?: V1Volume[]86 annotations?: Record<string, string>87}89export const deployTmpl = ({name, strategy, initContainers, containers, volumes, annotations}: DeployTmplProps) => {90 const base = generic3DeploymentTmpl({91 name, strategy,92 spec: {93 initContainers,94 containers, volumes95 }96 })97 if (annotations) (base.spec.template.metadata as any).annotations = annotations98 return base99}101type GenericDeployTmplProps = { name: string, volumes?: V1Volume[] } & Record<string, unknown>103export const genericDeployTmpl = ({volumes, ...props}: GenericDeployTmplProps) => {104 const {name} = props105 return deployTmpl({106 name: name as string,107 volumes,108 containers: [props as unknown as V1Container]109 })110}