1import * as _ from 'lodash-es'2import { inspect2KubeRes } from '../kubeClientF.mts'3import { read2Resource } from '../read2ResourceF.mts'4import { guardPromptEq } from '../../readlineF/guardPromptF.mts'5import { getKlusterCtx, type KubeResource } from '../ctxF/klusterCtxF.mts'6import { isPvc } from '../isKubeResF.mts'7import { genericPvcTmplA } from '../genericPvcF.mts'8import { resourcesActionLite } from '../resourcesActionLiteF.mts'9import { getAction } from '../../ctxF/actionCtxF.mts'11type KubeActionPvcProps = {12 softdeleted?: boolean13 [key: string]: any14}16export const kubeActionPvc = async (props: KubeActionPvcProps) => {17 let {cluster_name} = getKlusterCtx(props)19 if (action == 'delete') {20 props.softdeleted = true21 action = 'patch'22 }23 let noDelPvcs = true24 const resources: KubeResource[] = await genericPvcTmplA(props as any)25 if (action == 'delpvcs') {26 console.log(..._.map(resources, (resource) => inspect2KubeRes({resource, cluster_name})))27 await guardPromptEq('Are you sure delete pvcs^? Your data is throw-away or backed up (y/n)? ', 'y')28 action = 'delete'29 noDelPvcs = false30 }31 if (props.softdeleted) {32 const resource = _.find(resources, isPvc)33 const existingPvc = await read2Resource({resource: resource!, cluster_name})34 if (!existingPvc) return35 }36 await resourcesActionLite({37 resources,38 action, cluster_name,39 noDelPvcs,40 })41}