-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize database pause and backup handling (#5242)
* update * fix launchpad * feat: support disable auto backup when pause database * fix connection * fix launchpad * refactor database modification logic * update pod age time
- Loading branch information
Showing
16 changed files
with
380 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
frontend/providers/dbprovider/src/pages/api/pauseDBByName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { authSession } from '@/services/backend/auth'; | ||
import { getK8s } from '@/services/backend/kubernetes'; | ||
import { jsonRes } from '@/services/backend/response'; | ||
import { ApiResp } from '@/services/kubernet'; | ||
import { KbPgClusterType } from '@/types/cluster'; | ||
import { json2StartOrStop } from '@/utils/json2Yaml'; | ||
import { PatchUtils } from '@kubernetes/client-node'; | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) { | ||
try { | ||
const { dbName } = req.body as { | ||
dbName: string; | ||
}; | ||
|
||
if (!dbName) { | ||
return jsonRes(res, { | ||
code: 400, | ||
error: 'params error' | ||
}); | ||
} | ||
|
||
const { applyYamlList, k8sCustomObjects, namespace } = await getK8s({ | ||
kubeconfig: await authSession(req) | ||
}); | ||
|
||
const { yaml, yamlObj } = json2StartOrStop({ | ||
dbName, | ||
type: 'Stop' | ||
}); | ||
|
||
const { body } = (await k8sCustomObjects.getNamespacedCustomObject( | ||
'apps.kubeblocks.io', | ||
'v1alpha1', | ||
namespace, | ||
'clusters', | ||
dbName | ||
)) as { | ||
body: KbPgClusterType; | ||
}; | ||
|
||
if (body.spec.backup?.enabled === true) { | ||
const patch = [ | ||
{ | ||
op: 'replace', | ||
path: '/spec/backup/enabled', | ||
value: false | ||
} | ||
]; | ||
await k8sCustomObjects.patchNamespacedCustomObject( | ||
'apps.kubeblocks.io', | ||
'v1alpha1', | ||
namespace, | ||
'clusters', | ||
dbName, | ||
patch, | ||
undefined, | ||
undefined, | ||
undefined, | ||
{ headers: { 'Content-type': PatchUtils.PATCH_FORMAT_JSON_PATCH } } | ||
); | ||
} | ||
|
||
await applyYamlList([yaml], 'update'); | ||
|
||
jsonRes(res, { data: 'pause success' }); | ||
} catch (err: any) { | ||
jsonRes(res, { | ||
code: 500, | ||
error: err | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
frontend/providers/dbprovider/src/pages/api/startDBByName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { authSession } from '@/services/backend/auth'; | ||
import { getK8s } from '@/services/backend/kubernetes'; | ||
import { jsonRes } from '@/services/backend/response'; | ||
import { ApiResp } from '@/services/kubernet'; | ||
import { KbPgClusterType } from '@/types/cluster'; | ||
import { json2StartOrStop } from '@/utils/json2Yaml'; | ||
import { PatchUtils } from '@kubernetes/client-node'; | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) { | ||
try { | ||
const { dbName } = req.body as { | ||
dbName: string; | ||
}; | ||
|
||
if (!dbName) { | ||
return jsonRes(res, { | ||
code: 400, | ||
error: 'params error' | ||
}); | ||
} | ||
|
||
const { applyYamlList, k8sCustomObjects, namespace } = await getK8s({ | ||
kubeconfig: await authSession(req) | ||
}); | ||
|
||
const { yaml, yamlObj } = json2StartOrStop({ | ||
dbName, | ||
type: 'Start' | ||
}); | ||
|
||
const { body } = (await k8sCustomObjects.getNamespacedCustomObject( | ||
'apps.kubeblocks.io', | ||
'v1alpha1', | ||
namespace, | ||
'clusters', | ||
dbName | ||
)) as { | ||
body: KbPgClusterType; | ||
}; | ||
|
||
console.log(yamlObj, body.spec.backup, body.spec.backup?.enabled === false, 'yaml'); | ||
|
||
if (body.spec.backup?.enabled === false) { | ||
const patch = [ | ||
{ | ||
op: 'replace', | ||
path: '/spec/backup/enabled', | ||
value: true | ||
} | ||
]; | ||
|
||
await k8sCustomObjects.patchNamespacedCustomObject( | ||
'apps.kubeblocks.io', | ||
'v1alpha1', | ||
namespace, | ||
'clusters', | ||
dbName, | ||
patch, | ||
undefined, | ||
undefined, | ||
undefined, | ||
{ headers: { 'Content-type': PatchUtils.PATCH_FORMAT_JSON_PATCH } } | ||
); | ||
} | ||
await applyYamlList([yaml], 'update'); | ||
|
||
jsonRes(res, { data: 'start success' }); | ||
} catch (err: any) { | ||
jsonRes(res, { | ||
code: 500, | ||
error: err | ||
}); | ||
} | ||
} |
Oops, something went wrong.