Skip to content

Commit

Permalink
fix:dbprovider number of database instances (#4580)
Browse files Browse the repository at this point in the history
* fix:dbprovider number of database instances

Signed-off-by: jingyang <3161362058@qq.com>

* fix db secret

Signed-off-by: jingyang <3161362058@qq.com>

---------

Signed-off-by: jingyang <3161362058@qq.com>
  • Loading branch information
zjy365 committed Mar 13, 2024
1 parent 4f09c0a commit fe50d09
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
5 changes: 3 additions & 2 deletions frontend/providers/dbprovider/public/locales/en/common.json
Expand Up @@ -262,5 +262,6 @@
"db instances tip": "The number of {{db}} instances is recommended to be an odd number",
"Deleting": "Deleting",
"Backup Running": "Backup Running",
"Backup Deleting": "Backup Deleting"
}
"Backup Deleting": "Backup Deleting",
"DataBase": "DataBase"
}
5 changes: 3 additions & 2 deletions frontend/providers/dbprovider/public/locales/zh/common.json
Expand Up @@ -265,5 +265,6 @@
"db instances tip": "{{db}} 实例数量建议为奇数",
"Deleting": "删除中",
"Backup Running": "备份中",
"Backup Deleting": "删除中"
}
"Backup Deleting": "删除中",
"DataBase": "数据库"
}
Expand Up @@ -94,9 +94,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
'base64'
).toString('utf-8');

const host = Buffer.from(secret.body.data[dbTypeMap[dbType].hostKey], 'base64').toString(
'utf-8'
);
const host =
Buffer.from(secret.body.data[dbTypeMap[dbType].hostKey], 'base64').toString('utf-8') +
`.${namespace}.svc`;

const port = Buffer.from(secret.body.data[dbTypeMap[dbType].portKey], 'base64').toString(
'utf-8'
Expand Down
23 changes: 11 additions & 12 deletions frontend/providers/dbprovider/src/pages/db/edit/components/Form.tsx
Expand Up @@ -173,17 +173,6 @@ const Form = ({
fontWeight: 'bold',
borderColor: 'myGray.900'
}}
// {...(activeNav === item.id
// ? {
// fontWeight: 'bold',
// borderColor: 'myGray.900',
// backgroundColor: 'myWhite.600 !important'
// }
// : {
// color: 'myGray.500',
// borderColor: 'myGray.200',
// backgroundColor: 'transparent'
// })}
>
<MyIcon
name={item.icon as any}
Expand Down Expand Up @@ -317,6 +306,12 @@ const Form = ({
value={getValues('replicas')}
min={1}
max={20}
step={
getValues('dbType') === DBTypeEnum.mongodb ||
getValues('dbType') === DBTypeEnum.mysql
? 2
: 1
}
setVal={(val) => {
register('replicas', {
required: t('Replicas Cannot Empty') || '',
Expand All @@ -329,7 +324,11 @@ const Form = ({
message: `${t('Max Replicas')}20`
}
});
setValue('replicas', val || 1);
const dbType = getValues('dbType');
const oddVal = val % 2 === 0 ? val + 1 : val;
const replicasValue =
dbType === DBTypeEnum.mongodb || dbType === DBTypeEnum.mysql ? oddVal : val;
setValue('replicas', isNaN(replicasValue) ? 1 : replicasValue);
}}
/>
{getValues('replicas') === 1 && (
Expand Down
24 changes: 21 additions & 3 deletions frontend/providers/dbprovider/src/utils/json2Yaml.ts
Expand Up @@ -111,9 +111,9 @@ export const json2CreateCluster = (data: DBEditType, backupInfo?: BackupItemType
spec: {
affinity: {
nodeLabels: {},
podAntiAffinity: 'Preferred',
podAntiAffinity: 'Required',
tenancy: 'SharedNode',
topologyKeys: []
topologyKeys: ['kubernetes.io/hostname']
},
clusterDefinitionRef: 'apecloud-mysql',
clusterVersionRef: data.dbVersion,
Expand Down Expand Up @@ -1064,6 +1064,23 @@ export const json2NetworkService = ({
weaviate: '',
milvus: ''
};
const labelMap = {
postgresql: {
'kubeblocks.io/role': 'primary'
},
mongodb: {
'kubeblocks.io/role': 'primary'
},
'apecloud-mysql': {
'kubeblocks.io/role': 'leader'
},
redis: {},
kafka: {},
qdrant: {},
nebula: {},
weaviate: {},
milvus: {}
};

const template = {
apiVersion: 'v1',
Expand All @@ -1072,7 +1089,8 @@ export const json2NetworkService = ({
name: `${dbDetail.dbName}-export`,
labels: {
'app.kubernetes.io/instance': dbDetail.dbName,
'apps.kubeblocks.io/component-name': dbDetail.dbType
'apps.kubeblocks.io/component-name': dbDetail.dbType,
...labelMap[dbDetail.dbType]
},
ownerReferences: [
{
Expand Down

0 comments on commit fe50d09

Please sign in to comment.