diff --git a/src/pages/cluster/containers/Cluster/actions/Create/Cluster.jsx b/src/pages/cluster/containers/Cluster/actions/Create/Cluster.jsx index 826630b1..0a605cdc 100644 --- a/src/pages/cluster/containers/Cluster/actions/Create/Cluster.jsx +++ b/src/pages/cluster/containers/Cluster/actions/Create/Cluster.jsx @@ -28,6 +28,9 @@ import { isNumber, } from 'utils/validate'; import { + clusterParams, + IPVersionOptions, + proxyModeOptions, containerRuntimeOption, networkPluginOption, calicoModeOption, @@ -79,35 +82,12 @@ export default class Cluster extends BaseForm { ); return { + ...clusterParams, offline: !!this.state.offline, - localRegistry: '', - // kubernetesVersion: firstK8s.value, kubernetesVersionOnline: firstK8sOnline.value, kubernetesVersionOffline: firstK8sOffline.value, - etcdDataDir: '/var/lib/etcd', - // containerRuntime - containerRuntimeType: 'containerd', - dockerVersion: '19.03.12', - dockerRootDir: '/var/lib/docker', - // containerdVersion: firstContainerd.value, containerdVersionOffline: firstContainerdOffline.value, containerdVersionOnline: firstContainerdOnline.value, - containerdRootDir: '/var/lib/containerd', - // 网络 - dnsDomain: 'cluster.local', - workerNodeVip: '169.254.169.100', - cniType: 'calico', - calicoMode: 'Overlay-Vxlan-All', - IPVersion: 'IPv4', - proxyMode: 'ipvs', - IPManger: true, - podIPv4CIDR: '172.25.0.0/24', - podIPv6CIDR: 'fd05::/120', - pod_network_underlay: 'first-found', - pod_network_underlay_v6: 'first-found', - mtu: 1440, - serviceSubnet: '10.96.0.0/16', - serviceSubnetV6: 'fd03::/112', ...this.props.context, }; } @@ -638,20 +618,7 @@ export default class Cluster extends BaseForm { label: t('proxyMode'), type: 'radio', optionType: 'default', - options: [ - { - label: 'ipvs', - value: 'ipvs', - }, - { - label: 'iptables', - value: 'iptables', - }, - { - label: 'ebpf', - value: 'ebpf', - }, - ], + options: proxyModeOptions, }, { name: 'IPManger', @@ -667,16 +634,7 @@ export default class Cluster extends BaseForm { label: t('IP Version'), type: 'radio', optionType: 'default', - options: [ - { - label: 'IPv4', - value: 'IPv4', - }, - { - label: t('IPv4 IPv6 Dual Stack'), - value: 'IPv4+IPv6', - }, - ], + options: IPVersionOptions, }, { name: 'pod_network_underlay', diff --git a/src/pages/cluster/containers/Cluster/actions/Create/Confirm.jsx b/src/pages/cluster/containers/Cluster/actions/Create/Confirm.jsx index a4f34e49..eaef5d96 100644 --- a/src/pages/cluster/containers/Cluster/actions/Create/Confirm.jsx +++ b/src/pages/cluster/containers/Cluster/actions/Create/Confirm.jsx @@ -153,7 +153,7 @@ export class ConfirmStep extends BaseForm { serviceSubnetV6, }, } = this.props; - const isDualStack = IPVersion === 'dualStack'; + const isDualStack = IPVersion === 'IPv4+IPv6'; if (isDualStack) { return [ { diff --git a/src/pages/cluster/containers/Template/cluster/actions/Create/Cluster.jsx b/src/pages/cluster/containers/Template/cluster/actions/Create/Cluster.jsx index c6802afe..635b4b8f 100644 --- a/src/pages/cluster/containers/Template/cluster/actions/Create/Cluster.jsx +++ b/src/pages/cluster/containers/Template/cluster/actions/Create/Cluster.jsx @@ -28,6 +28,9 @@ import { isNumber, } from 'utils/validate'; import { + clusterParams, + IPVersionOptions, + proxyModeOptions, containerRuntimeOption, networkPluginOption, calicoModeOption, @@ -48,34 +51,6 @@ const { templatesStore, } = rootStore; -const BASEPARAMS = { - offline: true, - localRegistry: '', - // kubernetesVersion: firstK8s?.value, - etcdDataDir: '/var/lib/etcd', - // containerRuntime - containerRuntimeType: 'containerd', - dockerVersion: '19.03.12', - dockerRootDir: '/var/lib/docker', - // containerdVersion: firstContainerd?.value, - containerdRootDir: '/var/lib/containerd', - // 网络 - dnsDomain: 'cluster.local', - workerNodeVip: '169.254.169.100', - cniType: 'calico', - calicoMode: 'Overlay-Vxlan-All', - ipvs: true, - IPVersion: 'ipv4', - IPManger: true, - podIPv4CIDR: '172.25.0.0/24', - podIPv6CIDR: 'fd05::/120', - pod_network_underlay: 'first-found', - pod_network_underlay_v6: 'first-found', - mtu: 1440, - serviceSubnet: '10.96.0.0/16', - serviceSubnetV6: 'fd03::/112', -}; - @observer export default class Cluster extends BaseForm { init() { @@ -137,7 +112,7 @@ export default class Cluster extends BaseForm { ); return { - ...BASEPARAMS, + ...clusterParams, kubernetesVersionOnline: firstK8sOnline?.value, kubernetesVersionOffline: firstK8sOffline?.value, containerdVersionOffline: firstContainerdOffline?.value, @@ -236,7 +211,7 @@ export default class Cluster extends BaseForm { get isDualStack() { const { IPVersion } = this.state; - return IPVersion === 'dualStack'; + return IPVersion === 'IPv4+IPv6'; } checkIpOrDomain = (rule, value) => { @@ -660,13 +635,11 @@ export default class Cluster extends BaseForm { hidden: !this.isCalico, }, { - name: 'ipvs', - label: t('Ipvs'), - type: 'check', - content: t('Enable Ipvs'), - tip: t( - 'IPVS (IP Virtual Server) is built on the upper layer of Netfilter and as a part of the Linux kernel to achieve load balancing at the transport layer. It is recommended to enable it.' - ), + name: 'proxyMode', + label: t('proxyMode'), + type: 'radio', + optionType: 'default', + options: proxyModeOptions, }, { name: 'IPManger', @@ -682,16 +655,7 @@ export default class Cluster extends BaseForm { label: t('IP Version'), type: 'radio', optionType: 'default', - options: [ - { - label: 'IPv4', - value: 'ipv4', - }, - { - label: t('IPv4 IPv6 Dual Stack'), - value: 'dualStack', - }, - ], + options: IPVersionOptions, }, { name: 'pod_network_underlay', diff --git a/src/pages/cluster/containers/Template/cluster/actions/Create/Confirm.jsx b/src/pages/cluster/containers/Template/cluster/actions/Create/Confirm.jsx index 5fb1e59e..cb17acf2 100644 --- a/src/pages/cluster/containers/Template/cluster/actions/Create/Confirm.jsx +++ b/src/pages/cluster/containers/Template/cluster/actions/Create/Confirm.jsx @@ -135,7 +135,7 @@ export class ConfirmStep extends BaseForm { serviceSubnetV6, }, } = this.props; - const isDualStack = IPVersion === 'dualStack'; + const isDualStack = IPVersion === 'IPv4+IPv6'; if (isDualStack) { return [ { @@ -215,7 +215,7 @@ export class ConfirmStep extends BaseForm { dnsDomain, cniType, calicoMode, - ipvs, + proxyMode, IPManger, IPVersion, mtu, @@ -253,8 +253,8 @@ export class ConfirmStep extends BaseForm { value: calicoMode, }, { - label: t('Ipvs'), - value: ipvs, + label: t('proxyMode'), + value: proxyMode, }, { label: t('IPManger'), diff --git a/src/pages/cluster/containers/Template/cluster/actions/Create/index.jsx b/src/pages/cluster/containers/Template/cluster/actions/Create/index.jsx index 605f6048..b65fa7f3 100644 --- a/src/pages/cluster/containers/Template/cluster/actions/Create/index.jsx +++ b/src/pages/cluster/containers/Template/cluster/actions/Create/index.jsx @@ -206,7 +206,7 @@ export default class Create extends StepAction { IPVersion, calicoMode, cniType, - ipvs, + proxyMode, podIPv4CIDR, podIPv6CIDR, serviceSubnet, @@ -218,9 +218,9 @@ export default class Create extends StepAction { // labels, } = values; - const dualStack = IPVersion === 'dualStack'; - // podSubnet 等于 podIPv4CIDR 和 podIPv6CIDR 逗号分隔合并 - const podSubnet = dualStack ? `${podIPv4CIDR},${podIPv6CIDR}` : podIPv4CIDR; + const isIPv4 = IPVersion === 'IPv4'; + const servicesCidr = isIPv4 ? [podIPv4CIDR] : [podIPv4CIDR, podIPv6CIDR]; + const podCidr = isIPv4 ? [serviceSubnet] : [serviceSubnet, serviceSubnetV6]; const { IPv4AutoDetection, IPv6AutoDetection } = computeAutoDetection(values); @@ -233,54 +233,48 @@ export default class Create extends StepAction { ? kubernetesVersionOffline : kubernetesVersionOnline, containerRuntime: { - containerRuntimeType, + type: containerRuntimeType, ...(containerRuntimeType === 'docker' ? { - docker: { - version: dockerVersion, - insecureRegistry: this.getRegistry(dockerInsecureRegistry), // dockerInsecureRegistry, - rootDir: dockerRootDir, - }, + version: dockerVersion, + insecureRegistry: this.getRegistry(dockerInsecureRegistry), // dockerInsecureRegistry, + rootDir: dockerRootDir, } : { - containerd: { - version: offline - ? containerdVersionOffline - : containerdVersionOnline, - insecureRegistry: this.getRegistry(containerdInsecureRegistry), - rootDir: containerdRootDir, - }, + version: offline + ? containerdVersionOffline + : containerdVersionOnline, + insecureRegistry: this.getRegistry(containerdInsecureRegistry), + rootDir: containerdRootDir, }), }, networking: { - serviceSubnet: dualStack - ? `${serviceSubnet},${serviceSubnetV6}` - : serviceSubnet, - dnsDomain, - podSubnet, - }, - kubeComponents: { - kubeProxy: { - ipvs, + ipFamily: IPVersion, + services: { + cidrBlocks: servicesCidr, }, - etcd: { - dataDir: etcdDataDir, + dnsDomain, + pods: { + cidrBlocks: podCidr, }, - cni: { - type: cniType, - podIPv4CIDR, - podIPv6CIDR, + workerNodeVip, + proxyMode, + }, + kubeProxy: {}, + etcd: { + dataDir: etcdDataDir, + }, + cni: { + type: cniType, + calico: { + IPv4AutoDetection, + IPv6AutoDetection, + mode: calicoMode, + IPManger, mtu, - calico: { - IPv4AutoDetection, - IPv6AutoDetection, - mode: calicoMode, - dualStack, - IPManger, - }, }, }, - components: this.getComponents(values), + addons: this.getComponents(values), }; // eslint-disable-next-line no-console diff --git a/src/resources/cluster.jsx b/src/resources/cluster.jsx index 633b6fc6..3f85fbab 100644 --- a/src/resources/cluster.jsx +++ b/src/resources/cluster.jsx @@ -18,6 +18,31 @@ import { Link } from 'react-router-dom'; import { getRoles, nodeEnum } from 'resources/node'; import RenderOption from 'components/RenderOption'; +export const clusterParams = { + offline: true, + localRegistry: '', + etcdDataDir: '/var/lib/etcd', + containerRuntimeType: 'containerd', + dockerVersion: '19.03.12', + dockerRootDir: '/var/lib/docker', + containerdRootDir: '/var/lib/containerd', + // 网络 + dnsDomain: 'cluster.local', + workerNodeVip: '169.254.169.100', + cniType: 'calico', + calicoMode: 'Overlay-Vxlan-All', + IPVersion: 'IPv4', + proxyMode: 'ipvs', + IPManger: true, + podIPv4CIDR: '172.25.0.0/24', + podIPv6CIDR: 'fd05::/120', + pod_network_underlay: 'first-found', + pod_network_underlay_v6: 'first-found', + mtu: 1440, + serviceSubnet: '10.96.0.0/16', + serviceSubnetV6: 'fd03::/112', +}; + export const isMaster = (role) => { if (getRoles(role).includes('master')) return true; @@ -219,7 +244,7 @@ export const computeAutoDetection = (values) => { IPv6AutoDetection: v6, } = values; - const dualStack = IPVersion === 'dualStack'; + const dualStack = IPVersion === 'IPv4+IPv6'; function ipAutoDetection(underlay, ip) { if (underlay === 'first-found') return 'first-found'; @@ -282,3 +307,29 @@ export const columns = [ valueRender: 'toLocalTime', }, ]; + +export const IPVersionOptions = [ + { + label: 'IPv4', + value: 'IPv4', + }, + { + label: t('IPv4 IPv6 Dual Stack'), + value: 'IPv4+IPv6', + }, +]; + +export const proxyModeOptions = [ + { + label: 'ipvs', + value: 'ipvs', + }, + { + label: 'iptables', + value: 'iptables', + }, + { + label: 'ebpf', + value: 'ebpf', + }, +]; diff --git a/src/resources/common.js b/src/resources/common.js index ebdfb0cb..50907801 100644 --- a/src/resources/common.js +++ b/src/resources/common.js @@ -37,20 +37,20 @@ export const computeAutoDetectionReversion = (values) => { return { pod_network_underlay_v6: 'first-found', IPv6AutoDetection: '', - IPVersion: 'ipv4', + IPVersion: 'IPv4', }; } else if (val === 'first-found') { return { pod_network_underlay_v6: 'first-found', IPv6AutoDetection: '', - IPVersion: 'dualStack', + IPVersion: 'IPv4+IPv6', }; } else { const [underlay, IPv6AutoDetection] = val.split('='); return { pod_network_underlay_v6: underlay, IPv6AutoDetection, - IPVersion: 'dualStack', + IPVersion: 'IPv4+IPv6', }; } } diff --git a/src/stores/cluster.js b/src/stores/cluster.js index 3051333c..eac62fed 100644 --- a/src/stores/cluster.js +++ b/src/stores/cluster.js @@ -89,8 +89,8 @@ export default class ClusterStore extends BaseStore { } async fetchVersion(params) { - this.fetchOnlineVersion(params); - this.fetchOfflineVersion(params); + await this.fetchOnlineVersion(params); + await this.fetchOfflineVersion(params); } async fetchOnlineVersion(params) { diff --git a/src/utils/object.mapper.js b/src/utils/object.mapper.js index 02ad07af..0960de5d 100644 --- a/src/utils/object.mapper.js +++ b/src/utils/object.mapper.js @@ -142,27 +142,26 @@ const ClusterMapper = (item) => { const ClusterTemplateMapper = (item) => { const { config } = item; - const IPv4AutoDetection = get( - config, - 'kubeComponents.cni.calico.IPv4AutoDetection' - ); - const IPv6AutoDetection = get( - config, - 'kubeComponents.cni.calico.IPv6AutoDetection' - ); + const IPv4AutoDetection = get(config, 'cni.calico.IPv4AutoDetection'); + const IPv6AutoDetection = get(config, 'cni.calico.IPv6AutoDetection'); const podNetwork = computeAutoDetectionReversion({ IPv4AutoDetection, IPv6AutoDetection, }); + const [podIPv4CIDR, podIPv6CIDR] = get(config, 'networking.pods.cidrBlocks'); + const [serviceSubnet, serviceSubnetV6] = get( + config, + 'networking.services.cidrBlocks' + ); + const isDualStack = get(item, 'networking.ipFamily') === 'IPv4+IPv6'; const offline = get(config, 'offline'); const kubernetesVersion = get(config, 'kubernetesVersion'); const kubernetesVersionOnline = !offline && kubernetesVersion; const kubernetesVersionOffline = offline && kubernetesVersion; - const containerdVersion = get(config, 'containerRuntime.containerd.version'); - const containerdVersionOnline = !offline && containerdVersion; - const containerdVersionOffline = offline && containerdVersion; + const containerRuntimeVersion = get(config, 'containerRuntime.version'); + const containerRuntimeType = get(config, 'containerRuntime.type'); const result = { offline, @@ -172,45 +171,45 @@ const ClusterTemplateMapper = (item) => { kubernetesVersion, kubernetesVersionOnline, kubernetesVersionOffline, - containerRuntimeType: get(config, 'containerRuntime.containerRuntimeType'), - dockerVersion: get(config, 'containerRuntime.docker.dockerVersion'), - dockerInsecureRegistry: get( - config, - 'containerRuntime.docker.insecureRegistry' - ), - dockerRootDir: get(config, 'containerRuntime.docker.rootDir'), - containerdVersion, - containerdVersionOnline, - containerdVersionOffline, - containerdInsecureRegistry: get( + containerRuntimeType, + [`${containerRuntimeType}Version`]: containerRuntimeVersion, + [`${containerRuntimeType}VersionOnline`]: + !offline && containerRuntimeVersion, + [`${containerRuntimeType}VersionOffline`]: + offline && containerRuntimeVersion, + + [`${containerRuntimeType}RootDir`]: get(config, 'containerRuntime.rootDir'), + [`${containerRuntimeType}InsecureRegistry`]: get( config, - 'containerRuntime.containerd.insecureRegistry', - [] + 'containerRuntime.insecureRegistry' ) .filter((val) => !!val) .map((val, index) => ({ value: val, index, })), - containerdRootDir: get(config, 'containerRuntime.containerd.rootDir'), // networking - serviceSubnet: get(config, 'networking.serviceSubnet'), + podIPv4CIDR, + podIPv6CIDR, + serviceSubnet, + serviceSubnetV6, + isDualStack, + IPVersion: get(config, 'networking.ipFamily'), dnsDomain: get(config, 'networking.dnsDomain'), podSubnet: get(config, 'networking.podSubnet'), - // kubeComponents - ipvs: get(config, 'kubeComponents.kubeProxy.ipvs'), - etcdDataDir: get(config, 'kubeComponents.etcd.dataDir'), - cniType: get(config, 'kubeComponents.cni.type'), - podIPv4CIDR: get(config, 'kubeComponents.cni.podIPv4CIDR'), - podIPv6CIDR: get(config, 'kubeComponents.cni.podIPv6CIDR'), - mtu: get(config, 'kubeComponents.cni.mtu'), - IPv4AutoDetection, - IPv6AutoDetection, - calicoMode: get(config, 'kubeComponents.cni.calico.mode'), - dualStack: get(config, 'kubeComponents.cni.calico.dualStack'), - IPManger: get(config, 'kubeComponents.cni.calico.IPManger'), + proxyMode: get(config, 'networking.proxyMode'), + // etcd + etcdDataDir: get(config, 'etcd.dataDir'), + // cni + cniType: get(config, 'cni.type'), + mtu: get(config, 'cni.calico.mtu'), + IPv4AutoDetection: get(config, 'cni.calico.IPv4AutoDetection'), + IPv6AutoDetection: get(config, 'cni.calico.IPv6AutoDetection'), + calicoMode: get(config, 'cni.calico.mode'), + IPManger: get(config, 'cni.calico.IPManger'), availableComponents: get(config, 'components'), ...podNetwork, + _originData: item, }; return result;