Skip to content

Commit 142837d

Browse files
authored
feat: remove team jobs (#1665)
1 parent 6d5ad13 commit 142837d

File tree

12 files changed

+42
-203
lines changed

12 files changed

+42
-203
lines changed

.values/env/settings.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: 25
1+
version: 27

.vscode/launch.json

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@
6666
"envFile": ".env",
6767
"console": "integratedTerminal",
6868
"cwd": "${workspaceRoot}"
69+
},
70+
{
71+
"name": "Migrate values",
72+
"request": "launch",
73+
"runtimeArgs": ["run", "migrate-values"],
74+
"runtimeExecutable": "npm",
75+
"type": "node",
76+
"envFile": ".env",
77+
"console": "integratedTerminal",
78+
"cwd": "${workspaceRoot}"
6979
}
7080
]
7181
}

helmfile.d/helmfile-60.teams.yaml

-24
Original file line numberDiff line numberDiff line change
@@ -254,28 +254,4 @@ releases:
254254
svc: prometheus-blackbox-exporter
255255
port: 9115
256256
{{- end }}
257-
{{- range $job := $team | get "jobs" list }}
258-
- name: job-{{ $teamId }}-{{ $job.name }}
259-
installed: {{ $job.enabled }}
260-
namespace: team-{{ $teamId }}
261-
chart: ../charts/jobs
262-
labels:
263-
group: jobs
264-
tag: teams
265-
team: {{ $teamId }}
266-
pipeline: otomi-task-teams
267-
hooks:
268-
- events: [presync]
269-
showlogs: true
270-
command: ../bin/job-presync.sh
271-
args:
272-
- job-{{ $teamId }}-{{ $job.name }}
273-
{{- if hasKey $job "runPolicy" }}
274-
- "{{ $job.runPolicy }}"
275-
{{- end }}
276-
values:
277-
- teamSecrets: {{- $team | get "secrets" nil | toYaml | nindent 10 }}
278-
teamId: {{ $teamId }}
279-
- {{- $job | toYaml | nindent 8 }}
280-
{{- end }}
281257
{{- end }}

helmfile.d/snippets/defaults.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -785,4 +785,4 @@ environments:
785785
upgrade:
786786
version: main
787787
# TODO: update this when schema version changes: (and think more?)
788-
version: 26
788+
version: 27

src/cmd/migrate.ts

+24
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface Change {
2828
clones?: Array<{
2929
[targetPath: string]: string
3030
}>
31+
fileDeletions?: Array<string>
3132
deletions?: Array<string>
3233
relocations?: Array<{
3334
[oldLocation: string]: string
@@ -50,6 +51,22 @@ interface Change {
5051

5152
export type Changes = Array<Change>
5253

54+
export const deleteFile = async (
55+
relativeFilePath: string,
56+
dryRun = false,
57+
deps = { pathExists, renameSync, terminal, copy, rm },
58+
): Promise<void> => {
59+
const d = deps.terminal(`cmd:${cmdName}:rename`)
60+
const path = `${env.ENV_DIR}/${relativeFilePath}`
61+
if (!(await deps.pathExists(path))) {
62+
d.warn(`File does not exist: "${path}". Already removed?`)
63+
return
64+
}
65+
if (!dryRun) {
66+
await deps.rm(path)
67+
}
68+
}
69+
5370
export const rename = async (
5471
oldName: string,
5572
newName: string,
@@ -332,6 +349,13 @@ export const applyChanges = async (
332349
await setDeep(values, path, tmplStr)
333350
}
334351
}
352+
// Lastly we remove files
353+
for (const change of changes) {
354+
change.fileDeletions?.forEach((entry) => {
355+
const paths = unparsePaths(entry, values)
356+
paths.forEach((path) => deleteFile(path))
357+
})
358+
}
335359

336360
if (c.networkPoliciesMigration) await networkPoliciesMigration(values)
337361

src/common/values.ts

-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ export const writeValues = async (inValues: Record<string, any>, overwrite = fal
214214
'apps',
215215
'backups',
216216
'builds',
217-
'jobs',
218217
'secrets',
219218
'netpols',
220219
'sealedsecrets',

tests/fixtures/env/settings.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ status:
131131
deployingVersion: 0.21.0
132132
status: deployed
133133
version: 0.21.0
134-
version: 26
134+
version: 27

tests/fixtures/env/teams/jobs.admin.yaml

-3
This file was deleted.

tests/fixtures/env/teams/jobs.demo.yaml

-167
This file was deleted.

tests/fixtures/env/teams/jobs.dev.yaml

-3
This file was deleted.

values-changes.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,8 @@ changes:
278278
- version: 26
279279
relocations:
280280
- 'apps.metrics-server.apiServer.enabled': 'apps.metrics-server.apiServer.create'
281+
- version: 27
282+
deletions:
283+
- 'teamConfig.{team}.jobs'
284+
fileDeletions:
285+
- env/teams/jobs.{team}.yaml

values-schema.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,6 @@ definitions:
10881088
id:
10891089
$ref: '#/definitions/idName'
10901090
description: Must be the same as the name.
1091-
jobs:
1092-
$ref: '#/definitions/jobs'
10931091
limitRange:
10941092
description: 'Kubernetes limit range. As is.'
10951093
properties:

0 commit comments

Comments
 (0)