Skip to content

Commit

Permalink
feat:domain
Browse files Browse the repository at this point in the history
  • Loading branch information
zjy365 committed Sep 9, 2024
1 parent 6dabc64 commit 17e766e
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 109 deletions.
3 changes: 2 additions & 1 deletion frontend/providers/applaunchpad/src/constants/editApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const defaultEditVal: AppEditType = {
protocol: 'HTTP',
openPublicDomain: false,
publicDomain: '',
customDomain: ''
customDomain: '',
domain: ''
}
],
envs: [],
Expand Down
3 changes: 2 additions & 1 deletion frontend/providers/applaunchpad/src/mock/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ export const MOCK_APP_DETAIL: AppDetailType = {
protocol: 'HTTP',
openPublicDomain: false,
publicDomain: '',
customDomain: ''
customDomain: '',
domain: ''
}
],
envs: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export type Response = {
CURRENCY: Coin;
guideEnabled: boolean;
fileMangerConfig: FileMangerType;
SEALOS_USER_DOMAIN: string[];
};

export const defaultAppConfig: AppConfigType = {
cloud: {
domain: 'cloud.sealos.io',
port: ''
port: '',
userDomain: ['cloud.sealos.io']
},
common: {
guideEnabled: false,
Expand Down Expand Up @@ -76,7 +78,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
FORM_SLIDER_LIST_CONFIG: global.AppConfig.launchpad.appResourceFormSliderConfig,
guideEnabled: global.AppConfig.common.guideEnabled,
fileMangerConfig: global.AppConfig.launchpad.fileManger,
CURRENCY: Coin.shellCoin
CURRENCY: Coin.shellCoin,
SEALOS_USER_DOMAIN: global.AppConfig.cloud.userDomain
}
});
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo, useRef } from 'react';
import React, { useMemo, useRef } from 'react';
import {
Box,
ModalBody,
Expand All @@ -15,7 +15,6 @@ import {
ModalHeader
} from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { SEALOS_DOMAIN } from '@/store/static';
import { Tip } from '@sealos/ui';
import { InfoOutlineIcon } from '@chakra-ui/icons';
import { useRequest } from '@/hooks/useRequest';
Expand All @@ -24,11 +23,13 @@ import { postAuthCname } from '@/api/platform';
export type CustomAccessModalParams = {
publicDomain: string;
customDomain: string;
domain: string;
};

const CustomAccessModal = ({
publicDomain,
customDomain,
domain,
onClose,
onSuccess
}: CustomAccessModalParams & { onClose: () => void; onSuccess: (e: string) => void }) => {
Expand All @@ -41,7 +42,7 @@ const CustomAccessModal = ({
mb: 2
};

const completePublicDomain = useMemo(() => `${publicDomain}.${SEALOS_DOMAIN}`, [publicDomain]);
const completePublicDomain = useMemo(() => `${publicDomain}.${domain}`, [publicDomain, domain]);

const { mutate: authCNAME, isLoading } = useRequest({
mutationFn: async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defaultSliderKey, ProtocolList } from '@/constants/app';
import { GpuAmountMarkList } from '@/constants/editApp';
import { useToast } from '@/hooks/useToast';
import { useGlobalStore } from '@/store/global';
import { SEALOS_DOMAIN } from '@/store/static';
import { SEALOS_DOMAIN, SEALOS_USER_DOMAIN } from '@/store/static';
import { useUserStore } from '@/store/user';
import type { QueryType } from '@/types';
import type { AppEditType } from '@/types/app';
Expand Down Expand Up @@ -801,7 +801,8 @@ const Form = ({
protocol: 'HTTP',
openPublicDomain: false,
publicDomain: '',
customDomain: ''
customDomain: '',
domain: SEALOS_USER_DOMAIN[0] ?? SEALOS_DOMAIN
})
}
>
Expand Down Expand Up @@ -866,7 +867,7 @@ const Form = ({
<Box flex={1} userSelect={'all'} className="textEllipsis">
{network.customDomain
? network.customDomain
: `${network.publicDomain}.${SEALOS_DOMAIN}`}
: `${network.publicDomain}.${network.domain}`}
</Box>
<Box
fontSize={'11px'}
Expand All @@ -875,7 +876,8 @@ const Form = ({
onClick={() =>
setCustomAccessModalData({
publicDomain: network.publicDomain,
customDomain: network.customDomain
customDomain: network.customDomain,
domain: network.domain
})
}
>
Expand Down
2 changes: 2 additions & 0 deletions frontend/providers/applaunchpad/src/store/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getInitData } from '@/api/platform';
import { Coin } from '@/constants/app';

export let SEALOS_DOMAIN = 'cloud.sealos.io';
export let SEALOS_USER_DOMAIN = ['cloud.sealos.io'];
export let DOMAIN_PORT = '';
export let INGRESS_SECRET = 'wildcard-cert';
export let SHOW_EVENT_ANALYZE = false;
Expand All @@ -13,6 +14,7 @@ export const loadInitData = async () => {
try {
const res = await getInitData();
SEALOS_DOMAIN = res.SEALOS_DOMAIN;
SEALOS_USER_DOMAIN = res.SEALOS_USER_DOMAIN;
DOMAIN_PORT = res.DOMAIN_PORT;
INGRESS_SECRET = res.INGRESS_SECRET;
SHOW_EVENT_ANALYZE = res.SHOW_EVENT_ANALYZE;
Expand Down
3 changes: 2 additions & 1 deletion frontend/providers/applaunchpad/src/types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export interface AppEditType {
port: number;
protocol: ProtocolType;
openPublicDomain: boolean;
publicDomain: string; // default domain
publicDomain: string; // default domain // domainPrefix
customDomain: string; // custom domain
domain: string;
}[];
envs: {
key: string;
Expand Down
1 change: 1 addition & 0 deletions frontend/providers/applaunchpad/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type AppConfigType = {
cloud: {
domain: string;
port?: string;
userDomain: string[];
};
common: {
guideEnabled: boolean;
Expand Down
107 changes: 12 additions & 95 deletions frontend/providers/applaunchpad/src/utils/adapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export enum YamlKindEnum {
}

export const adaptAppDetail = async (configs: DeployKindsType[]): Promise<AppDetailType> => {
const { SEALOS_DOMAIN } = await getInitData();
const { SEALOS_DOMAIN, SEALOS_USER_DOMAIN } = await getInitData();
const deployKindsMap: {
[YamlKindEnum.StatefulSet]?: V1StatefulSet;
[YamlKindEnum.Deployment]?: V1Deployment;
Expand Down Expand Up @@ -312,21 +312,23 @@ export const adaptAppDetail = async (configs: DeployKindsType[]): Promise<AppDet
const protocol =
backendProtocol ?? (item.protocol === 'TCP' ? 'HTTP' : (item.protocol as ProtocolType));

const isCustomDomain =
!domain.endsWith(SEALOS_DOMAIN) &&
!SEALOS_USER_DOMAIN.some((user) => domain.endsWith(user));

console.log(domain, domain.split('.'), isCustomDomain, SEALOS_DOMAIN, SEALOS_USER_DOMAIN);

return {
networkName: ingress?.metadata?.name || '',
portName: item.name || '',
port: item.port,
protocol: protocol,
openPublicDomain: !!ingress,
...(domain.endsWith(SEALOS_DOMAIN)
? {
publicDomain: domain.split('.')[0],
customDomain: ''
}
: {
publicDomain: ingress?.metadata?.labels?.[publicDomainKey] || '',
customDomain: domain
})
publicDomain: isCustomDomain
? ingress?.metadata?.labels?.[publicDomainKey] || ''
: domain.split('.')[0],
customDomain: isCustomDomain ? domain : '',
domain: domain.split('.').slice(1).join('.')
};
}) || [],
hpa: deployKindsMap.HorizontalPodAutoscaler?.spec
Expand Down Expand Up @@ -390,91 +392,6 @@ export const adaptEditAppData = (app: AppDetailType): AppEditType => {
return res as AppEditType;
};

// yaml file adapt to edit form
export const adaptYamlToEdit = (yamlList: string[]) => {
const configs = yamlList.map((item) => yaml.loadAll(item) as DeployKindsType).flat();

const deployKindsMap: {
[YamlKindEnum.Deployment]?: V1Deployment;
[YamlKindEnum.Service]?: V1Service;
[YamlKindEnum.ConfigMap]?: V1ConfigMap;
[YamlKindEnum.Ingress]?: V1Ingress;
[YamlKindEnum.HorizontalPodAutoscaler]?: V2HorizontalPodAutoscaler;
[YamlKindEnum.Secret]?: V1Secret;
} = {};

configs.forEach((item) => {
if (item.kind) {
// @ts-ignore
deployKindsMap[item.kind] = item;
}
});

const domain = deployKindsMap?.Ingress?.spec?.rules?.[0].host;
const cpuStr =
deployKindsMap?.Deployment?.spec?.template?.spec?.containers?.[0]?.resources?.requests?.cpu;
const memoryStr =
deployKindsMap?.Deployment?.spec?.template?.spec?.containers?.[0]?.resources?.requests?.memory;

const res: Record<string, any> = {
imageName: deployKindsMap?.Deployment?.spec?.template?.spec?.containers?.[0]?.image,
runCMD:
deployKindsMap?.Deployment?.spec?.template?.spec?.containers?.[0]?.command?.join(' ') || '',
cmdParam:
deployKindsMap?.Deployment?.spec?.template?.spec?.containers?.[0]?.args?.join(' ') || '',
replicas: deployKindsMap?.Deployment?.spec?.replicas,
cpu: cpuStr ? cpuFormatToM(cpuStr) : undefined,
memory: memoryStr ? memoryFormatToMi(memoryStr) : undefined,
accessExternal: deployKindsMap?.Ingress
? {
use: true,
outDomain: domain?.split('.')[0],
selfDomain: domain
}
: undefined,
containerOutPort:
deployKindsMap?.Deployment?.spec?.template?.spec?.containers?.[0]?.ports?.[0]?.containerPort,
envs:
deployKindsMap?.Deployment?.spec?.template?.spec?.containers?.[0]?.env?.map((env) => ({
key: env.name,
value: env.value
})) || undefined,
hpa: deployKindsMap.HorizontalPodAutoscaler?.spec
? {
use: true,
target:
(deployKindsMap.HorizontalPodAutoscaler.spec.metrics?.[0]?.resource
?.name as HpaTarget) || 'cpu',
value:
deployKindsMap.HorizontalPodAutoscaler.spec.metrics?.[0]?.resource?.target
?.averageUtilization || 50,
minReplicas: deployKindsMap.HorizontalPodAutoscaler.spec?.maxReplicas,
maxReplicas: deployKindsMap.HorizontalPodAutoscaler.spec?.minReplicas
}
: undefined,
configMapList: deployKindsMap?.ConfigMap?.data
? Object.entries(deployKindsMap?.ConfigMap.data).map(([key, value]) => ({
mountPath: key,
value
}))
: undefined,
secret: deployKindsMap.Secret
? {
...defaultEditVal.secret,
use: true
}
: undefined
};

for (const key in res) {
if (res[key] === undefined) {
delete res[key];
}
}

return res;
};

export const sliderNumber2MarkList = ({
val,
type,
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 @@ -7,7 +7,7 @@ import {
minReplicasKey,
publicDomainKey
} from '@/constants/app';
import { INGRESS_SECRET, SEALOS_DOMAIN } from '@/store/static';
import { INGRESS_SECRET, SEALOS_DOMAIN, SEALOS_USER_DOMAIN } from '@/store/static';
import type { AppEditType } from '@/types/app';
import { pathFormat, pathToNameFormat, str2Num, strToBase64 } from '@/utils/tools';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -270,9 +270,11 @@ export const json2Ingress = (data: AppEditType) => {
const result = data.networks
.filter((item) => item.openPublicDomain)
.map((network, i) => {
console.log(network, 'network');

const host = network.customDomain
? network.customDomain
: `${network.publicDomain}.${SEALOS_DOMAIN}`;
: `${network.publicDomain}.${network.domain}`;

const secretName = network.customDomain ? network.networkName : INGRESS_SECRET;

Expand Down

0 comments on commit 17e766e

Please sign in to comment.