Skip to content

Commit

Permalink
chore(web&server): database repair, add mock to web, rollback on depe…
Browse files Browse the repository at this point in the history
…ndency restar... (#8)
  • Loading branch information
HUAHUAI23 authored Jun 26, 2024
1 parent 09114b0 commit 74a4a8d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class DedicatedDatabaseService {
limitMemory,
requestCPU,
requestMemory,
capacity,
capacity: capacity / 1024,
replicas,
})

Expand Down Expand Up @@ -202,6 +202,7 @@ export class DedicatedDatabaseService {
options: {
authSource: 'admin',
replicaSet: `${name}-mongodb`,
readPreference: 'secondaryPreferred',
w: 'majority',
},
scheme: 'mongodb',
Expand Down
20 changes: 8 additions & 12 deletions server/src/dependency/dependency.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ export class DependencyService {
const new_deps = dto.map((dep) => `${dep.name}@${dep.spec}`)
const deps = extras.concat(new_deps)

const res = await this.db
await this.db
.collection<ApplicationConfiguration>('ApplicationConfiguration')
.findOneAndUpdate(
.updateOne(
{ appid },
{ $set: { dependencies: deps, updatedAt: new Date() } },
{ returnDocument: 'after' },
)
await this.confService.publish(res.value)
return true
}

Expand All @@ -87,14 +85,13 @@ export class DependencyService {

const deps = filtered.concat(new_deps)

const res = await this.db
await this.db
.collection<ApplicationConfiguration>('ApplicationConfiguration')
.findOneAndUpdate(
.updateOne(
{ appid },
{ $set: { dependencies: deps, updatedAt: new Date() } },
{ returnDocument: 'after' },
)
await this.confService.publish(res.value)

return true
}

Expand All @@ -107,14 +104,13 @@ export class DependencyService {

if (filtered.length === deps.length) return false

const res = await this.db
await this.db
.collection<ApplicationConfiguration>('ApplicationConfiguration')
.findOneAndUpdate(
.updateOne(
{ appid },
{ $set: { dependencies: filtered, updatedAt: new Date() } },
{ returnDocument: 'after' },
)
await this.confService.publish(res.value)

return true
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/initializer/deploy-manifest/database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: <%- capacity %>Mi
storage: <%- capacity %>Gi
terminationPolicy: Delete
tolerations: []
6 changes: 3 additions & 3 deletions server/src/instance/instance-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ export class InstanceTaskService {
return
}

// create instance
await this.instanceService.create(app.appid)

const appid = app.appid

const ddb = await this.dedicatedDatabaseService.findOne(appid)
Expand All @@ -150,6 +147,9 @@ export class InstanceTaskService {
}
}

// create instance
await this.instanceService.create(app.appid)

const instance = await this.instanceService.get(appid)
const unavailable =
instance.deployment?.status?.unavailableReplicas || false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export default function DatabaseMonitor() {
metric: Record<string, string>;
values: Array<[number, string]>;
}[] = resourceData?.data?.memory;

const podList = useMemo(() => {
if (!cpuData || !memoryData) return [];
const cpuPods = cpuData.map((item) => item.metric.pod);
const memoryPods = memoryData.map((item) => item.metric.pod);

Expand Down
21 changes: 21 additions & 0 deletions web/src/pages/auth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { Center, Spinner } from "@chakra-ui/react";
import { useMutation } from "@tanstack/react-query";
import { SessionV1 } from "@zjy365/sealos-desktop-sdk/*";
import { createSealosApp, sealosApp } from "@zjy365/sealos-desktop-sdk/app";

import useSessionStore from "./store";
Expand All @@ -17,9 +18,29 @@ const AuthPage = () => {

useEffect(() => {
const initApp = async () => {
const sealosUser = import.meta.env.VITE_SEALOS_MOCK_USER;
const sealosKc = import.meta.env.VITE_SEALOS_MOCK_KC;

if (sealosUser && sealosKc) {
const testSession: SessionV1 = {
user: {
id: "",
name: sealosUser,
avatar: "",
k8sUsername: "",
nsid: "",
},
kubeconfig: sealosKc,
};
setSession(testSession);
return;
}

const result = await sealosApp.getSession();

setSession(result);
};

initApp().finally(() => setIsInit(true));
}, []);

Expand Down

0 comments on commit 74a4a8d

Please sign in to comment.