@@ -5,15 +5,15 @@ import { randomUUID } from 'crypto'
5
5
import { diff } from 'deep-diff'
6
6
import { copy , createFileSync , move , pathExists , renameSync , rm } from 'fs-extra'
7
7
import { mkdir , readFile , writeFile } from 'fs/promises'
8
- import { glob } from 'glob'
8
+ import { glob , globSync } from 'glob'
9
9
import { cloneDeep , each , get , isObject , isUndefined , mapKeys , mapValues , omit , pick , pull , set , unset } from 'lodash'
10
10
import { basename , dirname , join } from 'path'
11
11
import { prepareEnvironment } from 'src/common/cli'
12
12
import { decrypt , encrypt } from 'src/common/crypt'
13
13
import { terminal } from 'src/common/debug'
14
14
import { env } from 'src/common/envalid'
15
15
import { hf , hfValues } from 'src/common/hf'
16
- import { getFileMap , getTeamNames , saveValues } from 'src/common/repo'
16
+ import { getFileMap , getTeamNames , saveResourceGroupToFiles , saveValues } from 'src/common/repo'
17
17
import { getFilename , getSchemaSecretsPaths , gucci , loadYaml , rootDir } from 'src/common/utils'
18
18
import { writeValues , writeValuesToFile } from 'src/common/values'
19
19
import { BasicArguments , getParsedArgs , setParsedArgs } from 'src/common/yargs'
@@ -53,6 +53,7 @@ interface Change {
53
53
networkPoliciesMigration ?: boolean
54
54
teamResourceQuotaMigration ?: boolean
55
55
buildImageNameMigration ?: boolean
56
+ policiesMigration ?: boolean
56
57
}
57
58
58
59
export type Changes = Array < Change >
@@ -310,6 +311,32 @@ export const getBuildName = (name: string, tag: string): string => {
310
311
. replace ( / ^ - | - $ / g, '' ) // Remove leading or trailing hyphens
311
312
}
312
313
314
+ export async function policiesMigration ( deps = { loadYaml, saveResourceGroupToFiles } ) {
315
+ const filePaths = globSync ( `${ env . ENV_DIR } /env/teams/*/policies.yaml` , {
316
+ nodir : true , // Exclude directories
317
+ dot : false ,
318
+ } ) . sort ( )
319
+ if ( filePaths . length === 0 ) {
320
+ console . info ( 'No policies.yaml files found in env/teams/*/policies.yaml. Skipping migration' )
321
+ return
322
+ }
323
+ const inValues = filePaths . map ( async ( filePath ) => {
324
+ const yaml = await deps . loadYaml ( filePath )
325
+ return {
326
+ [ yaml ! . metadata . name ] : {
327
+ policies : yaml ! . spec ,
328
+ } ,
329
+ }
330
+ } )
331
+ const teamArray = await Promise . all ( inValues )
332
+ const teamConfig = teamArray . reduce ( ( acc , team ) => {
333
+ return { ...acc , ...team }
334
+ } , { } )
335
+
336
+ const policiesFileMap = getFileMap ( 'AplTeamPolicy' , env . ENV_DIR )
337
+ await deps . saveResourceGroupToFiles ( policiesFileMap , { teamConfig } , { } )
338
+ }
339
+
313
340
const buildImageNameMigration = async ( values : Record < string , any > ) : Promise < void > => {
314
341
const teams : Array < string > = Object . keys ( values ?. teamConfig as Record < string , any > )
315
342
type Build = {
@@ -412,6 +439,7 @@ export const applyChanges = async (
412
439
if ( c . networkPoliciesMigration ) await networkPoliciesMigration ( values )
413
440
if ( c . teamResourceQuotaMigration ) teamResourceQuotaMigration ( values )
414
441
if ( c . buildImageNameMigration ) await buildImageNameMigration ( values )
442
+ if ( c . policiesMigration ) await policiesMigration ( )
415
443
416
444
Object . assign ( values . versions , { specVersion : c . version } )
417
445
}
0 commit comments