From eb838607f089f7bfc78ea5df44132bd2f2c9a824 Mon Sep 17 00:00:00 2001
From: jingyang <72259332+zjy365@users.noreply.github.com>
Date: Wed, 7 Aug 2024 15:05:04 +0800
Subject: [PATCH] feat:launchpad update container status reason (#4947)
* update container status reason
* update color
* update uploadConvertData
* fix mock app
---
.../src/pages/self-hosting/product/index.tsx | 7 +-
.../providers/applaunchpad/src/mock/apps.ts | 176 +-----------------
.../src/pages/app/detail/components/Pods.tsx | 15 +-
.../providers/applaunchpad/src/types/app.d.ts | 2 +-
.../providers/applaunchpad/src/utils/adapt.ts | 24 ++-
service/license/src/api/system.ts | 4 +-
.../license/src/components/login/index.tsx | 18 +-
service/license/src/pages/signin.tsx | 3 +-
8 files changed, 38 insertions(+), 211 deletions(-)
diff --git a/docs/website/src/pages/self-hosting/product/index.tsx b/docs/website/src/pages/self-hosting/product/index.tsx
index f29c955a8..6e6b52941 100644
--- a/docs/website/src/pages/self-hosting/product/index.tsx
+++ b/docs/website/src/pages/self-hosting/product/index.tsx
@@ -1,4 +1,3 @@
-import Link from '@docusaurus/Link';
import useWindow from '@site/src/hooks/useWindow';
import CheckIcon from '@site/static/price/check.svg';
import StarIcon from '@site/static/price/star.svg';
@@ -43,7 +42,7 @@ export default function Product() {
window.open('https://license.sealos.io/')}
+ onClick={() => window.open(`https://license.sealos.io/signin?bd_vid=${bd_vid}`)}
className="rounded-md cursor-pointer hover:no-underline text-[#FFFFFFCC] hover:text-[#FFFFFFCC] bg-[#B7D8FF26] flex justify-center items-center font-semibold text-lg gap-2 py-3 px-4 lg:text-sm"
>
diff --git a/frontend/providers/applaunchpad/src/mock/apps.ts b/frontend/providers/applaunchpad/src/mock/apps.ts
index d86a981a6..9b77b73fa 100644
--- a/frontend/providers/applaunchpad/src/mock/apps.ts
+++ b/frontend/providers/applaunchpad/src/mock/apps.ts
@@ -196,7 +196,8 @@ export const MOCK_PODS: PodDetailType[] = [
yData: new Array(30).fill('0')
},
cpu: 0,
- memory: 0
+ memory: 0,
+ containerStatus: podStatusMap.running
},
{
podName: '2',
@@ -216,177 +217,8 @@ export const MOCK_PODS: PodDetailType[] = [
yData: new Array(30).fill('0')
},
cpu: 0,
- memory: 0
- },
- {
- podName: '3',
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
- },
-
- {
- podName: '4',
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
- },
-
- {
- podName: '5',
-
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
- },
- {
- podName: '6',
-
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
- },
- {
- podName: '7',
-
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
- },
- {
- podName: '8',
-
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
- },
-
- {
- podName: '9',
-
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
- },
-
- {
- podName: 'dafsdd2sgsd6gsdg',
-
- nodeName: 'dafda-fasd-fas',
- ip: '311.241.41.41',
- restarts: 10,
- age: '22',
- status: podStatusMap.running,
- usedCpu: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- usedMemory: {
- name: '',
- xData: new Array(30).fill(0),
- yData: new Array(30).fill('0')
- },
- cpu: 0,
- memory: 0
+ memory: 0,
+ containerStatus: podStatusMap.running
}
];
diff --git a/frontend/providers/applaunchpad/src/pages/app/detail/components/Pods.tsx b/frontend/providers/applaunchpad/src/pages/app/detail/components/Pods.tsx
index 26b3b80c0..a500b8908 100644
--- a/frontend/providers/applaunchpad/src/pages/app/detail/components/Pods.tsx
+++ b/frontend/providers/applaunchpad/src/pages/app/detail/components/Pods.tsx
@@ -98,14 +98,12 @@ const Pods = ({
{item.status.label}
{!!item.status.reason && (
@@ -117,9 +115,14 @@ const Pods = ({
title: 'Restarts Num',
key: 'restarts',
render: (item: PodDetailType) => (
-
+
{item.restarts}
-
+ {!!item.containerStatus.reason && (
+
+ ({item.containerStatus?.reason})
+
+ )}
+
)
},
{
diff --git a/frontend/providers/applaunchpad/src/types/app.d.ts b/frontend/providers/applaunchpad/src/types/app.d.ts
index 89d4a0834..18200eec8 100644
--- a/frontend/providers/applaunchpad/src/types/app.d.ts
+++ b/frontend/providers/applaunchpad/src/types/app.d.ts
@@ -127,7 +127,6 @@ export interface PodStatusMapType {
color: string;
reason?: string;
message?: string;
- lastStateReason?: string;
}
export interface PodDetailType extends V1Pod {
podName: string;
@@ -142,6 +141,7 @@ export interface PodDetailType extends V1Pod {
memory: number;
podReason?: string;
podMessage?: string;
+ containerStatus: PodStatusMapType;
}
export interface PodMetrics {
podName: string;
diff --git a/frontend/providers/applaunchpad/src/utils/adapt.ts b/frontend/providers/applaunchpad/src/utils/adapt.ts
index 6c983109a..3b7f5ad86 100644
--- a/frontend/providers/applaunchpad/src/utils/adapt.ts
+++ b/frontend/providers/applaunchpad/src/utils/adapt.ts
@@ -90,23 +90,18 @@ export const adaptPod = (pod: V1Pod): PodDetailType => {
return {
...pod,
podName: pod.metadata?.name || 'pod name',
- // @ts-ignore
status: (() => {
const container = pod.status?.containerStatuses || [];
if (container.length > 0) {
const stateObj = container[0].state;
- const lasteStateObj = container[0].lastState;
if (stateObj) {
const stateKeys = Object.keys(stateObj);
- const key = stateKeys?.[0] as `${PodStatusEnum}`;
+ const key = stateKeys[0] as `${PodStatusEnum}`;
if (key === PodStatusEnum.running) {
return podStatusMap[PodStatusEnum.running];
}
if (key && podStatusMap[key]) {
- const lastStateReason =
- lasteStateObj && lasteStateObj[key] ? lasteStateObj[key]?.reason : '';
return {
- lastStateReason,
...podStatusMap[key],
...stateObj[key]
};
@@ -115,6 +110,23 @@ export const adaptPod = (pod: V1Pod): PodDetailType => {
}
return podStatusMap.waiting;
})(),
+ containerStatus: (() => {
+ const container = pod.status?.containerStatuses || [];
+ if (container.length > 0) {
+ const lastStateObj = container[0].lastState;
+ if (lastStateObj) {
+ const lastStateKeys = Object.keys(lastStateObj);
+ const key = lastStateKeys[0] as `${PodStatusEnum}`;
+ if (key && podStatusMap[key]) {
+ return {
+ ...podStatusMap[key],
+ ...lastStateObj[key]
+ };
+ }
+ }
+ }
+ return podStatusMap.waiting;
+ })(),
nodeName: pod.spec?.nodeName || 'node name',
ip: pod.status?.podIP || 'pod ip',
restarts: pod.status?.containerStatuses ? pod.status?.containerStatuses[0].restartCount : 0,
diff --git a/service/license/src/api/system.ts b/service/license/src/api/system.ts
index 125b64fda..5baaae3ba 100644
--- a/service/license/src/api/system.ts
+++ b/service/license/src/api/system.ts
@@ -14,9 +14,9 @@ export const getPriceBonus = () =>
// handle baidu
export const uploadConvertData = (newType: number[], url?: string) => {
- const defaultUrl = 'https://sealos.run/';
+ const defaultUrl = 'https://sealos.run/self-hosting';
const main_url = url || defaultUrl;
- const bd_vid = sessionStorage.getItem('bd_vid');
+ const bd_vid = localStorage.getItem('bd_vid');
if (!bd_vid) {
return Promise.reject('upload convert data params error');
}
diff --git a/service/license/src/components/login/index.tsx b/service/license/src/components/login/index.tsx
index f8f350ada..b7e2887de 100644
--- a/service/license/src/components/login/index.tsx
+++ b/service/license/src/components/login/index.tsx
@@ -15,7 +15,6 @@ import {
TabIndicator,
TabList,
Tabs,
- Image,
useDisclosure
} from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
@@ -106,22 +105,7 @@ export default function SigninComponent() {
}, 500);
return (
-
+
Sealos Cloud
diff --git a/service/license/src/pages/signin.tsx b/service/license/src/pages/signin.tsx
index c638eda3e..a7bbc4f42 100644
--- a/service/license/src/pages/signin.tsx
+++ b/service/license/src/pages/signin.tsx
@@ -22,9 +22,8 @@ export default function SigninPage() {
useEffect(() => {
const { bd_vid } = router.query;
if (bd_vid) {
- sessionStorage.setItem('bd_vid', bd_vid as string);
+ localStorage.setItem('bd_vid', bd_vid as string);
}
- // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return ;