Skip to content

feat: rely solely on metadata name #2040

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

Merged
merged 34 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2be2b14
feat: load id and name
j-zimnowoda Apr 3, 2025
9ee40db
Merge remote-tracking branch 'origin/main' into load-ids-from-metadata
j-zimnowoda Apr 3, 2025
08cda49
feat: remove name property from spec in fixtures
j-zimnowoda Apr 3, 2025
79d07e6
feat: remove teamId property from spec in fixtures
j-zimnowoda Apr 3, 2025
1da5efa
feat: remove id property from spec in fixtures
j-zimnowoda Apr 3, 2025
8f83c8b
feat: add name property to spec while loading
j-zimnowoda Apr 3, 2025
1184c55
feat: add name property to spec while loading
j-zimnowoda Apr 3, 2025
e18678d
Merge branch 'main' into APL-612
merll Apr 8, 2025
9919042
Merge remote-tracking branch 'origin/main' into APL-612
j-zimnowoda Apr 8, 2025
daf1b4e
Merge remote-tracking branch 'origin/main' into APL-612
j-zimnowoda Apr 9, 2025
c2077d0
ci: ignore order changes while using dyff
j-zimnowoda Apr 9, 2025
cd4c4c8
feat: load name to spec for arrayItems
j-zimnowoda Apr 9, 2025
4478eb3
feat: log sops errors
j-zimnowoda Apr 9, 2025
2d3188b
feat: remove teamId, name, and id from spec
j-zimnowoda Apr 9, 2025
fd049e1
ci: remove old secret
j-zimnowoda Apr 9, 2025
6d523ab
Merge branch 'main' into APL-612
j-zimnowoda Apr 9, 2025
c92ceb9
feat: use user name instead of user id
j-zimnowoda Apr 9, 2025
deed949
feat: use user name instead of user id
j-zimnowoda Apr 9, 2025
6f754b2
ci: debug bootstrap tests/fixtures
j-zimnowoda Apr 9, 2025
243cb20
ci: bootstrap tests fixtures
j-zimnowoda Apr 9, 2025
b99470e
ci: bootstrap tests fixtures
j-zimnowoda Apr 9, 2025
b1ca83d
Merge remote-tracking branch 'origin/APL-612' into APL-612
j-zimnowoda Apr 9, 2025
ae59a7b
fix: get user name from file name
j-zimnowoda Apr 9, 2025
2478ee3
fix: wring user name
j-zimnowoda Apr 9, 2025
fcb38b8
test: add unit
j-zimnowoda Apr 9, 2025
d13a2f1
fix: rework
j-zimnowoda Apr 11, 2025
258daf0
Merge branch 'main' into APL-612
j-zimnowoda Apr 11, 2025
1f1a081
fix: rework
j-zimnowoda Apr 11, 2025
8a648d8
Merge branch 'APL-612' of https://github.com/linode/apl-core into APL…
j-zimnowoda Apr 11, 2025
f5c8168
ci: fixtures for local dev
j-zimnowoda Apr 11, 2025
33f30fb
fix: rework
j-zimnowoda Apr 11, 2025
bcb6a9a
Merge remote-tracking branch 'origin/main' into APL-612
j-zimnowoda Apr 11, 2025
c7972ec
test: update resource quota
j-zimnowoda Apr 11, 2025
fbb81cd
Merge remote-tracking branch 'origin/main' into APL-612
j-zimnowoda Apr 11, 2025
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
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
"console": "integratedTerminal",
"cwd": "${workspaceRoot}"
},
{
"name": "Bootstrap-test-fixtures",
"request": "launch",
"runtimeArgs": ["run", "bootstrap-tests-fixtures"],
"runtimeExecutable": "npm",
"type": "node",
"envFile": ".env",
"console": "integratedTerminal",
"cwd": "${workspaceRoot}"
},
{
"name": "Migrate values",
"request": "launch",
Expand Down
2 changes: 1 addition & 1 deletion bin/dyff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ echo "$diff_output" | while read -r line; do
# Use dyff to compare the files
dyff between "$second_path" "$first_path" --omit-header \
--exclude "data.tls.key" --exclude "/data/ca.crt" --exclude "/data/tls.crt" --exclude "/data/tls.key" \
--exclude-regexp "/checksum" --exclude-regexp "/webhooks.*"
--exclude-regexp "/checksum" --exclude-regexp "/webhooks.*" --ignore-order-changes
fi
done
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
"validate-templates:all": "set -e; i=29; while [ $i -le 32 ]; do NODE_ENV=test binzx/otomi validate-templates -k 1.$i; i=$(($i+1)); done",
"validate-values": "ENV_DIR=$PWD/tests/fixtures NODE_ENV=test binzx/otomi validate-values",
"bootstrap-dev": "rm -rf /tmp/otomi-bootstrap-dev; CI=1 VALUES_INPUT=$PWD/tests/bootstrap/input-local-dev.yaml ENV_DIR=/tmp/otomi-bootstrap-dev binzx/otomi bootstrap",
"bootstrap-dev-with-repo": "CI=1 ENV_DIR=/tmp/otomi-bootstrap-dev binzx/otomi bootstrap"
"bootstrap-dev-with-repo": "CI=1 ENV_DIR=/tmp/otomi-bootstrap-dev binzx/otomi bootstrap",
"bootstrap-tests-fixtures": "CI=1 ENV_DIR=$PWD/tests/fixtures binzx/otomi bootstrap"
},
"standard-version": {
"skip": {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
deps.addPlatformAdmin(users, domainSuffix)
}
deps.addInitialPasswords(users)
users.forEach((user) => {
set(user, 'id', user.id || randomUUID())
set(user, 'name', user.name || randomUUID())

Check warning on line 227 in src/cmd/bootstrap.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 227 in src/cmd/bootstrap.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 227 in src/cmd/bootstrap.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
})

Check warning on line 228 in src/cmd/bootstrap.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
return users
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { diff } from 'deep-diff'
import { copy, createFileSync, move, pathExists, renameSync, rm } from 'fs-extra'
import { mkdir, readFile, writeFile } from 'fs/promises'
import { glob } from 'glob'
import { cloneDeep, each, get, isObject, mapKeys, mapValues, omit, pick, pull, set, unset } from 'lodash'
import { basename, dirname, join } from 'path'
import { prepareEnvironment } from 'src/common/cli'
Expand All @@ -20,7 +21,6 @@
import { parse } from 'yaml'
import { Argv } from 'yargs'
import { $, cd } from 'zx'
import { glob } from 'glob'
const cmdName = getFilename(__filename)

interface Arguments extends BasicArguments {
Expand Down Expand Up @@ -494,8 +494,8 @@
oldTeams[teamName] = newTeam
})
const users = get(oldValues, 'users', [])
users.forEach((user) => {
set(user, 'id', user.id || randomUUID())
set(user, 'name', user.id || randomUUID())

Check warning on line 498 in src/cmd/migrate.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 498 in src/cmd/migrate.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 498 in src/cmd/migrate.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
})

