Skip to content
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
828e64c
feat: remove type from service
ElderMatt Mar 3, 2025
5f30c67
feat: versions
ElderMatt Mar 10, 2025
4949ebe
feat: removed type checks
ElderMatt Mar 10, 2025
c75c61a
fix: remove type from integrations
ElderMatt Mar 10, 2025
69de771
Merge branch 'main' into APL-537
ElderMatt Mar 10, 2025
78d165a
fix: change values-schema to 32
ElderMatt Mar 13, 2025
5ac22b1
Merge branch 'main' into APL-537
ElderMatt Mar 14, 2025
40791d6
fix: change version to 34
ElderMatt Mar 14, 2025
810871b
fix: changed version to 34
ElderMatt Mar 14, 2025
b37c51a
fix: version 34 deletions
ElderMatt Mar 14, 2025
2ae0f9b
Merge branch 'main' into APL-537
ElderMatt Mar 18, 2025
01fa5f3
fix: remove type from services
ElderMatt Mar 19, 2025
32d1aaf
Merge branch 'main' into APL-537
ElderMatt Mar 19, 2025
9252d53
fix: values changes
ElderMatt Mar 21, 2025
22e82c0
fix: schemachange
ElderMatt Mar 21, 2025
43a731d
feat: allow array deletion in the values changes
ElderMatt Mar 21, 2025
72c0f44
fix: values changes
ElderMatt Mar 21, 2025
e7a6b17
feat: update specversion
ElderMatt Mar 21, 2025
c90584e
fix: debug migrate
ElderMatt Mar 21, 2025
549e756
fix: path to yaml files
ElderMatt Mar 24, 2025
e959bb6
fix: env and previous version
ElderMatt Mar 24, 2025
b169c7d
fix: logging
ElderMatt Mar 24, 2025
5bb90c9
fix: logging services
ElderMatt Mar 24, 2025
c0c0814
fix: logging three
ElderMatt Mar 24, 2025
e8eb7ec
fix: log manifest
ElderMatt Mar 24, 2025
75c9e15
fix: logging four
ElderMatt Mar 25, 2025
0d2428c
fix: overwrite instead of merge
ElderMatt Mar 25, 2025
d04b42f
feat: mergewith
ElderMatt Mar 31, 2025
02a96f0
Merge branch 'main' into APL-537
ElderMatt Apr 4, 2025
e9ec64a
Merge branch 'main' into APL-537
ElderMatt Apr 14, 2025
588f213
fix: fixtures and tests
ElderMatt Apr 14, 2025
edac3ae
fix: use correct api branch
ElderMatt Apr 14, 2025
868f049
Merge branch 'main' into APL-537
j-zimnowoda Apr 15, 2025
c561a8f
fix: remove logs and files
ElderMatt Apr 15, 2025
c73cfc1
fix: rename function isarray
ElderMatt Apr 15, 2025
116c351
Merge branch 'main' into APL-537
ElderMatt Apr 16, 2025
2488ae0
fix: delete old netpols
ElderMatt Apr 16, 2025
95041ff
Merge branch 'main' into APL-537
ElderMatt Apr 16, 2025
3008827
Merge remote-tracking branch 'origin/main' into APL-537
svcAPLBot Apr 16, 2025
f33c0e4
fix: updated specVersion
ElderMatt Apr 16, 2025
3590fa0
chore: merge main into branch
ElderMatt Apr 17, 2025
b173df6
Merge branch 'main' into APL-537
ElderMatt Apr 17, 2025
b15f7ee
Merge remote-tracking branch 'origin/main' into APL-537
svcAPLBot Apr 17, 2025
86aa8a4
fix: fixtures
ElderMatt Apr 17, 2025
52d2ab7
Merge remote-tracking branch 'origin/main' into APL-537
svcAPLBot Apr 17, 2025
cea36c8
fix: remove logs
ElderMatt Apr 22, 2025
b8c9bb4
Merge remote-tracking branch 'origin/main' into APL-537
svcAPLBot Apr 22, 2025
2fe158a
fix: removed logs
ElderMatt Apr 23, 2025
209dd01
Update versions.yaml
ElderMatt Apr 23, 2025
7355487
Update src/cmd/migrate.ts
ElderMatt Apr 23, 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
3 changes: 1 addition & 2 deletions helmfile.d/snippets/blackbox-targets.gotmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{- $registry := list }}
{{- range $s := .services }}
{{- $type := $s.type | default "auth" }}
{{- if and (eq $type "public") (not ($s | get "ksvc.scaleToZero" false)) }}
{{- if (not ($s | get "ksvc.scaleToZero" false)) }}
{{- $host := (printf "%s-%s" $s.name $.teamId) }}
{{- $svcDomain := ($s | get "domain" (printf "%s.%s" $host $.domain)) }}
{{- $paths:= $s | get "paths" list }}
Expand Down
18 changes: 13 additions & 5 deletions src/cmd/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('Upgrading values', () => {
teamConfig: {
teamA: {
services: [
{ name: 'svc1', prop: 'replaceMe', bla: [{ ok: 'replaceMe' }] },
{ name: 'svc1', prop: 'replaceMe', di: [{ ok: 'replaceMeNot' }] },
{ name: 'svc1', prop: 'replaceMe', bla: [{ ok: 'replaceMe' }], type: 'cluster' },
{ name: 'svc2', prop: 'replaceMe', di: [{ ok: 'replaceMeNot' }], type: 'public' },
],
},
},
Expand All @@ -43,11 +43,19 @@ describe('Upgrading values', () => {
],
renamings: [{ 'somefile.yaml': 'newloc.yaml' }],
},
{
version: 4,
deletions: [
// { 'some.k8sVersion': 'printf "v%s" .prev' },
'teamConfig.{team}.services[].type',
// { 'teamConfig.{team}.services[].bla[].ok': 'print .prev "ee"' },
],
},
]

describe('Filter changes', () => {
it('should only select changes whose version >= current version', () => {
expect(filterChanges(oldVersion, mockChanges)).toEqual(mockChanges.slice(1, 3))
expect(filterChanges(oldVersion, mockChanges)).toEqual(mockChanges.slice(1, 4))
})
})
describe('Apply changes to values', () => {
Expand All @@ -66,12 +74,12 @@ describe('Upgrading values', () => {
teamA: {
services: [
{ name: 'svc1', prop: 'replaced', bla: [{ ok: 'replaceMe' }] },
{ name: 'svc1', prop: 'replaced', di: [{ ok: 'replaceMeNot' }] },
{ name: 'svc2', prop: 'replaced', di: [{ ok: 'replaceMeNot' }] },
],
},
},
some: { bla: {}, k8sVersion: '1.18' },
versions: { specVersion: 3 },
versions: { specVersion: 4 },
},
true,
)
Expand Down
35 changes: 31 additions & 4 deletions src/cmd/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,40 @@ export const applyChanges = async (

export const unparsePaths = (path: string, values: Record<string, any>): Array<string> => {
if (path.includes('{team}')) {
const paths: Array<string> = []
let paths: Array<string> = []
const teams: Array<string> = Object.keys(values?.teamConfig as Record<string, any>)
teams.forEach((teamName) => paths.push(path.replace('{team}', teamName)))
paths = transformArrayToPaths(paths, values)
return paths.sort()
} else {
return [path]
const paths = transformArrayToPaths([path], values)
return paths
}
}

function transformArrayToPaths(paths: string[], values: Record<string, any>): string[] {
const transformedPaths: string[] = []

paths.forEach((path) => {
const match = path.match(/^(.*)\.(\w+)\[\](.*)$/)
if (!match) {
transformedPaths.push(path)
return
}

const [, beforeArrayPath, arrayKey, afterArrayPath] = match

const objectPath = beforeArrayPath.split('.').reduce((obj, key) => obj?.[key], values)

if (objectPath && objectPath[arrayKey]) {
objectPath[arrayKey].forEach((_item: any, index: number) => {
transformedPaths.push(`${beforeArrayPath}.${arrayKey}[${index}]${afterArrayPath}`)
})
}
})

return transformedPaths
}
export const unsetAtPath = (path: string, values: Record<string, any>): void => {
const paths = unparsePaths(path, values)
paths.forEach((p) => unset(values, p))
Expand Down Expand Up @@ -610,12 +636,13 @@ export const migrate = async (): Promise<boolean> => {
const versions = await loadYaml(`${env.ENV_DIR}/env/settings/versions.yaml`, { noError: true })
const prevVersion: number = versions?.spec?.specVersion
if (!prevVersion) {
d.log('No previous version detected')
d.log('No changes detected, skipping')
return false
}

d.log('PREVIOUS VERSION: ', prevVersion)
const filteredChanges = filterChanges(prevVersion, changes)

d.log('FILTEREDCHANGES', filteredChanges)
if (filteredChanges.length) {
d.log(
`Changes detected, migrating from ${prevVersion} to ${
Expand Down
2 changes: 2 additions & 0 deletions src/common/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ export async function saveResourceGroupToFiles(
try {
const filePath = getFilePath(fileMap, nodePath, nodeValue, '')
const manifest = renderManifest(fileMap, nodePath, nodeValue)
console.log('filepath: ', filePath)
console.log('manifest: ', manifest)
await deps.writeValuesToFile(filePath, manifest)
} catch (e) {
console.log(nodePath)
Expand Down
9 changes: 7 additions & 2 deletions src/common/values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { pathExists } from 'fs-extra'
import { mkdir, unlink, writeFile } from 'fs/promises'
import { cloneDeep, get, isEmpty, isEqual, merge, omit, pick, set } from 'lodash'
import { cloneDeep, get, isEmpty, isEqual, merge, mergeWith, omit, pick, set } from 'lodash'
import path from 'path'
import { supportedK8sVersions } from 'src/supportedK8sVersions.json'
import { stringify } from 'yaml'
Expand Down Expand Up @@ -102,6 +102,10 @@ export const getRepo = (values: Record<string, any>): Repo => {
return { remote, branch, email, username, password }
}

function mergeCustomizer(prev, next) {
return next
}

let hasSops = false
/**
* Writes new values to a file. Will keep the original values if `overwrite` is `false`.
Expand All @@ -121,7 +125,7 @@ export const writeValuesToFile = async (
const values = cloneDeep(inValues)
const originalValues = (await loadYaml(targetPath + suffix, { noError: true })) ?? {}
d.debug('originalValues: ', JSON.stringify(originalValues, null, 2))
const mergeResult = merge(cloneDeep(originalValues), values)
const mergeResult = mergeWith(cloneDeep(originalValues), values, mergeCustomizer)
const cleanedValues = removeBlankAttributes(values)
const cleanedMergeResult = removeBlankAttributes(mergeResult)
if (((overwrite && isEmpty(cleanedValues)) || (!overwrite && isEmpty(cleanedMergeResult))) && isSecretsFile) {
Expand All @@ -145,6 +149,7 @@ export const writeValuesToFile = async (
return
}
}

if (isEqual(originalValues, useValues)) {
d.info(`No changes for ${targetPath}${suffix}, skipping...`)
return
Expand Down
3 changes: 0 additions & 3 deletions tests/bootstrap/input-local-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ teamConfig:
name: httpbin
ownHost: true
port: 80
type: public
- id: a106eb22-8c06-41b6-ab15-97aafb0888b5
ingressClassName: platform
name: nginx-deployment
ownHost: true
paths: []
port: 80
type: public
- id: 91f6af98-ad8e-4111-b916-cf1b5bdcafb0
ingressClassName: platform
ksvc:
Expand All @@ -74,7 +72,6 @@ teamConfig:
ownHost: true
paths: []
port: 80
type: public
workloads:
- name: nodejs-helloworld
url: https://github.com/linode/apl-nodejs-helloworld.git
Expand Down
3 changes: 0 additions & 3 deletions tests/bootstrap/input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ teamConfig:
name: httpbin
ownHost: true
port: 80
type: public
- id: a106eb22-8c06-41b6-ab15-97aafb0888b5
ingressClassName: platform
name: nginx-deployment
ownHost: true
paths: []
port: 80
type: public
- id: 91f6af98-ad8e-4111-b916-cf1b5bdcafb0
ingressClassName: platform
ksvc:
Expand All @@ -73,7 +71,6 @@ teamConfig:
ownHost: true
paths: []
port: 80
type: public
workloads:
- name: nodejs-helloworld
url: https://github.com/linode/apl-nodejs-helloworld.git
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/env/apps/loki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ metadata:
name: loki
labels: {}
spec:
_rawValues: {}
autoscaling:
distributor:
enabled: true
Expand Down Expand Up @@ -94,4 +95,3 @@ spec:
duration: 24h
period: 24h
v11StartDate: 2021-05-13T00:00:00.000Z
_rawValues: {}
2 changes: 1 addition & 1 deletion tests/fixtures/env/settings/versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ metadata:
name: versions
labels: {}
spec:
specVersion: 35
specVersion: 36
1 change: 0 additions & 1 deletion tests/fixtures/env/teams/admin/services/hello-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ spec:
domain: hello.team-admin.dev.linode-apl.net
ownHost: true
port: 80
type: public
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ metadata:
apl.io/teamId: demo
spec:
externalRepo: false
imageName: demo-java1
mode:
docker:
path: ./Dockerfile
repoUrl: https://github.com/buildpacks/samples
revision: HEAD
type: docker
name: demo-java1-v0-0-1
imageName: demo-java1
scanSource: true
tag: v0.0.1
trigger: false
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
apl.io/teamId: demo
spec:
externalRepo: false
imageName: demo-java2
mode:
buildpacks:
envVars:
Expand All @@ -16,8 +17,6 @@ spec:
repoUrl: https://github.com/buildpacks/samples
revision: HEAD
type: buildpacks
name: demo-java2-v0-0-1
imageName: demo-java2
scanSource: false
tag: v0.0.1
trigger: false
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
apl.io/teamId: demo
spec:
externalRepo: true
imageName: demo-java3
mode:
docker:
envVars:
Expand All @@ -16,8 +17,6 @@ spec:
repoUrl: https://github.com/buildpacks/samples
revision: HEAD
type: docker
name: demo-java3-v0-0-1
imageName: demo-java3
scanSource: true
secretName: my-secret
tag: v0.0.1
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/env/teams/demo/services/has-cert-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ spec:
hasCert: true
paths:
- /jeho
type: public
1 change: 0 additions & 1 deletion tests/fixtures/env/teams/demo/services/hello-auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ spec:
ownHost: true
paths: []
port: 80
type: public
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ spec:
enabled: true
weightV1: 90
weightV2: 10
type: public
useCname: false
1 change: 0 additions & 1 deletion tests/fixtures/env/teams/demo/services/hello.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ spec:
enabled: true
weightV1: 70
weightV2: 30
type: public
useCname: true
3 changes: 1 addition & 2 deletions tests/fixtures/env/teams/demo/services/service-a.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ metadata:
name: service-a
labels:
apl.io/teamId: demo
spec:
type: cluster
spec: {}
7 changes: 0 additions & 7 deletions tests/fixtures/env/teams/demo/services/service-b.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions tests/fixtures/env/teams/demo/services/service-d.yaml

This file was deleted.

1 change: 0 additions & 1 deletion tests/fixtures/env/teams/demo/services/service-e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ spec:
enabled: true
weightV1: 50
weightV2: 50
type: public
useCname: true
8 changes: 0 additions & 8 deletions tests/fixtures/env/teams/demo/services/some-svc.yaml

This file was deleted.

1 change: 0 additions & 1 deletion tests/fixtures/env/teams/demo/services/tlspass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ spec:
predeployed: true
port: 443
tlsPass: true
type: public
8 changes: 2 additions & 6 deletions tests/fixtures/env/teams/demo/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ metadata:
apl.io/teamId: demo
spec:
alerts:
email:
critical: [email protected]
nonCritical: [email protected]
email: {}
groupInterval: 5m
receivers:
- slack
repeatInterval: 3h
slack:
channel: aaaaa
channelCrit: aaaaa
url: https://slack.con
groupInterval: 5m
managedMonitoring:
alertmanager: true
grafana: true
Expand All @@ -40,4 +37,3 @@ spec:
- ingress
team:
- alerts
password: somesecretvalue
Loading