1import { calcHash } from '../../serverF/calcHashF.mts'2import { do2ExecFile } from '../../serverF/childProcF/do2ExecFileF.mts'3import { ensureTmpDirExists } from '../../serverF/ptDiskF/ptDiskF.mts'4import { pathDownJoin } from '../../serverF/pathF.mts'5import { write1File } from '../../serverF/libFs/write1FileF.mts'6import { getResolvedKubeConfigPath } from './cliF/eptKubeCliF.mts'7import { getCurKlusterCfg } from './ctxF/klusterCtxF.mts'8import type { KubeResource } from './ctxF/klusterCtxF.mts'10type TryDryRunApplyProps = { resource: KubeResource, cluster_name: string }12export const tryDryRunApply = async ({resource, cluster_name}: TryDryRunApplyProps): Promise<boolean> => {13 const contents = JSON.stringify(resource, null, 2)14 const tmpResPath = pathDownJoin(await ensureTmpDirExists('kubetmp'), calcHash(contents) + '.json')15 await write1File(tmpResPath, contents)17 const kubeConfigPath = await getResolvedKubeConfigPath(cluster_name)18 const {kubeTlsInsecure = false} = getCurKlusterCfg(cluster_name) as {kubeTlsInsecure?: boolean}20 const cmdA = [21 'kubectl',22 kubeTlsInsecure && '--insecure-skip-tls-verify',23 'apply', '--dry-run=server', '-f', tmpResPath,24 ].filter(Boolean) as string[]26 const result = await do2ExecFile({27 cmdA,28 opts: {env: {...process.env, KUBECONFIG: kubeConfigPath}},29 })30 return result.isSuccess ?? false31}