Skip to content

Commit 97bafa0

Browse files
merllj-zimnowoda
andauthored
fix: revert structural change of app values on toggle (#863)
* fix: revert structural change of app values on toggle * fix: order of arguments * feat: simplify app toggle functionallity --------- Co-authored-by: Jehoszafat Zimnowoda <[email protected]>
1 parent 9d09335 commit 97bafa0

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/otomi-stack.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CoreV1Api, KubeConfig, User as k8sUser, V1ObjectReference } from '@kubernetes/client-node'
1+
import { CoreV1Api, User as k8sUser, KubeConfig, V1ObjectReference } from '@kubernetes/client-node'
22
import Debug from 'debug'
33

44
import { getRegions, ObjectStorageKeyRegions } from '@linode/api-v4'
@@ -17,9 +17,9 @@ import {
1717
PublicUrlExists,
1818
ValidationError,
1919
} from 'src/error'
20-
import getRepo, { getWorktreeRepo, Git } from 'src/git'
21-
import { FileStore } from 'src/fileStore/file-store'
2220
import { getSettingsFileMaps } from 'src/fileStore/file-map'
21+
import { FileStore } from 'src/fileStore/file-store'
22+
import getRepo, { getWorktreeRepo, Git } from 'src/git'
2323
import { cleanSession, getSessionStack } from 'src/middleware'
2424
import {
2525
AplAgentRequest,
@@ -109,6 +109,7 @@ import { v4 as uuidv4 } from 'uuid'
109109
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml'
110110
import { getAIModels } from './ai/aiModelHandler'
111111
import { DatabaseCR } from './ai/DatabaseCR'
112+
import { getResourceFilePath, getSecretFilePath } from './fileStore/file-map'
112113
import {
113114
apply,
114115
checkPodExists,
@@ -132,7 +133,6 @@ import { getSealedSecretsPEM, sealedSecretManifest } from './utils/sealedSecretU
132133
import { getKeycloakUsers, isValidUsername } from './utils/userUtils'
133134
import { ObjectStorageClient } from './utils/wizardUtils'
134135
import { fetchChartYaml, fetchWorkloadCatalog, NewHelmChartValues, sparseCloneChart } from './utils/workloadUtils'
135-
import { getResourceFilePath, getSecretFilePath } from './fileStore/file-map'
136136

137137
interface ExcludedApp extends App {
138138
managed: boolean
@@ -616,15 +616,13 @@ export default class OtomiStack {
616616
const orig = this.getApp(id)
617617
if (orig && this.canToggleApp(id)) {
618618
const filePath = getResourceFilePath('AplApp', id)
619-
const aplApp = toPlatformObject('AplApp', id, {
620-
...orig,
621-
enabled,
622-
values: { ...orig.values, enabled },
623-
})
624-
this.fileStore.set(filePath, aplApp)
625-
626-
const app = { ...orig, enabled }
627-
await this.saveAdminApp(app)
619+
const aplApp = this.fileStore.get(filePath)
620+
if (!aplApp) {
621+
throw new NotExistError(`App ${id} not found`)
622+
}
623+
set(aplApp, 'spec.enabled', enabled)
624+
625+
await this.saveAppToggle(aplApp)
628626
return { filePath, content: aplApp } as AplRecord
629627
}
630628
return undefined
@@ -2391,6 +2389,11 @@ export default class OtomiStack {
23912389

23922390
return { filePath, content: aplObject }
23932391
}
2392+
async saveAppToggle(app: AplObject): Promise<void> {
2393+
const globalPaths = getSecretPaths()
2394+
const appSecretPaths = this.extractAppSecretPaths(app.metadata.name, globalPaths)
2395+
await this.saveWithSecrets(app, appSecretPaths)
2396+
}
23942397

23952398
async saveAdminApp(app: App, secretPaths?: string[]): Promise<void> {
23962399
const { id, enabled, values, rawValues } = app

0 commit comments

Comments
 (0)