Skip to content

Commit

Permalink
feat: support multiple volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
zjy365 committed Jan 9, 2025
1 parent cf3c237 commit 64a8c12
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions frontend/providers/applaunchpad/src/constants/editApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const editModeMap = (isEdit: boolean) => {
};

export const defaultEditVal: AppEditType = {
kind: 'deployment',
appName: 'hello-world',
imageName: 'nginx',
runCMD: '',
Expand Down Expand Up @@ -58,6 +59,7 @@ export const defaultEditVal: AppEditType = {
serverAddress: 'docker.io'
},
storeList: [],
volumes: [],
gpu: {
manufacturers: 'nvidia',
type: '',
Expand Down
2 changes: 2 additions & 0 deletions frontend/providers/applaunchpad/src/mock/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ export const MOCK_PODS: PodDetailType[] = [
];

export const MOCK_APP_DETAIL: AppDetailType = {
kind: 'deployment',
volumes: [],
crYamlList: [],
id: '4bd50c41-149e-4da5-89d5-0308b9dd75c6',
createTime: '2022/1/22',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const ConfigmapModal = ({
{t('file value')}{' '}
</Box>
<Textarea
whiteSpace={'pre-wrap'}
rows={10}
resize={'both'}
{...register('value', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ const EditEnvs = ({
{t('Environment Variables')}
</Box>
<Textarea
whiteSpace={'pre-wrap'}
h={'350px'}
maxH={'100%'}
value={inputVal}
resize={'both'}
placeholder={t('Env Placeholder') || ''}
overflowX={'auto'}
whiteSpace={inputVal === '' ? 'pre-wrap' : 'nowrap'}
onChange={(e) => setInputVal(e.target.value)}
/>
</ModalBody>
Expand Down
4 changes: 2 additions & 2 deletions frontend/providers/applaunchpad/src/pages/app/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export const formData2Yamls = (
filename: 'service.yaml',
value: json2Service(data)
},
!!data.storeList?.length
data.kind === 'statefulset' || data.storeList?.length > 0
? {
filename: 'statefulSet.yaml',
filename: 'statefulset.yaml',
value: json2DeployCr(data, 'statefulset')
}
: {
Expand Down
5 changes: 4 additions & 1 deletion frontend/providers/applaunchpad/src/types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import type {
V1HorizontalPodAutoscaler,
V1Pod,
SinglePodMetrics,
V1StatefulSet
V1StatefulSet,
V1Volume
} from '@kubernetes/client-node';
import { MonitorDataResult } from './monitor';

Expand Down Expand Up @@ -108,6 +109,8 @@ export interface AppEditType {
value: number;
}[];
labels: { [key: string]: string };
volumes: V1Volume[];
kind: 'deployment' | 'statefulset';
}

export type AppEditSyncedFields = Pick<
Expand Down
7 changes: 6 additions & 1 deletion frontend/providers/applaunchpad/src/utils/adapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ export const adaptAppDetail = async (configs: DeployKindsType[]): Promise<AppDet
value: Number(item.metadata?.annotations?.value || 0)
}))
: [],
// keep original non-configMap type volumes
volumes: appDeploy?.spec?.template?.spec?.volumes?.filter((volume) => !volume.configMap) || [],
kind: appDeploy?.kind?.toLowerCase() as 'deployment' | 'statefulset',
source: getAppSource(appDeploy)
};
};
Expand All @@ -393,7 +396,9 @@ export const adaptEditAppData = (app: AppDetailType): AppEditType => {
'secret',
'storeList',
'gpu',
'labels'
'labels',
'kind',
'volumes'
];

const res: Record<string, any> = {};
Expand Down
6 changes: 4 additions & 2 deletions frontend/providers/applaunchpad/src/utils/deployYaml2Json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import dayjs from 'dayjs';
import yaml from 'js-yaml';

export const json2DeployCr = (data: AppEditType, type: 'deployment' | 'statefulset') => {
console.log(data, 'data');

const totalStorage = data.storeList.reduce((acc, item) => acc + item.value, 0);

const metadata = {
Expand Down Expand Up @@ -171,7 +173,7 @@ export const json2DeployCr = (data: AppEditType, type: 'deployment' | 'statefuls
}
],
...gpuMap,
volumes: [...configMapVolumes]
volumes: [...(data?.volumes || []), ...configMapVolumes]
}
}
}
Expand Down Expand Up @@ -209,7 +211,7 @@ export const json2DeployCr = (data: AppEditType, type: 'deployment' | 'statefuls
}
],
...gpuMap,
volumes: [...configMapVolumes]
volumes: [...(data?.volumes || []), ...configMapVolumes]
}
},
volumeClaimTemplates: storageTemplates
Expand Down

0 comments on commit 64a8c12

Please sign in to comment.