Skip to content

Commit

Permalink
feat: 完善lbcf (tkestack#205)
Browse files Browse the repository at this point in the history
Co-authored-by: kaychen <[email protected]>
  • Loading branch information
KayIter and kaychen committed Mar 24, 2020
1 parent 14658c1 commit 3570db1
Show file tree
Hide file tree
Showing 12 changed files with 815 additions and 124 deletions.
12 changes: 9 additions & 3 deletions web/console/config/resource/k8sConfig/lbcf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const displayField: DisplayField = {
noExsitedValue: defaulNotExistedValue
},
lb: {
dataField: ['status.lbInfo.lbID'],
dataField: ['status.lbInfo.loadBalancerID'],
dataFormat: dataFormatConfig['text'],
width: '10%',
headTitle: '负载均衡对象',
Expand Down Expand Up @@ -204,8 +204,14 @@ export const lbcf = (k8sVersion: string) => {
useDetailInfo: true,
detailInfoList: {
info: [{ text: '负载均衡', value: 'lbcf' }],
yaml: [{ text: '负载均衡', value: 'lbcf' }, { text: '后端负载', value: 'lbcf_bg' }],
event: [{ text: '负载均衡', value: 'lbcf' }, { text: '后端记录', value: 'lbcf_br' }]
yaml: [
{ text: '负载均衡', value: 'lbcf' },
{ text: '后端负载', value: 'lbcf_bg' }
],
event: [
{ text: '负载均衡', value: 'lbcf' },
{ text: '后端记录', value: 'lbcf_br' }
]
}
},
displayField,
Expand Down
8 changes: 6 additions & 2 deletions web/console/src/modules/cluster/WebAPI/ClusterAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { QueryState, RecordSet, uuid } from '@tencent/ff-redux';

import { resourceConfig } from '../../../../config';
import {
Method, operationResult, reduceK8sRestfulPath, reduceNetworkRequest, reduceNetworkWorkflow,
requestMethodForAction
Method,
operationResult,
reduceK8sRestfulPath,
reduceNetworkRequest,
reduceNetworkWorkflow,
requestMethodForAction
} from '../../../../helpers';
import { Cluster, ClusterFilter, RequestParams, ResourceInfo } from '../../common/models';
import { CreateResource } from '../../common/models/CreateResource';
Expand Down
257 changes: 233 additions & 24 deletions web/console/src/modules/cluster/actions/lbcfEditActions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { initStringArray } from './../constants/initState';
import { KeyValue } from 'src/modules/common';

import { deepClone, uuid } from '@tencent/ff-redux';

import { resourceConfig } from '../../../../config/resourceConfig';
import * as ActionType from '../constants/ActionType';
import { initLbcfBackGroupEdition, initLbcfBGPort, initSelector } from '../constants/initState';
import { RootState } from '../models';
import { RootState, BackendGroup } from '../models';
import { Namespace } from '../models/Namespace';
import { ResourceFilter } from '../models/ResourceOption';
import { CLB, Selector } from '../models/ServiceEdit';
import { router } from '../router';
import * as WebAPI from '../WebAPI';
import { validateLbcfActions } from './validateLbcfActions';
import { BackendType } from '../constants/Config';
import { GameBackgroupEdition } from '../models/LbcfEdit';

type GetState = () => RootState;

Expand Down Expand Up @@ -177,6 +180,126 @@ export const lbcfEditActions = {
};
},

updateLbcfBGAddress: (backGroupId: string, id: string, object: any) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
let { staticAddress } = backGroupEdition;
let index = staticAddress.findIndex(item => item.id === id);
staticAddress[index] = Object.assign({}, staticAddress[index], object);
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

addLbcfBGAddress: (backGroupId: string) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
let { staticAddress } = backGroupEdition;

staticAddress.push(Object.assign({}, initStringArray, { id: uuid() }));
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

deleteLbcfBGAddress: (backGroupId: string, id: string) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
let { staticAddress } = backGroupEdition;
let index = staticAddress.findIndex(item => item.id === id);
staticAddress.splice(index, 1);
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

updateLbcfBGPodName: (backGroupId: string, id: string, object: any) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
let { byName } = backGroupEdition;
let index = byName.findIndex(item => item.id === id);
byName[index] = Object.assign({}, byName[index], object);
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

addLbcfBGPodName: (backGroupId: string) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
let { byName } = backGroupEdition;

byName.push(Object.assign({}, initStringArray, { id: uuid() }));
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

deleteLbcfBGPodName: (backGroupId: string, id: string) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
let { byName } = backGroupEdition;
let index = byName.findIndex(item => item.id === id);
byName.splice(index, 1);
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

initLbcfBGLabels: (backGroupId: string, labels: Selector[]) => {
return async (dispatch, getState: GetState) => {
let {
Expand Down Expand Up @@ -277,32 +400,82 @@ export const lbcfEditActions = {
};
},

initGameBGEdition: backGroups => {
initGameBGEdition: (backGroups: BackendGroup[]) => {
return async (dispatch, getState: GetState) => {
let backGroupEditions = [];
let backGroupEditions: GameBackgroupEdition[] = [];
backGroups.forEach(backGroup => {
let keys = Object.keys(backGroup.labels);
backGroupEditions.push(
Object.assign({}, initLbcfBackGroupEdition, {
id: uuid(),
name: backGroup.name,
v_name: { status: 1, message: '' },
ports: [
Object.assign({}, initLbcfBGPort, {
id: uuid(),
portNumber: backGroup.port.portNumber,
protocol: backGroup.port.protocol
})
],
labels: keys.map(key => {
return Object.assign({}, initSelector, {
id: uuid(),
key: key,
value: backGroup.labels[key]
});
if (backGroup.pods) {
let keys = backGroup.pods.labels ? Object.keys(backGroup.pods.labels) : [];
backGroupEditions.push(
Object.assign({}, initLbcfBackGroupEdition, {
id: uuid(),
name: backGroup.name,
backgroupType: BackendType.Pods,
ports: [
Object.assign({}, initLbcfBGPort, {
id: uuid(),
portNumber: backGroup.pods.port.portNumber,
protocol: backGroup.pods.port.protocol
})
],
labels: keys.map(key => {
return Object.assign({}, initSelector, {
id: uuid(),
key: key,
value: backGroup.pods.labels[key]
});
}),
byName: backGroup.pods.byName
? backGroup.pods.byName.map(name => {
return Object.assign({}, initStringArray, {
id: uuid(),
value: name
});
})
: []
})
);
} else if (backGroup.service) {
let keys = backGroup.service.nodeSelector ? Object.keys(backGroup.service.nodeSelector) : [];
backGroupEditions.push(
Object.assign({}, initLbcfBackGroupEdition, {
id: uuid(),
name: backGroup.name,
backgroupType: BackendType.Service,
ports: [
Object.assign({}, initLbcfBGPort, {
id: uuid(),
portNumber: backGroup.service.port.portNumber,
protocol: backGroup.service.port.protocol
})
],
labels: keys.map(key => {
return Object.assign({}, initSelector, {
id: uuid(),
key: key,
value: backGroup.service.nodeSelector[key]
});
}),
serviceName: backGroup.service.name
})
);
} else {
backGroupEditions.push(
Object.assign({}, initLbcfBackGroupEdition, {
id: uuid(),
name: backGroup.name,
backgroupType: BackendType.Static,
staticAddress: backGroup.static
? backGroup.static.map(name => {
return Object.assign({}, initStringArray, {
id: uuid(),
value: name
});
})
: []
})
})
);
);
}
});
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
Expand All @@ -311,6 +484,42 @@ export const lbcfEditActions = {
};
},

inputLbcfBackGroupType: (backGroupId: string, type: string) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
backGroupEdition.backgroupType = type;
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

inputLbcfBackGroupServiceName: (backGroupId: string, serviceName: string) => {
return async (dispatch, getState: GetState) => {
let {
subRoot: {
lbcfEdit: { lbcfBackGroupEditions }
}
} = getState();

let newBackGroupEdition = deepClone(lbcfBackGroupEditions);
let backGroupEdition = newBackGroupEdition.find(item => item.id === backGroupId);
backGroupEdition.serviceName = serviceName;
dispatch({
type: ActionType.GBG_UpdateLbcfBackGroup,
payload: newBackGroupEdition
});
};
},

clearEdition: () => {
return async (dispatch, getState: GetState) => {
dispatch({
Expand Down
Loading

0 comments on commit 3570db1

Please sign in to comment.