1import * as _ from 'lodash-es'2import fs from 'fs'3import { betLog } from "../../sharedF/betterConsLogF.mts";4import { getKlusterCtx } from "../k8sF/ctxF/klusterCtxF.mts";5import { getAction } from '../ctxF/actionCtxF.mts'6import { resourcesAction } from '../k8sF/resourcesActionF.mts'7import { kube2ApplyK, yamlReplaceAndLoad } from '../k8sF/kustomizeF.mts'8import { awaitCnpgNsActive, awaitCnpgWebhookReady } from './awaitCnpgReadyAI.mts'9import type { KubeResource } from '../k8sF/ctxF/klusterCtxF.mts'10import { getMyDir } from '../setPtDirForImportMetaUrlF.mts'11import { tsImportMetaUrl } from '../../ptDirF.mts'13const cnpgManifestPath = getMyDir(tsImportMetaUrl(import.meta.url)) + '/kust/cnpg-1.25.1.yaml'15export const k8sCnPg = async () => {17 if (action !== 'apply') return19 const {cluster_name} = getKlusterCtx()21 let resources = yamlReplaceAndLoad({contentS: fs.readFileSync(cnpgManifestPath, 'utf8')}) as KubeResource[]24 const nsResA = _.filter(resources, ({kind}) => kind == 'Namespace')25 resources = _.difference(resources, nsResA)26 await kube2ApplyK({action, resources: nsResA, cluster_name})27 await awaitCnpgNsActive()29 const crdResA = _.filter(resources, ({kind}) => kind == 'CustomResourceDefinition')30 resources = _.difference(resources, crdResA)31 await kube2ApplyK({action, resources: crdResA, cluster_name})33 await kube2ApplyK({action, resources, cluster_name})34 await awaitCnpgWebhookReady()36 await resourcesAction({resources: [{37 apiVersion: 'v1',38 kind: 'ConfigMap',39 metadata: {40 name: 'cnpg-controller-manager-config',41 namespace: 'cnpg-system'42 },43 data: {44 INHERITED_LABELS: 'name'45 }46 } as KubeResource]})47}