Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(devbox): fix invaild devbox cr #5339

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import CreateTemplateModal from '@/app/[lang]/(platform)/template/updateTemplate
import SelectTemplateModal from '@/app/[lang]/(platform)/template/updateTemplate/SelectActionModal'
import UpdateTemplateRepositoryModal from '@/app/[lang]/(platform)/template/updateTemplate/UpdateTemplateRepositoryModal'
import AppSelectModal from '@/components/modals/AppSelectModal'
import useReleaseDriver from '@/hooks/useReleaseDriver'
import { useDevboxStore } from '@/stores/devbox'
import { useEnvStore } from '@/stores/env'
import { AppListItemType } from '@/types/app'
import { parseTemplateConfig } from '@/utils/tools'
import useReleaseDriver from '@/hooks/useReleaseDriver'

const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 6)

Expand Down Expand Up @@ -260,7 +260,7 @@ const Version = () => {
<SealosMenu
width={100}
Button={
<MenuButton as={Button} variant={'square'} boxSize={'32px'} data-group>
<MenuButton as={Button} variant={'square'} boxSize={'32px'} data-group isDisabled={item?.status?.value !== 'Success'}>
<MyIcon
name={'more'}
color={'grayModern.600'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function GET(req: NextRequest) {

const devbox = {
status:
body.status.phase && devboxStatusMap[body.status.phase]
body.status?.phase && devboxStatusMap[body.status.phase]
? devboxStatusMap[body.status.phase]
: devboxStatusMap.Error,
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/providers/devbox/types/k8s.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type KBDevboxTypeV2 = {
creationTimestamp: string
}
spec: KBDevboxSpecV2
status: {
status?: {
lastState: {
terminated?: {
containerID: string
Expand Down
82 changes: 24 additions & 58 deletions frontend/providers/devbox/utils/adapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { GetDevboxByNameReturn } from '@/types/adapt'
import { DBListItemType, KbPgClusterType } from '@/types/cluster'
import {
DevboxDetailType,
DevboxDetailTypeV2,
DevboxListItemType,
DevboxListItemTypeV2,
Expand Down Expand Up @@ -70,10 +69,10 @@ export const adaptDevboxListItemV2 = ([devbox, template]: [KBDevboxTypeV2, {
name: devbox.metadata.name || 'devbox',
template,
status:
devbox.status.phase && devboxStatusMap[devbox.status.phase]
devbox.status?.phase && devboxStatusMap[devbox.status.phase]
? devboxStatusMap[devbox.status.phase]
: devboxStatusMap.Error,
sshPort: devbox.status.network.nodePort,
sshPort: devbox.status?.network.nodePort || 65535,
createTime: dayjs(devbox.metadata.creationTimestamp).format('YYYY/MM/DD HH:mm'),
cpu: cpuFormatToM(devbox.spec.resource.cpu),
memory: memoryFormatToMi(devbox.spec.resource.memory),
Expand All @@ -88,60 +87,25 @@ export const adaptDevboxListItemV2 = ([devbox, template]: [KBDevboxTypeV2, {
yData: new Array(30).fill('0')
},
lastTerminatedReason:
devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error'
? devbox.status.state.waiting
? devbox.status.state.waiting.reason
: devbox.status.state.terminated
? devbox.status.state.terminated.reason
: ''
: ''
}
}
export const adaptDevboxDetail = (
devbox: KBDevboxType & { portInfos: any[] }
): DevboxDetailType => {
return {
id: devbox.metadata?.uid || ``,
name: devbox.metadata.name || 'devbox',
runtimeType: devbox.spec.runtimeType || '',
runtimeVersion: devbox.spec.runtimeRef.name || '',
status:
devbox.status.phase && devboxStatusMap[devbox.status.phase]
? devboxStatusMap[devbox.status.phase]
: devboxStatusMap.Error,
sshPort: devbox.status.network.nodePort,
isPause: devbox.status.phase === 'Stopped',
createTime: dayjs(devbox.metadata.creationTimestamp).format('YYYY-MM-DD HH:mm'),
cpu: cpuFormatToM(devbox.spec.resource.cpu),
memory: memoryFormatToMi(devbox.spec.resource.memory),
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')
},
networks: devbox.portInfos,
lastTerminatedReason:
devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error'
? devbox.status.state.waiting
? devbox.status.state.waiting.reason
: devbox.status.state.terminated
? devbox.status.state.terminated.reason
: ''
devbox.status ?
devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error'
? devbox.status.state.waiting
? devbox.status.state.waiting.reason
: devbox.status.state.terminated
? devbox.status.state.terminated.reason
: ''
: ''
: ''
}
}

export const adaptDevboxDetailV2 = (
[devbox, portInfos, template]: GetDevboxByNameReturn
): DevboxDetailTypeV2 => {
console.log('adaptDevboxDetailV2')
const status = devbox.status.phase && devboxStatusMap[devbox.status.phase]
? devboxStatusMap[devbox.status.phase]
: devboxStatusMap.Error
const status = devbox.status?.phase && devboxStatusMap[devbox.status.phase]
? devboxStatusMap[devbox.status.phase]
: devboxStatusMap.Error
return {
id: devbox.metadata?.uid || ``,
name: devbox.metadata.name || 'devbox',
Expand All @@ -153,8 +117,8 @@ export const adaptDevboxDetailV2 = (
image: template.image,
iconId: template.templateRepository.iconId || '',
status,
sshPort: devbox.status.network.nodePort,
isPause: devbox.status.phase === 'Stopped',
sshPort: devbox.status?.network.nodePort || 65535,
isPause: devbox.status?.phase === 'Stopped',
createTime: dayjs(devbox.metadata.creationTimestamp).format('YYYY-MM-DD HH:mm'),
cpu: cpuFormatToM(devbox.spec.resource.cpu),
memory: memoryFormatToMi(devbox.spec.resource.memory),
Expand All @@ -170,12 +134,14 @@ export const adaptDevboxDetailV2 = (
},
networks: portInfos || [],
lastTerminatedReason:
devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error'
? devbox.status.state.waiting
? devbox.status.state.waiting.reason
: devbox.status.state.terminated
? devbox.status.state.terminated.reason
: ''
devbox.status ?
devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error'
? devbox.status.state.waiting
? devbox.status.state.waiting.reason
: devbox.status.state.terminated
? devbox.status.state.terminated.reason
: ''
: ''
: ''
}
}
Expand Down
Loading