From fd9e19ce856d4a8b3c654e41fca626f065e5362b Mon Sep 17 00:00:00 2001 From: leoliu Date: Mon, 20 Jul 2020 16:12:31 +0800 Subject: [PATCH] fix: Fix service session affinity settings Signed-off-by: leoliu --- src/components/Base/Form/Group.jsx | 4 +- .../AdvanceSettings/SessionAffinity/index.jsx | 58 ------------------- .../Forms/Service/AdvanceSettings/index.jsx | 39 ++++++++----- .../Volume/VolumeSettings/FormTemplate.jsx | 4 +- src/locales/en/service.js | 2 + src/locales/tc/service.js | 2 + src/locales/zh/service.js | 2 + 7 files changed, 37 insertions(+), 74 deletions(-) delete mode 100644 src/components/Forms/Service/AdvanceSettings/SessionAffinity/index.jsx diff --git a/src/components/Base/Form/Group.jsx b/src/components/Base/Form/Group.jsx index 2d42e8ff5db..2ced2904a46 100644 --- a/src/components/Base/Form/Group.jsx +++ b/src/components/Base/Form/Group.jsx @@ -94,7 +94,7 @@ export default class Group extends React.Component { } handleCheck = (e, check) => { - const { keepDataWhenUnCheck } = this.props + const { keepDataWhenUnCheck, onChange } = this.props this.setState({ isCheck: check }, () => { if (!keepDataWhenUnCheck && !check) { const { formData } = this.context @@ -102,6 +102,8 @@ export default class Group extends React.Component { this.items.forEach(item => unset(formData, item)) } } + + onChange && onChange(check) }) } diff --git a/src/components/Forms/Service/AdvanceSettings/SessionAffinity/index.jsx b/src/components/Forms/Service/AdvanceSettings/SessionAffinity/index.jsx deleted file mode 100644 index 3fea86c0400..00000000000 --- a/src/components/Forms/Service/AdvanceSettings/SessionAffinity/index.jsx +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of KubeSphere Console. - * Copyright (C) 2019 The KubeSphere Console Authors. - * - * KubeSphere Console is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KubeSphere Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with KubeSphere Console. If not, see . - */ - -import React from 'react' -import { set } from 'lodash' -import { Form } from 'components/Base' -import { NumberInput } from 'components/Inputs' - -export default class SessionAffinity extends React.Component { - get fedPreifx() { - return this.props.isFederated ? 'spec.template.' : '' - } - - componentDidMount() { - const { formTemplate } = this.props - - set( - formTemplate, - `Service.${this.fedPreifx}spec.sessionAffinity`, - 'ClientIP' - ) - } - - componentWillUnmount() { - const { formTemplate } = this.props - - set(formTemplate, `Service.${this.fedPreifx}spec.sessionAffinity`, 'None') - } - - render() { - return ( - - - - ) - } -} diff --git a/src/components/Forms/Service/AdvanceSettings/index.jsx b/src/components/Forms/Service/AdvanceSettings/index.jsx index e1587f713e1..82ad338ce81 100644 --- a/src/components/Forms/Service/AdvanceSettings/index.jsx +++ b/src/components/Forms/Service/AdvanceSettings/index.jsx @@ -17,15 +17,15 @@ */ import React from 'react' -import { get, set } from 'lodash' +import { get, set, unset } from 'lodash' import { MODULE_KIND_MAP } from 'utils/constants' import { Form } from 'components/Base' +import { NumberInput } from 'components/Inputs' import Metadata from './Metadata' import NodeSchedule from './NodeSchedule' import InternetAccess from './InternetAccess' -import SessionAffinity from './SessionAffinity' export default class AdvancedSettings extends React.Component { get namespace() { @@ -51,13 +51,16 @@ export default class AdvancedSettings extends React.Component { } handleSessionAffinityChange = value => { - const { formTemplate, noWorkload } = this.props - if (!noWorkload) { - set( - formTemplate, - `Service.${this.fedPrefix}spec.sessionAffinity`, - value ? 'clusterIP' : 'None' - ) + const { formTemplate } = this.props + + set( + formTemplate, + `Service.${this.fedPrefix}spec.sessionAffinity`, + value ? 'ClientIP' : 'None' + ) + + if (!value) { + unset(formTemplate, `Service.${this.fedPrefix}spec.sessionAffinityConfig`) } } @@ -88,12 +91,22 @@ export default class AdvancedSettings extends React.Component { - + + + {!noWorkload && ( . */ -import { get, isNaN } from 'lodash' +import { get, isNaN, unset } from 'lodash' import React from 'react' import { toJS } from 'mobx' @@ -146,7 +146,7 @@ export default class VolumeSettings extends React.Component { const newStorageClass = storageClasses.find(item => item.name === value) || {} - this.context.formData[ACCESSMODE_KEY] = undefined + unset(this.context.formData, ACCESSMODE_KEY) this.setState({ storageClass: newStorageClass, diff --git a/src/locales/en/service.js b/src/locales/en/service.js index 59d553c180e..d8f2b7c8196 100644 --- a/src/locales/en/service.js +++ b/src/locales/en/service.js @@ -161,4 +161,6 @@ export default { 'Specify a workload that needs to be associated with the service.', EIP_POOL_DESC: 'Access method within the cluster (DNS)', + + SERVICE_SESSION_STICKY_DESC: 'must be greater than 0 and less than 86400', } diff --git a/src/locales/tc/service.js b/src/locales/tc/service.js index 6cb81b43142..48a2479b29a 100644 --- a/src/locales/tc/service.js +++ b/src/locales/tc/service.js @@ -164,4 +164,6 @@ export default { SERVICE_PORTS_DESC: '设置容器镜像暴露的端口以及服务端口', EIP_POOL_DESC: '集群内部访问方式(DNS)', + + SERVICE_SESSION_STICKY_DESC: '最小为 0,最大为 86400', } diff --git a/src/locales/zh/service.js b/src/locales/zh/service.js index 2d88f3505d8..b4d3df41deb 100644 --- a/src/locales/zh/service.js +++ b/src/locales/zh/service.js @@ -164,4 +164,6 @@ export default { SERVICE_PORTS_DESC: '设置容器镜像暴露的端口以及服务端口', EIP_POOL_DESC: '集群内部访问方式(DNS)', + + SERVICE_SESSION_STICKY_DESC: '最小为 0,最大为 86400', }