Skip to content

Commit 785f19d

Browse files
committed
fix: cleanup and addres comments
1 parent 0fb24cd commit 785f19d

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

src/cmd/apply-as-apps.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ export const getArgocdGitopsManifest = (name: string, targetNamespace?: string)
153153
}
154154
const repoURL = `${env.GIT_PROTOCOL}://${env.GIT_URL}:${env.GIT_PORT}/otomi/values.git`
155155
const path = targetNamespace
156-
? `${operatorEnv.GITOPS_MANIFESTS_NS_PATH}/${targetNamespace}`
157-
: operatorEnv.GITOPS_MANIFESTS_GLOBAL_PATH
156+
? `${operatorEnv.GITOPS_MANIFESTS_NS_RELATIVE_DIR_PATH}/${targetNamespace}`
157+
: operatorEnv.GITOPS_GLOBAL_MANIFESTS_RELATIVE_PATH
158158
return getArgoCdAppManifest(name, ARGOCD_APP_GITOPS_LABEL, {
159159
project: 'default',
160160
syncPolicy,
@@ -461,13 +461,17 @@ export const calculateGitOpsAppsDiff = async (
461461
deps = { getApplications },
462462
): Promise<{ toAdd: Set<string>; toRemove: Set<string>; namespaceDirs: string[] }> => {
463463
const envDir = env.ENV_DIR
464-
const namespaceListing = await glob(`${envDir}/${operatorEnv.GITOPS_MANIFESTS_NS_PATH}/*`, { withFileTypes: true })
464+
const namespaceListing = await glob(`${envDir}/${operatorEnv.GITOPS_MANIFESTS_NS_RELATIVE_DIR_PATH}/*`, {
465+
withFileTypes: true,
466+
})
465467
const namespaceDirs = namespaceListing.filter((path) => path.isDirectory()).map((path) => path.name)
466468
const existingGitOpsApps = new Set(await deps.getApplications(`otomi.io/app=${ARGOCD_APP_GITOPS_LABEL}`))
467469

468470
// First create sets of Applications to be updated
469471
const requiredGitOpsApps = new Set(namespaceDirs.map((dirName) => `${ARGOCD_APP_GITOPS_NS_PREFIX}-${dirName}`))
470-
const globalPath = statSync(`${envDir}/${operatorEnv.GITOPS_MANIFESTS_GLOBAL_PATH}`, { throwIfNoEntry: false })
472+
const globalPath = statSync(`${envDir}/${operatorEnv.GITOPS_GLOBAL_MANIFESTS_RELATIVE_PATH}`, {
473+
throwIfNoEntry: false,
474+
})
471475
if (globalPath && globalPath.isDirectory()) {
472476
requiredGitOpsApps.add(ARGOCD_APP_GITOPS_GLOBAL_NAME)
473477
}

src/common/utils.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import $RefParser, { JSONSchema } from '@apidevtools/json-schema-ref-parser'
22
import cleanDeep, { CleanOptions } from 'clean-deep'
33
import { createHash } from 'crypto'
44
import fs, { existsSync, readFileSync } from 'fs'
5-
import { readdir, readFile, writeFile } from 'fs/promises'
5+
import { readdir, readFile } from 'fs/promises'
66
import { glob } from 'glob'
77
import walk from 'ignore-walk'
88
import { dump, load } from 'js-yaml'
99
import { omit } from 'lodash'
10-
import * as pathModule from 'path'
1110
import { dirname, join, resolve } from 'path'
1211
import { $, ProcessOutput, within } from 'zx'
1312
import { operatorEnv } from '../operator/validators'
@@ -207,25 +206,14 @@ export const getSchemaSecretsPaths = async (teams: string[]): Promise<string[]>
207206
return cleanSecretPaths
208207
}
209208

210-
async function ensureKeepFile(keepFilePath: string, deps = { writeFile }): Promise<void> {
211-
const dirPath = dirname(keepFilePath)
212-
if (!existsSync(dirPath)) {
213-
await $`mkdir -p ${dirname(keepFilePath)}`
214-
}
215-
if (existsSync(keepFilePath)) return
216-
// create the .keep file
217-
await deps.writeFile(keepFilePath, '')
218-
}
219-
220-
export function ensureManifestDirectories(): void {
221-
;[operatorEnv.GITOPS_MANIFESTS_NS_PATH, operatorEnv.GITOPS_MANIFESTS_GLOBAL_PATH].forEach((p) =>
222-
ensureDirectoryWithGitkeepAsync(pathModule.join(env.ENV_DIR, p)),
223-
)
209+
export async function ensureManifestDirectories(): Promise<void> {
210+
await ensureDirectoryWithGitkeepAsync(join(env.ENV_DIR, operatorEnv.GITOPS_MANIFESTS_NS_RELATIVE_DIR_PATH))
211+
await ensureDirectoryWithGitkeepAsync(join(env.ENV_DIR, operatorEnv.GITOPS_GLOBAL_MANIFESTS_RELATIVE_PATH))
224212
}
225213

226-
async function ensureDirectoryWithGitkeepAsync(dirPath: string, deps = { fs, path: pathModule }) {
214+
async function ensureDirectoryWithGitkeepAsync(dirPath: string, deps = { fs }) {
227215
await deps.fs.promises.mkdir(dirPath, { recursive: true })
228-
const gitkeepPath = deps.path.join(dirPath, '.gitkeep')
216+
const gitkeepPath = join(dirPath, '.gitkeep')
229217

230218
try {
231219
await deps.fs.promises.access(gitkeepPath)
@@ -234,11 +222,7 @@ async function ensureDirectoryWithGitkeepAsync(dirPath: string, deps = { fs, pat
234222
}
235223
}
236224

237-
export async function ensureTeamGitOpsDirectories(
238-
envDir: string,
239-
values: Record<string, any>,
240-
deps = { fs, path: pathModule, glob },
241-
) {
225+
export async function ensureTeamGitOpsDirectories(envDir: string, values: Record<string, any>, deps = { fs, glob }) {
242226
const dirs = await deps.glob(`${envDir}/env/teams/*`)
243227
const baseGitOpsDirs = ['sealedsecrets', 'workloadValues']
244228
const aiGitOpsDirs = ['databases', 'knowledgebases', 'agents']

src/operator/validators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ dotenv.config()
66
export const operatorEnv = cleanEnv(process.env, {
77
GIT_ORG: str({ desc: 'Git organisation', default: 'otomi' }),
88
GIT_REPO: str({ desc: 'Git repository', default: 'values' }),
9-
GITOPS_MANIFESTS_NS_PATH: str({
9+
GITOPS_MANIFESTS_NS_RELATIVE_DIR_PATH: str({
1010
desc: 'Path to the gitops manifests namespace',
1111
default: 'env/manifests/namespaces',
1212
}),
13-
GITOPS_MANIFESTS_GLOBAL_PATH: str({
13+
GITOPS_GLOBAL_MANIFESTS_RELATIVE_PATH: str({
1414
desc: 'Path to the gitops manifests global',
1515
default: 'env/manifests/global',
1616
}),

0 commit comments

Comments
 (0)