Skip to content

Commit

Permalink
refactor: project logic web
Browse files Browse the repository at this point in the history
* feat: fix monitor ns prefix

* feat: add project resourceLimit manage

* feat: add sub project

* feat: add project ns migrate

* feat: add project ns kubectlConfig

* feat: add bussiness project model

* feat: refator project

* feat(bussiness): add projectId requestHeader

* fix: nodeSelector can not select more node

* feat: add Import cluster

* feat: add helm namespace

* feat: add project ns kubeconfig

Co-authored-by: kaychen <[email protected]>
  • Loading branch information
KayIter and kaychen committed Jun 19, 2020
1 parent 7a4c26d commit b344a77
Show file tree
Hide file tree
Showing 88 changed files with 3,323 additions and 1,376 deletions.
Binary file modified third_party/fe_node_modules.zip
Binary file not shown.
29 changes: 19 additions & 10 deletions web/console/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@
"env": {
"development": {
"presets": [
["env", {
"loose": true,
"modules": "commonjs",
"exclude": ["babel-plugin-transform-async-to-generator", "babel-plugin-transform-regenerator", "babel-plugin-transform-es2015-spread"]
}]
[
"env",
{
"loose": true,
"modules": "commonjs",
"exclude": [
"babel-plugin-transform-async-to-generator",
"babel-plugin-transform-regenerator",
"babel-plugin-transform-es2015-spread"
]
}
]
],
"plugins": [
[
"react-transform",
{
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}]
"transforms": [
{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}
]
}
]
]
Expand Down
15 changes: 9 additions & 6 deletions web/console/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": ["eslint-config-alloy/react", "eslint-config-alloy/typescript"],
"rules": {
"@typescript-eslint/no-namespace": ["off"],
"indent": ["off"],
"no-script-url": ["off"],
"no-implicit-coercion": ["off"],
Expand Down Expand Up @@ -34,15 +35,17 @@
"react/jsx-curly-brace-presence": ["off"],
"react/sort-comp": ["off"]
},
"overrides": [{
"files": ["**/*.ts", "**/*.tsx"],
"rules": {
"no-unused-vars": ["off"]
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
"rules": {
"no-unused-vars": ["off"]
}
}
}],
],
"settings": {
"react": {
"version": "detect"
}
}
}
}
5 changes: 5 additions & 0 deletions web/console/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ const businessCommonRouterConfig: RouterConfig[] = [
title: 'Helm应用',
watchModule: ConsoleModuleEnum.PLATFORM
},
{
url: '/tkestack-project/project',
title: '业务管理',
watchModule: ConsoleModuleEnum.Business
},
{
title: '组织资源',
watchModule: [ConsoleModuleEnum.Registry, ConsoleModuleEnum.Auth],
Expand Down
7 changes: 0 additions & 7 deletions web/console/blankPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ import { Button } from '@tea/component/button';
import { Blank, BlankTheme } from '@tea/component/blank';
import { Card } from '@tea/component/card';
import { Layout } from '@tea/component/layout';
import { ExternalLink } from '@tea/component/link';
import { Radio } from '@tea/component/radio';
import { ContentView } from '@tencent/tea-component';

const { Body, Content } = Layout;

function BlankExample() {
/**
* @type [any, any]
*/
const [theme, setTheme] = useState('permission');

return (
<ContentView>
<ContentView.Body>
Expand Down
8 changes: 8 additions & 0 deletions web/console/config/resource/common/apiVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ApiVersion {
helm?: ResourceApiInfo;
logcs?: ResourceApiInfo;
clustercredential?: ResourceApiInfo;
auth_project?: ResourceApiInfo;

lbcf?: ResourceApiInfo;
lbcf_bg?: ResourceApiInfo;
Expand Down Expand Up @@ -389,6 +390,13 @@ const k8sApiVersionFor18: ApiVersion = {
watchModule: ConsoleModuleEnum.Auth,
headTitle: 'Users'
},
auth_project: {
group: authServerVersion.group,
version: authServerVersion.version,
basicEntry: authServerVersion.basicUrl,
watchModule: ConsoleModuleEnum.Auth,
headTitle: 'PorjectUsers'
},
role: {
group: authServerVersion.group,
version: authServerVersion.version,
Expand Down
11 changes: 11 additions & 0 deletions web/console/config/resource/k8sConfig/otherResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ export const user = (k8sVersion: string) => {
});
};

/** users的配置 */
export const auth_project = (k8sVersion: string) => {
return generateResourceInfo({
k8sVersion,
resourceName: 'auth_project',
requestType: {
list: 'projects'
}
});
};

/** roles的配置 */
export const role = (k8sVersion: string) => {
return generateResourceInfo({
Expand Down
2 changes: 2 additions & 0 deletions web/console/config/resourceConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { auth_project } from './resource/k8sConfig/otherResource';
import {
deployment,
statefulset,
Expand Down Expand Up @@ -181,6 +182,7 @@ export const resourceConfig = (k8sVersion: string = '1.16'): ResourceConfigKey =
role: getResourceConfig(role, finalK8sVersion),
localgroup: getResourceConfig(localgroup, finalK8sVersion),
group: getResourceConfig(group, finalK8sVersion),
auth_project: getResourceConfig(auth_project, finalK8sVersion),
/** =============== 这里是权限相关的 =============== */

/** 告警配置 */
Expand Down
19 changes: 15 additions & 4 deletions web/console/helpers/appUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ export function getClusterId(): string {
return rId;
}

/**
* 设置默认集群
*/
export function setProjectName(projectId: string) {
util.cookie.set('projectId', projectId);
}

export function getProjectName(): string {
let rId = util.cookie.get('projectId');
return rId;
}

/**
* 设置默认集群
*/
Expand All @@ -62,7 +74,6 @@ export function setClusterId(clusterId: string) {
localStorage[util.getUin() + '_clusterId'] = clusterId;
}
}

/**
* 获取当前默认的集群命名空间
*/
Expand Down Expand Up @@ -145,7 +156,7 @@ export function setRegionList(list: string[]) {

export function debounce(fn, delay: number, immediate?: boolean) {
let timer = null;
return function() {
return function () {
const that = this;
const args = arguments; // 箭头函数不能用arguments参数
if (timer) {
Expand All @@ -158,12 +169,12 @@ export function debounce(fn, delay: number, immediate?: boolean) {
}

// 过了delay时间,设置判定条件timer = null; 上边才可以响应
timer = setTimeout(function() {
timer = setTimeout(function () {
timer = null;
}, delay);
} else {
// 每次触发都要delay时间之后才响应
timer = setTimeout(function() {
timer = setTimeout(function () {
fn.apply(that, args);
}, delay);
}
Expand Down
35 changes: 35 additions & 0 deletions web/console/helpers/downloadText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const tips = seajs.require('tips');
import { t, Trans } from '@tencent/tea-app/lib/i18n';

export function downloadText(crtText, filename, contentType = 'text/plain;charset=utf-8;') {
let crtFile = '\ufeff';
let userAgent = navigator.userAgent;

if (navigator.msSaveBlob) {
let blob = new Blob([crtText], { type: contentType });
navigator.msSaveBlob(blob, filename);
} else if (userAgent.indexOf('MSIE 9.0') > 0) {
tips.error(t('该浏览器暂不支持导出功能'));
} else {
let blob = new Blob([crtText], { type: contentType });
let link = document.createElement('a') as any;

if (link.download !== undefined) {
let url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', filename);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
}

export function downloadCrt(crtText, filename = 'cluster-ca.crt') {
downloadText(crtText, filename, 'text/plain;charset=utf-8;');
}

export function downloadKubeconfig(crtText, filename = 'kubeconfig') {
downloadText(crtText, filename, 'applicatoin/octet-stream;charset=utf-8;');
}
2 changes: 1 addition & 1 deletion web/console/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export { getScrollBarSize } from './getScrollBarSize';
export { dateFormat } from './dateUtil';
export * from './appUtil';
export { getCookie } from './cookieUtil';
export { reduceK8sQueryString, reduceK8sRestfulPath, reduceNs } from './urlUtil';
export { reduceK8sQueryString, reduceK8sRestfulPath, reduceNs, parseQueryString } from './urlUtil';
46 changes: 25 additions & 21 deletions web/console/helpers/reduceNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import axios from 'axios';
import { OperationResult } from '@tencent/ff-redux';
import { RequestParams, ResourceInfo } from '../src/modules/common/models';
import { changeForbiddentConfig } from '../index';
import { parseQueryString } from './urlUtil';
import { getProjectName } from './appUtil';

/** 是否展示没有权限的弹窗 */
export let Init_Forbiddent_Config = {
Expand Down Expand Up @@ -71,16 +73,8 @@ export const requestMethodForAction = (type: string) => {
* 统一的请求处理
* @param userParams: RequestParams
*/
export const reduceNetworkRequest = async (userParams: RequestParams, clusterId?: string, projectId?: string, keyword?: string) => {
let {
method,
url,
userDefinedHeader = {},
data = {},
apiParams,
// baseURL = getConsoleAPIAddress(ConsoleModuleAddressEnum.PLATFORM)
baseURL = GET_CONSOLE_MODULE_BASE_URL
} = userParams;
export const reduceNetworkRequest = async (userParams: RequestParams, clusterId?: string, keyword?: string) => {
let { method, url, userDefinedHeader = {}, data = {}, apiParams, baseURL = GET_CONSOLE_MODULE_BASE_URL } = userParams;

let rsp;
// 请求tke-apiserver的 cluster的header
Expand All @@ -89,16 +83,26 @@ export const reduceNetworkRequest = async (userParams: RequestParams, clusterId?
'X-TKE-ClusterName': clusterId
});
}
if (projectId) {
userDefinedHeader = Object.assign({}, userDefinedHeader, {
'X-TKE-ProjectName': projectId
});
}
if (keyword) {
userDefinedHeader = Object.assign({}, userDefinedHeader, {
'X-TKE-FuzzyResourceName': keyword
});

/// #if project
let searchParams;
try {
searchParams = parseQueryString(location.search);
} catch (error) {}
let projectId = '';
if (searchParams && (searchParams.projectName || searchParams.projectId)) {
projectId = searchParams.projectName || searchParams.projectId;
} else {
projectId = getProjectName();
}
userDefinedHeader = Object.assign(
{},
{
'X-TKE-ProjectName': projectId
},
userDefinedHeader
);
/// #endif

let params = {
method,
Expand All @@ -125,7 +129,7 @@ export const reduceNetworkRequest = async (userParams: RequestParams, clusterId?
} catch (error) {
// 如果返回是 401的话,自动登出,此时是鉴权不过,cookies失效了
if (error.response && error.response.status === 401) {
// location.reload();
location.reload();
} else if (error.response && error.response.status === 403) {
changeForbiddentConfig({
isShow: true,
Expand Down Expand Up @@ -182,7 +186,7 @@ export const reduceNetworkWorkflow = (error: any) => {
* @param target T[]
* @param error any
*/
export const operationResult = function<T>(target: T[] | T, error?: any): OperationResult<T>[] {
export const operationResult = function <T>(target: T[] | T, error?: any): OperationResult<T>[] {
if (target instanceof Array) {
return target.map(x => ({ success: !error, target: x, error }));
}
Expand Down
1 change: 0 additions & 1 deletion web/console/helpers/urlUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export const reduceK8sRestfulPath = (options: K8sRestfulPathOptions) => {
resourceInfo,
namespace = '',
isSpetialNamespace = false,
middleKey = '',
specificName = '',
extraResource = '',
clusterId = '',
Expand Down
14 changes: 14 additions & 0 deletions web/console/index.project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AlarmPolicy } from '@src/modules/alarmPolicy';
import { Notify } from '@src/modules/notify';
// 公有云的图表组件为异步加载,这里为了减少路径配置,还是保留为同步加载,预先import即可变成不split
import '@tencent/tchart/build/ChartsComponents';
import { Project } from '@src/modules/project';
insertCSS(
'myTagSearchBox',
`.myTagSearchBox{ width:100% !important; background-color: #fff; }
Expand Down Expand Up @@ -113,6 +114,19 @@ Entry.register({
)
},

/**
* @url https://{{domain}}/tkestack-project/project
*/
project: {
title: t('业务管理 - TKEStack业务侧'),
container: (
<Wrapper platformType={PlatformTypeEnum.Business}>
<ForbiddentDialog />
<Project />
</Wrapper>
)
},

/**
* @urlhttps://{{domain}}//tkestack-project/regitry
*/
Expand Down
8 changes: 3 additions & 5 deletions web/console/lib/ff-component/src/formpanel/TransferTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function FormPanelTransferTable<TResource = any>({ ...props }: FormPanelTransfer
<Transfer.Cell
title={
title +
t(' 共{{totalCount}}项 已加载 {{count}} 项', {
totalCount: finallist.data.recordCount,
t(' 已加载 {{count}} 项', {
// totalCount: finallist.data.recordCount,
count: finallist.data.records.length
})
}
Expand All @@ -143,9 +143,7 @@ function FormPanelTransferTable<TResource = any>({ ...props }: FormPanelTransfer
bottomTip={
isNeedScollLoding && finallist.data.records.length < finallist.data.recordCount ? (
<LoadingTip />
) : (
undefined
)
) : undefined
}
scrollable={scrollableOption}
selectable={{
Expand Down
Loading

0 comments on commit b344a77

Please sign in to comment.