|
1 | | -import { CoreV1Api, KubeConfig, User as k8sUser, V1ObjectReference } from '@kubernetes/client-node' |
| 1 | +import { CoreV1Api, User as k8sUser, KubeConfig, V1ObjectReference } from '@kubernetes/client-node' |
2 | 2 | import Debug from 'debug' |
3 | 3 |
|
4 | 4 | import { getRegions, ObjectStorageKeyRegions } from '@linode/api-v4' |
@@ -94,6 +94,10 @@ import { |
94 | 94 | } from 'src/validators' |
95 | 95 | import { v4 as uuidv4 } from 'uuid' |
96 | 96 | import { parse as parseYaml, stringify as stringifyYaml } from 'yaml' |
| 97 | +import { getAIModels } from './ai/aiModelHandler' |
| 98 | +import { AkamaiAgentCR } from './ai/AkamaiAgentCR' |
| 99 | +import { AkamaiKnowledgeBaseCR } from './ai/AkamaiKnowledgeBaseCR' |
| 100 | +import { DatabaseCR } from './ai/DatabaseCR' |
97 | 101 | import { |
98 | 102 | apply, |
99 | 103 | checkPodExists, |
@@ -121,10 +125,6 @@ import { getSealedSecretsPEM, sealedSecretManifest, SealedSecretManifestType } f |
121 | 125 | import { getKeycloakUsers, isValidUsername } from './utils/userUtils' |
122 | 126 | import { ObjectStorageClient } from './utils/wizardUtils' |
123 | 127 | import { fetchChartYaml, fetchWorkloadCatalog, NewHelmChartValues, sparseCloneChart } from './utils/workloadUtils' |
124 | | -import { getAIModels } from './ai/aiModelHandler' |
125 | | -import { AkamaiKnowledgeBaseCR } from './ai/AkamaiKnowledgeBaseCR' |
126 | | -import { AkamaiAgentCR } from './ai/AkamaiAgentCR' |
127 | | -import { DatabaseCR } from './ai/DatabaseCR' |
128 | 128 |
|
129 | 129 | interface ExcludedApp extends App { |
130 | 130 | managed: boolean |
@@ -159,6 +159,14 @@ function getTeamSealedSecretsValuesFilePath(teamId: string, sealedSecretsName: s |
159 | 159 | return `env/teams/${teamId}/sealedsecrets/${sealedSecretsName}` |
160 | 160 | } |
161 | 161 |
|
| 162 | +function getTeamWorkloadValuesManagedFilePath(teamId: string, workloadName: string): string { |
| 163 | + return `env/teams/${teamId}/workloadValues/${workloadName}.managed.yaml` |
| 164 | +} |
| 165 | + |
| 166 | +function getTeamWorkloadValuesFilePath(teamId: string, workloadName: string): string { |
| 167 | + return `env/teams/${teamId}/workloadValues/${workloadName}.yaml` |
| 168 | +} |
| 169 | + |
162 | 170 | function getTeamKnowledgeBaseValuesFilePath(teamId: string, knowledgeBaseName: string): string { |
163 | 171 | return `env/teams/${teamId}/knowledgebases/${knowledgeBaseName}` |
164 | 172 | } |
@@ -272,16 +280,13 @@ export default class OtomiStack { |
272 | 280 | }) |
273 | 281 | } |
274 | 282 |
|
275 | | - transformWorkloads(workloads: AplWorkloadResponse[], workloadValues: Record<string, any>[]): AplWorkloadResponse[] { |
276 | | - const values = {} |
277 | | - workloadValues.forEach((value) => { |
278 | | - const workloadName = value.name |
279 | | - if (workloadName) { |
280 | | - values[workloadName] = value.values |
281 | | - } |
282 | | - }) |
| 283 | + transformWorkloads(workloads: AplWorkloadResponse[], files: string[]): AplWorkloadResponse[] { |
283 | 284 | return workloads.map((workload) => { |
284 | | - return merge(workload, { spec: { values: values[workload.metadata.name] } }) |
| 285 | + const workloadName = workload.metadata.name |
| 286 | + const teamId = workload.metadata.labels?.['apl.io/teamId'] |
| 287 | + |
| 288 | + const filePath = getTeamWorkloadValuesFilePath(teamId, workloadName) |
| 289 | + return merge(workload, { spec: { values: files[filePath] } }) |
285 | 290 | }) |
286 | 291 | } |
287 | 292 |
|
@@ -314,10 +319,9 @@ export default class OtomiStack { |
314 | 319 | apps: this.transformApps(teamConfig.apps), |
315 | 320 | policies: this.transformPolicies(teamName, teamConfig.policies || {}), |
316 | 321 | sealedsecrets: this.transformSecrets(teamName, teamConfig.sealedsecrets || []), |
317 | | - workloads: this.transformWorkloads(teamConfig.workloads || [], teamConfig.workloadValues || []), |
| 322 | + workloads: this.transformWorkloads(teamConfig.workloads || [], rawRepo.files || {}), |
318 | 323 | settings: this.transformTeamSettings(teamConfig.settings), |
319 | 324 | })) |
320 | | - |
321 | 325 | const repo = rawRepo as Repo |
322 | 326 | this.repoService = new RepoService(repo) |
323 | 327 | } |
@@ -834,18 +838,16 @@ export default class OtomiStack { |
834 | 838 | await this.git.saveConfig(repo, fileMap) |
835 | 839 | } |
836 | 840 |
|
837 | | - async saveTeamWorkloadValues(data: AplWorkloadResponse) { |
| 841 | + async saveTeamWorkloadValues(data: AplWorkloadResponse, createManagedFile = false) { |
838 | 842 | const { metadata } = data |
839 | 843 | const teamId = metadata.labels['apl.io/teamId']! |
840 | 844 | debug(`Saving AplTeamWorkloadValues ${metadata.name} for team ${teamId}`) |
841 | | - const values = { |
842 | | - name: metadata.name, |
843 | | - values: data.spec.values, |
| 845 | + const filePath = getTeamWorkloadValuesFilePath(teamId, metadata.name) |
| 846 | + await this.git.writeTextFile(filePath, data.spec.values || '{}') |
| 847 | + if (createManagedFile) { |
| 848 | + const filePathValuesManaged = getTeamWorkloadValuesManagedFilePath(teamId, metadata.name) |
| 849 | + await this.git.writeTextFile(filePathValuesManaged, '') |
844 | 850 | } |
845 | | - const configKey = this.getConfigKey('AplTeamWorkloadValues') |
846 | | - const repo = this.createTeamConfigInRepo(teamId, configKey, [values]) |
847 | | - const fileMap = getFileMaps('').find((fm) => fm.kind === 'AplTeamWorkloadValues')! |
848 | | - await this.git.saveConfig(repo, fileMap, false) |
849 | 851 | } |
850 | 852 |
|
851 | 853 | async saveTeamPolicy(teamId: string, data: AplPolicyResponse): Promise<void> { |
@@ -884,8 +886,10 @@ export default class OtomiStack { |
884 | 886 | const fileMapWorkload = getFileMaps('').find((fm) => fm.kind === 'AplTeamWorkload')! |
885 | 887 | const repoValues = this.createTeamConfigInRepo(teamId, 'workloads', [data]) |
886 | 888 | const fileMapValues = getFileMaps('').find((fm) => fm.kind === 'AplTeamWorkloadValues')! |
| 889 | + const filePathValuesManaged = getTeamWorkloadValuesManagedFilePath(teamId, metadata.name) |
887 | 890 | await this.git.deleteConfig(repoWorkload, fileMapWorkload) |
888 | 891 | await this.git.deleteConfig(repoValues, fileMapValues) |
| 892 | + await this.git.removeFile(filePathValuesManaged) |
889 | 893 | } |
890 | 894 |
|
891 | 895 | getTeamBackups(teamId: string): Backup[] { |
@@ -1786,7 +1790,7 @@ export default class OtomiStack { |
1786 | 1790 | try { |
1787 | 1791 | const workload = this.repoService.getTeamConfigService(teamId).createWorkload(data) |
1788 | 1792 | await this.saveTeamWorkload(workload) |
1789 | | - await this.saveTeamWorkloadValues(workload) |
| 1793 | + await this.saveTeamWorkloadValues(workload, true) |
1790 | 1794 | await this.doTeamDeployment( |
1791 | 1795 | teamId, |
1792 | 1796 | (teamService) => { |
|
0 commit comments