Check warning on line 499 in src/cmd/migrate.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
oldValues.versions = { specVersion: 1 }
const teamNames = await getTeamNames(env.ENV_DIR)
Expand Down
2 changes: 2 additions & 0 deletions src/common/crypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,31 @@

const processFileChunk = async (crypt: CR, files: string[]): Promise<(ProcessOutput | undefined)[]> => {
const d = terminal(`common:crypt:processFileChunk`)
const commands = files.map(async (file) => {
if (!crypt.condition || (await crypt.condition(file))) {
d.debug(`${crypt.cmd} ${file}`)
try {
d.info(`${crypt.cmd} ${file}`)
const result = await $`${[...crypt.cmd.split(' '), file]}`.quiet()

if (crypt.cmd === CryptType.DECRYPT) {
const outputFile = `${file}.dec`
await writeFile(outputFile, result.stdout)
}

if (crypt.post) {
await crypt.post(file)
}

return result
} catch (error) {
if (error.message.includes('Already encrypted') && (await pathExists(`${file}.dec`))) {
const res = await $`helm secrets encrypt ${file}.dec`
await writeFile(file, res.stdout)
if (crypt.post) await crypt.post(file)
return res
} else {
d.error(error.message)

Check warning on line 85 in src/common/crypt.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 86 in src/common/crypt.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 86 in src/common/crypt.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 86 in src/common/crypt.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 87 in src/common/crypt.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 88 in src/common/crypt.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 88 in src/common/crypt.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
Expand Down
66 changes: 42 additions & 24 deletions src/common/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,29 +400,33 @@

export function renderManifest(fileMap: FileMap, jsonPath: jsonpath.PathComponent[], data: Record<string, any>) {
//TODO remove this custom workaround for workloadValues
const manifest =
fileMap.kind === 'AplTeamWorkloadValues'
? omit(data, ['id', 'name', 'teamId'])
: {
kind: fileMap.kind,
metadata: {
name: getResourceName(fileMap, jsonPath, data),
labels: {},
},
spec: data,
}
let spec = data
if (fileMap.resourceGroup === 'team') {
spec = omit(data, ['id', 'name', 'teamId'])
}
const manifest = {
kind: fileMap.kind,
metadata: {
name: getResourceName(fileMap, jsonPath, data),
labels: {},
},
spec,
}
if (fileMap.resourceGroup === 'team' && fileMap.kind !== 'AplTeamWorkloadValues') {
manifest.metadata.labels['apl.io/teamId'] = getTeamNameFromJsonPath(jsonPath)
}

return manifest
}

export function renderManifestForSecrets(fileMap: FileMap, data: Record<string, any>) {
export function renderManifestForSecrets(fileMap: FileMap, resourceName: string, data: Record<string, any>) {

Check warning on line 422 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return {
kind: fileMap.kind,
metadata: {
name: resourceName,
},
spec: data,
}

Check warning on line 429 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

export async function saveResourceGroupToFiles(
Expand Down Expand Up @@ -455,13 +459,14 @@
}),
)

await Promise.all(
jsonPathsvaluesSecrets.map(async (node) => {
const nodePath = node.path
const nodeValue = node.value
try {
const filePath = getFilePath(fileMap, nodePath, nodeValue, 'secrets.')
const manifest = renderManifestForSecrets(fileMap, nodeValue)
const resourceName = getResourceName(fileMap, nodePath, nodeValue)

Check warning on line 468 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const manifest = renderManifestForSecrets(fileMap, resourceName, nodeValue)

Check warning on line 469 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
await deps.writeValuesToFile(filePath, manifest)
} catch (e) {
console.log(nodePath)
Expand Down Expand Up @@ -554,7 +559,6 @@
if (hasCorrespondingDecryptedFile(filePath, files)) return
promises.push(deps.loadFileToSpec(filePath, fileMap, spec))
})

await Promise.all(promises)
}

Expand All @@ -565,18 +569,32 @@
deps = { loadYaml },
): Promise<void> {
const jsonPath = getJsonPath(fileMap, filePath)
const data = await deps.loadYaml(filePath)
if (fileMap.processAs === 'arrayItem') {
const ref: Record<string, any>[] = get(spec, jsonPath)
ref.push(data?.spec)
} else {
const ref: Record<string, any> = get(spec, jsonPath)
// Decrypted secrets may need to be merged with plain text specs
const newRef = merge(cloneDeep(ref), data?.spec)
set(spec, jsonPath, newRef)
const data = (await deps.loadYaml(filePath)) || {}

try {
if (!filePath.includes('secrets.')) {
if (fileMap.resourceGroup === 'team' && fileMap.processAs === 'arrayItem') {
data.spec.name = data.metadata.name
}
}

Check warning on line 579 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 579 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
if (fileMap.resourceGroup === 'users') {
data.spec.name = data.metadata.name

Check warning on line 581 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 582 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 582 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
if (fileMap.processAs === 'arrayItem') {
const ref: Record<string, any>[] = get(spec, jsonPath)
ref.push(data?.spec)
} else {
const ref: Record<string, any> = get(spec, jsonPath)
// Decrypted secrets may need to be merged with plain text specs
const newRef = merge(cloneDeep(ref), data?.spec)
set(spec, jsonPath, newRef)
}
} catch (e) {
console.log(filePath)
console.log(fileMap)
throw e
}

Check warning on line 596 in src/common/repo.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

export async function getKmsSettings(envDir: string, deps = { loadToSpec }): Promise<Record<string, any>> {
const kmsFiles = getFileMap('AplKms', envDir)
const spec = {}
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ core.yaml
*.sample
.env
env/status.yaml
values-repo.yaml
env/bootstrap.yaml
values-repo.yaml
9 changes: 9 additions & 0 deletions tests/fixtures/env/apps/alertmanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ metadata:
labels: {}
spec:
enabled: true
_rawValues: {}
resources:
alertmanager:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 10m
memory: 64Mi
14 changes: 14 additions & 0 deletions tests/fixtures/env/apps/apl-gitea-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: AplApp
metadata:
name: apl-gitea-operator
labels: {}
spec:
_rawValues: {}
resources:
operator:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: 50m
memory: 128Mi
14 changes: 14 additions & 0 deletions tests/fixtures/env/apps/apl-harbor-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: AplApp
metadata:
name: apl-harbor-operator
labels: {}
spec:
_rawValues: {}
resources:
operator:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: 50m
memory: 128Mi
14 changes: 14 additions & 0 deletions tests/fixtures/env/apps/apl-keycloak-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: AplApp
metadata:
name: apl-keycloak-operator
labels: {}
spec:
_rawValues: {}
resources:
operator:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: 50m
memory: 128Mi
11 changes: 11 additions & 0 deletions tests/fixtures/env/apps/argocd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ spec:
enabled: true
maxReplicas: 5
minReplicas: 1
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
server:
enabled: true
maxReplicas: 5
minReplicas: 1
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
resources:
applicationSet:
limits:
Expand Down Expand Up @@ -62,3 +66,10 @@ spec:
requests:
cpu: 50m
memory: 256M
_rawValues: {}
applicationSet:
replicas: 1
controller:
replicas: 1
controllerOperationProcessors: 10
controllerStatusProcessors: 20
30 changes: 30 additions & 0 deletions tests/fixtures/env/apps/cert-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,33 @@ metadata:
spec:
externallyManagedTlsSecretName: mysecret
issuer: externally-managed-tls-secret
_rawValues: {}
resources:
cainjector:
limits:
cpu: 200m
memory: 1Gi
requests:
cpu: 50m
memory: 384Mi
certManager:
limits:
cpu: '1'
memory: 512Mi
requests:
cpu: 50m
memory: 128Mi
startupapicheck:
limits:
cpu: 200m
memory: 384Mi
requests:
cpu: 50m
memory: 64Mi
webhook:
limits:
cpu: 100m
memory: 256Mi
requests:
cpu: 50m
memory: 64Mi
1 change: 1 addition & 0 deletions tests/fixtures/env/apps/cnpg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ spec:
requests:
cpu: 100m
memory: 200Mi
_rawValues: {}
2 changes: 2 additions & 0 deletions tests/fixtures/env/apps/drone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ spec:
server: https://gitea.demo.eks.otomi.cloud
github: {}
provider: gitea
username: otomi-admin
trace: false
13 changes: 13 additions & 0 deletions tests/fixtures/env/apps/external-dns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: AplApp
metadata:
name: external-dns
labels: {}
spec:
logLevel: info
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 10m
memory: 64Mi
Loading