Skip to content

Commit f3b5745

Browse files
ElderMattj-zimnowodasvcAPLBotmerll
authored
feat: service page using new components (#1996)
Co-authored-by: jeho <[email protected]> Co-authored-by: svcAPLBot <[email protected]> Co-authored-by: merll <[email protected]>
1 parent 9be7903 commit f3b5745

38 files changed

+112
-169
lines changed

helmfile.d/snippets/blackbox-targets.gotmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{{- $registry := list }}
22
{{- range $s := .services }}
3-
{{- $type := $s.type | default "auth" }}
4-
{{- if and (eq $type "public") (not ($s | get "ksvc.scaleToZero" false)) }}
3+
{{- if (not ($s | get "ksvc.scaleToZero" false)) }}
54
{{- $host := (printf "%s-%s" $s.name $.teamId) }}
65
{{- $svcDomain := ($s | get "domain" (printf "%s.%s" $host $.domain)) }}
76
{{- $paths:= $s | get "paths" list }}

helmfile.d/snippets/defaults.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,4 +1350,4 @@ environments:
13501350
version: main
13511351
# TODO: update this when schema version changes
13521352
versions:
1353-
specVersion: 38
1353+
specVersion: 39

src/cmd/migrate.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('Upgrading values', () => {
1616
teamConfig: {
1717
teamA: {
1818
services: [
19-
{ name: 'svc1', prop: 'replaceMe', bla: [{ ok: 'replaceMe' }] },
20-
{ name: 'svc1', prop: 'replaceMe', di: [{ ok: 'replaceMeNot' }] },
19+
{ name: 'svc1', prop: 'replaceMe', bla: [{ ok: 'replaceMe' }], type: 'cluster' },
20+
{ name: 'svc2', prop: 'replaceMe', di: [{ ok: 'replaceMeNot' }], type: 'public' },
2121
],
2222
},
2323
},
@@ -43,11 +43,19 @@ describe('Upgrading values', () => {
4343
],
4444
renamings: [{ 'somefile.yaml': 'newloc.yaml' }],
4545
},
46+
{
47+
version: 4,
48+
deletions: [
49+
// { 'some.k8sVersion': 'printf "v%s" .prev' },
50+
'teamConfig.{team}.services[].type',
51+
// { 'teamConfig.{team}.services[].bla[].ok': 'print .prev "ee"' },
52+
],
53+
},
4654
]
4755

4856
describe('Filter changes', () => {
4957
it('should only select changes whose version >= current version', () => {
50-
expect(filterChanges(oldVersion, mockChanges)).toEqual(mockChanges.slice(1, 3))
58+
expect(filterChanges(oldVersion, mockChanges)).toEqual(mockChanges.slice(1, 4))
5159
})
5260
})
5361
describe('Apply changes to values', () => {
@@ -66,12 +74,12 @@ describe('Upgrading values', () => {
6674
teamA: {
6775
services: [
6876
{ name: 'svc1', prop: 'replaced', bla: [{ ok: 'replaceMe' }] },
69-
{ name: 'svc1', prop: 'replaced', di: [{ ok: 'replaceMeNot' }] },
77+
{ name: 'svc2', prop: 'replaced', di: [{ ok: 'replaceMeNot' }] },
7078
],
7179
},
7280
},
7381
some: { bla: {}, k8sVersion: '1.18' },
74-
versions: { specVersion: 3 },
82+
versions: { specVersion: 4 },
7583
},
7684
true,
7785
)

src/cmd/migrate.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,40 @@ export const applyChanges = async (
513513

514514
export const unparsePaths = (path: string, values: Record<string, any>): Array<string> => {
515515
if (path.includes('{team}')) {
516-
const paths: Array<string> = []
516+
let paths: Array<string> = []
517517
const teams: Array<string> = Object.keys(values?.teamConfig as Record<string, any>)
518518
teams.forEach((teamName) => paths.push(path.replace('{team}', teamName)))
519+
paths = transformArrayToPaths(paths, values)
519520
return paths.sort()
520521
} else {
521-
return [path]
522+
const paths = transformArrayToPaths([path], values)
523+
return paths
522524
}
523525
}
526+
527+
function transformArrayToPaths(paths: string[], values: Record<string, any>): string[] {
528+
const transformedPaths: string[] = []
529+
530+
paths.forEach((path) => {
531+
const match = path.match(/^(.*)\.(\w+)\[\](.*)$/)
532+
if (!match) {
533+
transformedPaths.push(path)
534+
return
535+
}
536+
537+
const [, beforeArrayPath, arrayKey, afterArrayPath] = match
538+
539+
const objectPath = beforeArrayPath.split('.').reduce((obj, key) => obj?.[key], values)
540+
541+
if (objectPath && objectPath[arrayKey]) {
542+
objectPath[arrayKey].forEach((_item: any, index: number) => {
543+
transformedPaths.push(`${beforeArrayPath}.${arrayKey}[${index}]${afterArrayPath}`)
544+
})
545+
}
546+
})
547+
548+
return transformedPaths
549+
}
524550
export const unsetAtPath = (path: string, values: Record<string, any>): void => {
525551
const paths = unparsePaths(path, values)
526552
paths.forEach((p) => unset(values, p))
@@ -674,12 +700,10 @@ export const migrate = async (): Promise<boolean> => {
674700
const versions = await loadYaml(`${env.ENV_DIR}/env/settings/versions.yaml`, { noError: true })
675701
const prevVersion: number = versions?.spec?.specVersion
676702
if (!prevVersion) {
677-
d.log('No changes detected, skipping')
703+
d.log('No previous version detected')
678704
return false
679705
}
680-
681706
const filteredChanges = filterChanges(prevVersion, changes)
682-
683707
if (filteredChanges.length) {
684708
d.log(
685709
`Changes detected, migrating from ${prevVersion} to ${

src/common/values.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export const getRepo = (values: Record<string, any>): Repo => {
102102
return { remote, branch, email, username, password }
103103
}
104104

105+
function mergeCustomizer(prev, next) {
106+
return next
107+
}
108+
105109
let hasSops = false
106110
/**
107111
* Writes new values to a file. Will keep the original values if `overwrite` is `false`.
@@ -121,9 +125,7 @@ export const writeValuesToFile = async (
121125
const values = cloneDeep(inValues)
122126
const originalValues = (await loadYaml(targetPath + suffix, { noError: true })) ?? {}
123127
d.debug('originalValues: ', JSON.stringify(originalValues, null, 2))
124-
const mergeResult = mergeWith(cloneDeep(originalValues), values, (prev, next) => {
125-
return next
126-
})
128+
const mergeResult = mergeWith(cloneDeep(originalValues), values, mergeCustomizer)
127129
const cleanedValues = removeBlankAttributes(values)
128130
const cleanedMergeResult = removeBlankAttributes(mergeResult)
129131
if (((overwrite && isEmpty(cleanedValues)) || (!overwrite && isEmpty(cleanedMergeResult))) && isSecretsFile) {
@@ -147,6 +149,7 @@ export const writeValuesToFile = async (
147149
return
148150
}
149151
}
152+
150153
if (isEqual(originalValues, useValues)) {
151154
d.info(`No changes for ${targetPath}${suffix}, skipping...`)
152155
return

tests/bootstrap/input-local-dev.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ teamConfig:
5858
name: httpbin
5959
ownHost: true
6060
port: 80
61-
type: public
6261
- id: a106eb22-8c06-41b6-ab15-97aafb0888b5
6362
ingressClassName: platform
6463
name: nginx-deployment
6564
ownHost: true
6665
paths: []
6766
port: 80
68-
type: public
6967
- id: 91f6af98-ad8e-4111-b916-cf1b5bdcafb0
7068
ingressClassName: platform
7169
ksvc:
@@ -74,7 +72,6 @@ teamConfig:
7472
ownHost: true
7573
paths: []
7674
port: 80
77-
type: public
7875
workloads:
7976
- name: nodejs-helloworld
8077
url: https://github.com/linode/apl-nodejs-helloworld.git

tests/bootstrap/input.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ teamConfig:
5757
name: httpbin
5858
ownHost: true
5959
port: 80
60-
type: public
6160
- id: a106eb22-8c06-41b6-ab15-97aafb0888b5
6261
ingressClassName: platform
6362
name: nginx-deployment
6463
ownHost: true
6564
paths: []
6665
port: 80
67-
type: public
6866
- id: 91f6af98-ad8e-4111-b916-cf1b5bdcafb0
6967
ingressClassName: platform
7068
ksvc:
@@ -73,7 +71,6 @@ teamConfig:
7371
ownHost: true
7472
paths: []
7573
port: 80
76-
type: public
7774
workloads:
7875
- name: nodejs-helloworld
7976
url: https://github.com/linode/apl-nodejs-helloworld.git

tests/fixtures/env/apps/loki.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ metadata:
33
name: loki
44
labels: {}
55
spec:
6+
_rawValues: {}
67
autoscaling:
78
distributor:
89
enabled: true
@@ -94,4 +95,3 @@ spec:
9495
duration: 24h
9596
period: 24h
9697
v11StartDate: 2021-05-13T00:00:00.000Z
97-
_rawValues: {}

tests/fixtures/env/settings/versions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ metadata:
33
name: versions
44
labels: {}
55
spec:
6-
specVersion: 35
6+
specVersion: 39

tests/fixtures/env/teams/admin/services/hello-admin.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ spec:
88
domain: hello.team-admin.dev.linode-apl.net
99
ownHost: true
1010
port: 80
11-
type: public

0 commit comments

Comments
 (0)