Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Clean orphan charts before generating #17584

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions infra/src/cli/generate-chart-values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderEnv } from './render-env'
import { ChartName, Deployments, Charts } from '../uber-charts/all-charts'
import { writeFileSync, mkdirSync } from 'fs'
import { writeFileSync, mkdirSync, rmSync } from 'fs'
import { Envs } from '../environments'
import { OpsEnv } from '../dsl/types/input-types'
import path from 'path'
Expand All @@ -21,6 +21,18 @@ const headerComment = `#########################################################

`

const relativeChartDir = '../../../charts'
const cleanOrphanDirs = (filePath: string): void => {
try {
rmSync(filePath, { recursive: true })
} catch (error) {
if (error instanceof Error) {
console.error(
`Failed to clean orphan directories at ${filePath}: ${error.message}`,
)
}
}
}
peturgq marked this conversation as resolved.
Show resolved Hide resolved
const writeYamlFile = (filePath: string, content: unknown) => {
const doc = new yaml.Document()
doc.contents = doc.createNode(content)
Expand All @@ -31,8 +43,9 @@ const writeYamlFile = (filePath: string, content: unknown) => {
}

const generateChartValues = async () => {
console.log('Cleaning orphan charts')
cleanOrphanDirs(path.join(__dirname, relativeChartDir))
console.log('Gathering charts')

for (const [name, envs] of Object.entries(Deployments)) {
for (const [envType, envName] of Object.entries(envs)) {
console.log(`Processing ${name} ${envName} ${envType}`)
Expand All @@ -45,7 +58,7 @@ const generateChartValues = async () => {
writeYamlFile(
path.join(
__dirname,
'/../../../charts',
relativeChartDir,
name,
`values.${Envs[envName].type}.yaml`,
),
Expand All @@ -67,7 +80,7 @@ const generateChartValues = async () => {
writeYamlFile(
path.join(
__dirname,
`/../../../charts/${name}-services`,
`${relativeChartDir}/${name}-services`,
serviceName,
`values.${Envs[envName].type}.yaml`,
),
Expand Down
Loading