Skip to content

Commit

Permalink
Fix/20200317 (#189)
Browse files Browse the repository at this point in the history
* fix: fix projectPanel create dp failed

* fix: fix object

Co-authored-by: kaychen <[email protected]>
  • Loading branch information
KayIter and kaychen committed Mar 17, 2020
1 parent 91844da commit 15438a3
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 54 deletions.
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 } from './urlUtil';
export { reduceK8sQueryString, reduceK8sRestfulPath, reduceNs } from './urlUtil';
32 changes: 28 additions & 4 deletions web/console/helpers/urlUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ export const reduceK8sRestfulPath = (options: K8sRestfulPathOptions) => {
/// #if project
//业务侧ns eg: cls-xxx-ns 需要去除前缀
if (namespace) {
namespace = namespace
.split('-')
.splice(2)
.join('-');
namespace = namespace.startsWith('global')
? namespace
.split('-')
.splice(1)
.join('-')
: namespace
.split('-')
.splice(2)
.join('-');
}
/// #endif
let url: string = '';
Expand Down Expand Up @@ -163,3 +168,22 @@ export const reduceK8sRestfulPath = (options: K8sRestfulPathOptions) => {
}
return url;
};

export function reduceNs(namesapce) {
let newNs = namesapce;
/// #if project
//业务侧ns eg: cls-xxx-ns 需要去除前缀
if (newNs) {
newNs = newNs.startsWith('global')
? newNs
.split('-')
.splice(1)
.join('-')
: newNs
.split('-')
.splice(2)
.join('-');
}
/// #endif
return newNs;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const restActions = {
};

dispatch({
type: FFReduxActionName.CLUSTER + '_FetchDone',
type: FFReduxActionName.CLUSTER + '_BaseDone',
payload: {
data: result,
trigger: 'Done'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { WorkflowDialog } from '../../../../common/components';
import { allActions } from '../../../actions';
import { CreateResource, RsEditJSONYaml } from '../../../models';
import { RootProps } from '../../ClusterApp';
import { reduceNs } from '../../../../../../helpers';

const mapDispatchToProps = dispatch =>
Object.assign({}, bindActionCreators({ actions: allActions }, dispatch), { dispatch });
Expand Down Expand Up @@ -36,7 +37,7 @@ export class ResourceRollbackDialog extends React.Component<RootProps, {}> {
let resource: CreateResource = {
id: uuid(),
resourceInfo,
namespace: route.queries['np'],
namespace: reduceNs(route.queries['np']),
clusterId: route.queries['clusterId'],
resourceIns,
jsonData: JSON.stringify(jsonData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import { Button, Text } from '@tea/component';
import { bindActionCreators, isSuccessWorkflow, OperationState, uuid } from '@tencent/ff-redux';
import { t, Trans } from '@tencent/tea-app/lib/i18n';

import {
FormItem, InputField, LinkButton, SelectList, TipInfo
} from '../../../../common/components';
import { FormItem, InputField, LinkButton, SelectList, TipInfo } from '../../../../common/components';
import { FormLayout, MainBodyLayout } from '../../../../common/layouts';
import { getWorkflowError } from '../../../../common/utils';
import { allActions } from '../../../actions';
import { validateCMActions } from '../../../actions/validateCMActions';
import { CreateResource } from '../../../models';
import { router } from '../../../router';
import { RootProps } from '../../ClusterApp';
import { reduceNs } from '../../../../../../helpers';

const ButtonBarStyle = { marginBottom: '5px' };

Expand Down Expand Up @@ -243,7 +242,7 @@ export class EditConfigMapPanel extends React.Component<RootProps, {}> {
apiVersion: (resourceInfo.group ? resourceInfo.group + '/' : '') + resourceInfo.version,
metadata: {
name: name,
namespace: namespace
namespace: reduceNs(namespace)
},
data: cmEdit.variables.reduce((prev, next) => {
return Object.assign({}, prev, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import * as React from 'react';
import { connect } from 'react-redux';

import {
Bubble, Button, ContentView, FormItem, Input, Justify, List, Select, Text
} from '@tea/component';
import { Bubble, Button, ContentView, FormItem, Input, Justify, List, Select, Text } from '@tea/component';
import { FormPanel } from '@tencent/ff-component';
import {
bindActionCreators, deepClone, isSuccessWorkflow, OperationState, uuid
} from '@tencent/ff-redux';
import { bindActionCreators, deepClone, isSuccessWorkflow, OperationState, uuid } from '@tencent/ff-redux';
import { t, Trans } from '@tencent/tea-app/lib/i18n';

import { resourceConfig } from '../../../../../../config';
Expand All @@ -19,6 +15,7 @@ import { CreateResource, LbcfBGJSONYaml, MergeType } from '../../../models';
import { router } from '../../../router';
import { RootProps } from '../../ClusterApp';
import { EditLbcfBackGroupItemPanel } from './EditLbcfBackGroupItemPanel';
import { reduceNs } from '../../../../../../helpers';

const mapDispatchToProps = dispatch =>
Object.assign({}, bindActionCreators({ actions: allActions }, dispatch), { dispatch });
Expand Down Expand Up @@ -197,7 +194,7 @@ export class EditLbcfBackGroupPanel extends React.Component<RootProps, {}> {
apiVersion: 'lbcf.tkestack.io/v1beta1', //(resourceInfo.group ? resourceInfo.group + '/' : '') + resourceInfo.version,
metadata: {
name: name,
namespace: namespace
namespace: reduceNs(namespace)
},
spec: {
lbName: resourceIns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { k8sVersionList, LbcfArgsConfig, LbcfConfig } from '../../../constants/C
import { CreateResource, LbcfLBJSONYaml } from '../../../models';
import { router } from '../../../router';
import { RootProps } from '../../ClusterApp';
import { reduceNs } from '../../../../../../helpers';

const mapDispatchToProps = dispatch =>
Object.assign({}, bindActionCreators({ actions: allActions }, dispatch), { dispatch });
Expand Down Expand Up @@ -213,7 +214,7 @@ export class EditLbcfPanel extends React.Component<RootProps, {}> {
apiVersion: 'lbcf.tkestack.io/v1beta1', //(resourceInfo.group ? resourceInfo.group + '/' : '') + resourceInfo.version,
metadata: {
name: name,
namespace: namespace
namespace: reduceNs(namespace)
},
spec: {
lbDriver: 'lbcf-clb-driver',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { connect } from 'react-redux';

import { Button, Radio, Select, Text } from '@tea/component';
import { FormPanel } from '@tencent/ff-component';
import {
bindActionCreators, insertCSS, isSuccessWorkflow, OperationState, uuid
} from '@tencent/ff-redux';
import { bindActionCreators, insertCSS, isSuccessWorkflow, OperationState, uuid } from '@tencent/ff-redux';
import { t, Trans } from '@tencent/tea-app/lib/i18n';

import { resourceConfig } from '../../../../../../config/resourceConfig';
Expand All @@ -17,12 +15,23 @@ import { getWorkflowError, isEmpty } from '../../../../common/utils';
import { allActions } from '../../../actions';
import { validateWorkloadActions } from '../../../actions/validateWorkloadActions';
import {
affinityType, NodeAbnormalStrategy, ResourceTypeList, RestartPolicyTypeList,
WorkloadNetworkTypeEnum
affinityType,
NodeAbnormalStrategy,
ResourceTypeList,
RestartPolicyTypeList,
WorkloadNetworkTypeEnum
} from '../../../constants/Config';
import {
Computer, ContainerItem, CreateResource, DifferentInterfaceResourceOperation, HealthCheckItem,
HpaEditJSONYaml, MetricOption, ServiceEditJSONYaml, VolumeItem, WorkloadEditJSONYaml
Computer,
ContainerItem,
CreateResource,
DifferentInterfaceResourceOperation,
HealthCheckItem,
HpaEditJSONYaml,
MetricOption,
ServiceEditJSONYaml,
VolumeItem,
WorkloadEditJSONYaml
} from '../../../models';
import { AffinityRule } from '../../../models/WorkloadEdit';
import { router } from '../../../router';
Expand All @@ -34,12 +43,11 @@ import { EditResourceLabelPanel } from './EditResourceLabelPanel';
import { EditResourceVolumePanel } from './EditResourceVolumePanel';
import { EditServiceAdvanceSettingPanel } from './EditServiceAdvanceSettingPanel';
import { EditServiceCommunicationPanel } from './EditServiceCommunicationPanel';
import {
ReduceServiceAnnotations, ReduceServiceJSONData, ReduceServicePorts
} from './EditServicePanel';
import { ReduceServiceAnnotations, ReduceServiceJSONData, ReduceServicePorts } from './EditServicePanel';
import { EditServicePortMapPanel } from './EditServicePortMapPanel';
import { ResourceEditHostPathDialog } from './ResourceEditHostPathDialog';
import { ResourceSelectConfigDialog } from './ResourceSelectConfigDialog';
import { reduceNs } from '../../../../../../helpers';

/** service YAML当中的type映射 */
const serviceTypeMap = {
Expand Down Expand Up @@ -625,7 +633,7 @@ export class EditResourceVisualizationPanel extends React.Component<RootProps, E
apiVersion: (workloadResourceInfo.group ? workloadResourceInfo.group + '/' : '') + workloadResourceInfo.version,
metadata: {
name: workloadName,
namespace: namespace,
namespace: reduceNs(namespace),
labels: labelsInfo,
annotations: isEmpty(annotations) ? undefined : annotations
},
Expand Down Expand Up @@ -757,7 +765,7 @@ export class EditResourceVisualizationPanel extends React.Component<RootProps, E
apiVersion: (resourceInfo.group ? resourceInfo.group + '/' : '') + resourceInfo.version,
metadata: {
name: workloadName,
namespace: namespace
namespace: reduceNs(namespace)
},
spec: {
scaleTargetRef: {
Expand Down Expand Up @@ -828,7 +836,7 @@ export class EditResourceVisualizationPanel extends React.Component<RootProps, E
apiVersion: (resourceInfo.group ? resourceInfo.group + '/' : '') + resourceInfo.version,
metadata: {
name: workloadName,
namespace: namespace,
namespace: reduceNs(namespace),
labels: {
'qcloud-app': workloadName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { connect } from 'react-redux';

import { Bubble, Button, Table, TableColumn } from '@tea/component';
import { stylize } from '@tea/component/table/addons/stylize';
import {
bindActionCreators, FetchState, isSuccessWorkflow, OperationState, uuid
} from '@tencent/ff-redux';
import { bindActionCreators, FetchState, isSuccessWorkflow, OperationState, uuid } from '@tencent/ff-redux';
import { t, Trans } from '@tencent/tea-app/lib/i18n';

import {
ButtonBar, FormItem, InputField, ResourceSelectorGeneric, ResourceSelectorInfoRow,
ResourceSelectorProps, TipInfo
ButtonBar,
FormItem,
InputField,
ResourceSelectorGeneric,
ResourceSelectorInfoRow,
ResourceSelectorProps,
TipInfo
} from '../../../../common/components';
import { FormLayout, MainBodyLayout } from '../../../../common/layouts';
import { getWorkflowError } from '../../../../common/utils';
Expand All @@ -21,6 +24,7 @@ import { SecretTypeList } from '../../../constants/Config';
import { CreateResource, Namespace, SecretData, SecretEditJSONYaml } from '../../../models';
import { router } from '../../../router';
import { RootProps } from '../../ClusterApp';
import { reduceNs } from '../../../../../../helpers';

const secretTypeTip = {
Opaque: t('适用于保存秘钥证书和配置文件,Value将以base64格式编码'),
Expand Down Expand Up @@ -345,7 +349,7 @@ export class EditSecretPanel extends React.Component<RootProps, EditSecretPanelS
apiVersion: (resourceInfo.group ? resourceInfo.group + '/' : '') + resourceInfo.version,
metadata: {
name: name,
namespace: item.name,
namespace: reduceNs(item.name),
labels: {
'qcloud-app': name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import { getWorkflowError, isEmpty } from '../../../../common/utils';
import { allActions } from '../../../actions';
import { validateServiceActions } from '../../../actions/validateServiceActions';
import { SessionAffinity } from '../../../constants/Config';
import {
CreateResource, PortMap, ServiceEdit, ServiceEditJSONYaml, ServicePorts
} from '../../../models';
import { CreateResource, PortMap, ServiceEdit, ServiceEditJSONYaml, ServicePorts } from '../../../models';
import { router } from '../../../router';
import { RootProps } from '../../ClusterApp';
import { EditServiceAdvanceSettingPanel } from './EditServiceAdvanceSettingPanel';
import { EditServiceCommunicationPanel } from './EditServiceCommunicationPanel';
import { EditServicePortMapPanel } from './EditServicePortMapPanel';
import { EditServiceWorkloadDialog } from './EditServiceWorkloadDialog';
import { reduceNs } from '../../../../../../helpers';

/** service YAML当中的type映射 */
export const ServiceTypeMap = {
Expand Down Expand Up @@ -108,7 +107,7 @@ export const ReduceServiceJSONData = (dataObj: {
apiVersion: (resourceInfo.group ? resourceInfo.group + '/' : '') + resourceInfo.version,
metadata: {
name: serviceName,
namespace: namespace,
namespace: reduceNs(namespace),
annotations: isEmpty(annotations) ? undefined : annotations
},
spec: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import * as React from 'react';
import { connect } from 'react-redux';

import { Button } from '@tea/component';
import {
bindActionCreators, FetchState, isSuccessWorkflow, OperationState, uuid
} from '@tencent/ff-redux';
import { bindActionCreators, FetchState, isSuccessWorkflow, OperationState, uuid } from '@tencent/ff-redux';
import { t } from '@tencent/tea-app/lib/i18n';

import { resourceConfig } from '../../../../../../config';
Expand All @@ -13,12 +11,11 @@ import { FormLayout, MainBodyLayout } from '../../../../common/layouts';
import { getWorkflowError } from '../../../../common/utils';
import { allActions } from '../../../actions';
import { validateWorkloadActions } from '../../../actions/validateWorkloadActions';
import {
CreateResource, HpaEditJSONYaml, HpaMetrics, MetricOption, WorkloadEditJSONYaml
} from '../../../models';
import { CreateResource, HpaEditJSONYaml, HpaMetrics, MetricOption, WorkloadEditJSONYaml } from '../../../models';
import { router } from '../../../router';
import { RootProps } from '../../ClusterApp';
import { EditResourceContainerNumPanel } from '../resourceEdition/EditResourceContainerNumPanel';
import { reduceNs } from '../../../../../../helpers';

/** 加载中的样式 */
const loadingElement = (
Expand Down Expand Up @@ -159,7 +156,7 @@ export class UpdateWorkloadPodNumPanel extends React.Component<RootProps, {}> {
apiVersion: (hpaResourceInfo.group ? hpaResourceInfo.group + '/' : '') + hpaResourceInfo.version,
metadata: {
name: workloadName,
namespace,
namespace: reduceNs(namespace),
labels: {
'qcloud-app': workloadName
}
Expand Down
8 changes: 3 additions & 5 deletions web/console/src/modules/helm/actions/createActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { generateFetcherActionCreator } from '@tencent/qcloud-redux-fetcher';
import { t } from '@tencent/tea-app/lib/i18n';

import { resourceConfig } from '../../../../config';
import { assureRegion } from '../../../../helpers';
import { assureRegion, reduceNs } from '../../../../helpers';
import { Region, RegionFilter, Resource, ResourceFilter, ResourceInfo } from '../../common/models';
import { CommonAPI } from '../../common/webapi';
import * as ActionType from '../constants/ActionType';
import { FFReduxActionName, HelmResource, OtherType, TencentHubType } from '../constants/Config';
import {
HelmCreationValid, HelmKeyValue, RootState, TencenthubChart, TencenthubChartVersion
} from '../models';
import { HelmCreationValid, HelmKeyValue, RootState, TencenthubChart, TencenthubChartVersion } from '../models';
import { router } from '../router';
import * as WebAPI from '../WebAPI';
import { helmActions } from './helmActions';
Expand Down Expand Up @@ -140,7 +138,7 @@ export const createActions = {
options['password'] = otherPassword;
}
/// #if project
kvs.push({ key: 'NAMESPACE', value: getState().namespaceSelection });
kvs.push({ key: 'NAMESPACE', value: reduceNs(getState().namespaceSelection) });
/// #endif
let response = await WebAPI.createHelmByOther(options, region.selection.value, clusterSelection);
}
Expand Down

0 comments on commit 15438a3

Please sign in to comment.