Skip to content

Commit

Permalink
--story=120477691 【集群管理】新增GKE集群创建 (merge request !2097)
Browse files Browse the repository at this point in the history
Squash merge branch 'feat/cluster-add-GKE' into 'master'
feat:--story=120477691 【集群管理】新增GKE集群创建

TAPD: --story=120477691
  • Loading branch information
v_yfqnyang authored and hitozhang committed Nov 14, 2024
1 parent 46f44bc commit a17aaef
Show file tree
Hide file tree
Showing 22 changed files with 3,482 additions and 56 deletions.
9 changes: 9 additions & 0 deletions bcs-ui/frontend/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export const SECRET_REGEX = '^[0-9a-zA-Z-~]+$';
export const SECRETKEY_REGEX = '^[0-9a-zA-Z/-]+$';
export const CLUSTER_NAME_REGEX = '^[0-9A-Za-z][A-Za-z0-9-_]*';

// 只能包含小写字母([a-z])、数字字符([0-9])、下划线(_)和破折号(-),并且必须以字母开头
export const GKE_LABEL_NAME_REGEX = '^[a-z][a-z0-9_-]*$';

// 内网cidr 正则
export const INTRANET_CIDR_REGEX = '\\b(10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|172\\.(1[6-9]|2[0-9]|3[0-1])\\.\\d{1,3}\\.\\d{1,3}|192\\.168\\.\\d{1,3}\\.\\d{1,3})\\/([0-9]|[1-2][0-9]|3[0-2])\\b';

// 公网cidr 正则
export const INTERNET_CIDR_REGEX = '\\b((?!(10|127)\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|172\\.(1[6-9]|2[0-9]|3[0-1])\\.\\d{1,3}\\.\\d{1,3}|192\\.168\\.\\d{1,3}\\.\\d{1,3}|0\\.0\\.0\\.0|255\\.255\\.255\\.255))(\\d{1,3}\\.){3}\\d{1,3}\\/([0-9]|[1-2][0-9]|3[0-2])\\b';

// 集群环境
export const CLUSTER_ENV = {
stag: 'UAT',
Expand Down
23 changes: 23 additions & 0 deletions bcs-ui/frontend/src/i18n/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ bcs:
cloud: Cloud credential import
platform: Platform created
machine: Machine
autopilot: AutoPilot
standard: Standard
msg:
emptyHostResource: >-
You do not have any host resources under the current business. Please
Expand Down Expand Up @@ -500,6 +502,9 @@ generic:
clusterName: >-
The cluster name can only contain numbers, letters, mid-line lines (-),
down line (_), The beginning must be numbers or letters
gkeLable: >-
Can only contain lowercase letters ([a-z]), numeric characters ([0-9]),
underscores (_), and dashes (-), and must start with a letter
title:
curVersion: Current
diffVersion: Comparison version
Expand Down Expand Up @@ -956,6 +961,24 @@ cluster:
create a new Safety group, please go to the appropriate page in the
{0}.'
vpcMaster: VPC console
google:
labels:
areaType: Area Type
region: region
zone: zone
tips:
containerNet: >-
All pods in the cluster will be assigned an IP address from this range.
Please enter a range and mask in CIDR notation within the network range.
Once this setting is confirmed, it cannot be changed, so please evaluate
carefully before filling it in.
autopilot: >-
GKE manages the underlying infrastructure, such as node configuration,
auto-scaling, automatic upgrades, baseline security configurations,
and baseline network configurations.
standard: >-
You are responsible for managing the underlying infrastructure,
including configuring the individual nodes.
detail:
title:
overview: Overview
Expand Down
12 changes: 12 additions & 0 deletions bcs-ui/frontend/src/i18n/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bcs:
cloud: 云凭证导入
platform: 平台创建
machine: 控制面服务器导入
autopilot: 托管集群
standard: 标准集群
msg:
emptyHostResource: 您在当前业务下没有主机资源,请联系业务运维
notDevOps: 您不是当前项目绑定业务的运维人员,请联系业务运维人员
Expand Down Expand Up @@ -462,6 +464,7 @@ generic:
fieldRequired: '{0} 必填'
fieldRepeat: '{0} 重复'
clusterName: 集群名称只能包含数字、字母、中划线(-)、下划线(_),且开头必须是数字或字母
gkeLable: '只能包含小写字母([a-z])、数字字符([0-9])、下划线(_)和破折号(-),并且必须以字母开头'
title:
createPublicCluster: 新建公有云集群
diffVersion: 线上版本
Expand Down Expand Up @@ -807,6 +810,15 @@ cluster:
text: 安全组
vpcLink: '选择将应用到在您的控制平面子网中创建的 AKS 托管弹性网络接口的安全组。 要创建新的安全组,请转到 {0} 中的相应页面。'
vpcMaster: VPC 控制台
google:
labels:
areaType: 位置类型
region: 区域
zone: 可用区
tips:
containerNet: 集群中所有 pod 都会分配一个此范围的IP地址。请以 CIDR 表示法输入网络范围内一个范围、掩码,此设置一经确定便无法更改,请谨慎评估后填写
autopilot: GKE管理底层基础架构,例如节点配置、自动扩缩、自动升级、基准安全配置和基准网络配置。
standard: 您负责管理底层基础架构,包括配置各个节点。
detail:
title:
overview: 集群总览
Expand Down
14 changes: 13 additions & 1 deletion bcs-ui/frontend/src/router/cluster-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const CreateVCluster = () => import(/* webpackChunkName: 'cluster' */'@/views/cl
const CreateK8SCluster = () => import(/* webpackChunkName: 'cluster' */'@/views/cluster-manage/add/create/k8s.vue');
// 创建aws云集群
const CreateAWSCloudCluster = () => import(/* webpackChunkName: 'cluster' */'@/views/cluster-manage/add/create/aws-cloud/index.vue');
// 创建aws云集群
// 创建微软云集群
const CreateAzureCloudCluster = () => import(/* webpackChunkName: 'cluster' */'@/views/cluster-manage/add/create/azure-cloud/index.vue');
// 创建谷歌云集群
const CreateGoogleCloudCluster = () => import(/* webpackChunkName: 'cluster' */'@/views/cluster-manage/add/create/google-cloud/index.vue');

// import模式
const ImportCluster = () => import(/* webpackChunkName: 'cluster' */'@/views/cluster-manage/add/import/import-cluster.vue');
Expand Down Expand Up @@ -177,6 +179,16 @@ export default [
hideMenu: true,
},
},
// 创建谷歌云集群
{
path: 'clusters/cloud/google',
name: 'CreateGoogleCloudCluster',
component: CreateGoogleCloudCluster,
meta: {
menuId: 'CLUSTER',
hideMenu: true,
},
},
// 创建k8s原生集群
{
path: 'clusters/k8s',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
filter: {
type: Function,
default: null,
},
});
const emits = defineEmits(['input', 'change']);
// 区域列表
Expand All @@ -56,6 +60,9 @@ const handleGetRegionList = async () => {
}).catch(() => []);
$store.commit('cloudMetadata/updateRegionList', data);
regionList.value = data.filter(item => item.regionState === 'AVAILABLE');
if (props.filter) {
regionList.value = props.filter(regionList.value, handleGetRegionList);
}
regionLoading.value = false;
};
Expand Down
95 changes: 95 additions & 0 deletions bcs-ui/frontend/src/views/cluster-manage/add/components/subnet.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<template>
<bk-select
searchable
:clearable="false"
:loading="subnetLoading"
:value="value"
@change="handleSubnetChange">
<bk-option
v-for="net in subnets"
:key="net.subnetID"
:id="net.subnetID"
:name="`${net.subnetName}(${net.subnetID})`"
:disabled="!net.availableIPAddressCount || !!Object.keys(net.cluster || {}).length">
<div
class="flex items-center justify-between"
v-bk-tooltips="{
content: Object.keys(net.cluster || {}).length
? $t('tke.tips.subnetInUsed', [net.cluster ? net.cluster.clusterName : ''])
: $t('tke.tips.noAvailableIp'),
disabled: net.availableIPAddressCount && !Object.keys(net.cluster || {}).length,
placement: 'left'
}">
<span>{{ `${net.subnetName}(${net.subnetID})` }}</span>
<span
:class="(!net.availableIPAddressCount || Object.keys(net.cluster || {}).length) ? '':'text-[#979BA5]'">
{{ `${$t('tke.label.availableIpNum')}: ${net.availableIPAddressCount}` }}
</span>
</div>
</bk-option>
</bk-select>
</template>
<script setup lang="ts">
import { onBeforeMount, ref, watch } from 'vue';
import { ISubnet } from '../../types/types';
import { cloudSubnets } from '@/api/modules/cluster-manager';
const props = defineProps({
value: {
type: String,
},
region: {
type: String,
default: '',
},
cloudAccountID: {
type: String,
default: '',
},
cloudID: {
type: String,
default: '',
},
vpcId: {
type: String,
default: '',
},
});
const emits = defineEmits(['input', 'change']);
// 子网
const subnets = ref<Array<ISubnet>>([]);
const subnetLoading = ref(false);
const handleGetSubnets = async () => {
if (!props.cloudAccountID || !props.region || !props.vpcId) return;
subnetLoading.value = true;
subnets.value = await cloudSubnets({
$cloudId: props.cloudID,
region: props.region,
accountID: props.cloudAccountID,
vpcID: props.vpcId,
injectCluster: true,
}).catch(() => []);
subnetLoading.value = false;
};
const handleSubnetChange = (subnetID: string) => {
emits('change', subnetID);
emits('input', subnetID);
};
watch([
() => props.region,
() => props.cloudAccountID,
() => props.vpcId,
], () => {
handleGetSubnets();
});
onBeforeMount(() => {
handleGetSubnets();
});
</script>
11 changes: 10 additions & 1 deletion bcs-ui/frontend/src/views/cluster-manage/add/components/vpc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<bk-option
v-for="item in vpcList"
:key="item.vpcId"
:id="item.vpcId"
:id="item[valueKey]"
:name="`${item.name}(${item.vpcId})`">
<div class="flex items-center place-content-between">
<span>
Expand All @@ -20,6 +20,7 @@
</div>
</bk-option>
<SelectExtension
v-if="showLink"
slot="extension"
:link-text="$t('tke.link.vpc')"
link="https://console.cloud.tencent.com/vpc/vpc"
Expand Down Expand Up @@ -62,6 +63,14 @@ const props = defineProps({
type: String,
default: '',
},
showLink: {
type: Boolean,
default: true,
},
valueKey: {
type: String,
default: 'vpcId',
},
});
const emits = defineEmits(['input', 'change']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
searchable
:clearable="false"
:value="value"
:loading="zoneLoading"
@change="handleZoneChange">
<bcs-option
v-for="zone in zoneList"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
<NetworkSelector
:ref="el => networkSelectorRef = el"
class="max-w-[600px]"
:value="masterConfig.clusterAdvanceSettings.clusterConnectSetting"
:value="connectConfig"
:region="region"
:cloud-account-i-d="cloudAccountID"
:cloud-i-d="cloudID"
:value-list="[
{ label: $t('tke.label.apiServerCLB.internet'), value: 'internet' },
{ label: $t('tke.label.apiServerCLB.intranet'), value: 'intranet' },
]"
@change="(v) => masterConfig.clusterAdvanceSettings.clusterConnectSetting = v" />
@change="handleChange" />
</bk-form-item>
<div class="flex items-center h-[48px] bg-[#FAFBFD] px-[24px] fixed bottom-0 left-0 w-full bcs-border-top">
<bk-button @click="preStep">{{ $t('generic.button.pre') }}</bk-button>
Expand Down Expand Up @@ -86,10 +86,8 @@ const masterConfig = ref({
autoGenerateMasterNodes: true,
clusterAdvanceSettings: {
clusterConnectSetting: {
ITNType: 'intranet',
isExtranet: false,
subnetId: '',
cidrs: [],
internet: {
publicIPAssigned: false,
publicAccessCidrs: [],
Expand All @@ -98,6 +96,16 @@ const masterConfig = ref({
},
});
const connectConfig = ref({
ITNType: 'intranet',
isExtranet: false,
cidrs: [],
internet: {
publicIPAssigned: false,
publicAccessCidrs: [],
},
});
const networkSelectorRef = ref<InstanceType<typeof NetworkSelector> | null>(null);
// 动态 i18n 问题,这里使用computed
const masterConfigRules = computed(() => ({
Expand All @@ -106,7 +114,7 @@ const masterConfigRules = computed(() => ({
trigger: 'blur',
message: $i18n.t('generic.validate.required'),
async validator() {
if (masterConfig.value.clusterAdvanceSettings.clusterConnectSetting.ITNType === 'internet') {
if (connectConfig.value.ITNType === 'internet') {
return await networkSelectorRef.value?.validate();
}
return true;
Expand All @@ -115,6 +123,16 @@ const masterConfigRules = computed(() => ({
],
}));
// 整理参数
function handleChange(data) {
connectConfig.value = data;
masterConfig.value.clusterAdvanceSettings.clusterConnectSetting.isExtranet = data?.isExtranet;
// eslint-disable-next-line max-len
masterConfig.value.clusterAdvanceSettings.clusterConnectSetting.internet.publicAccessCidrs = data?.internet?.publicAccessCidrs;
// eslint-disable-next-line max-len
if (!data?.isExtranet) masterConfig.value.clusterAdvanceSettings.clusterConnectSetting.internet.publicAccessCidrs = [];
};
// master配置
const handleChangeManageType = (type: 'INDEPENDENT_CLUSTER' | 'MANAGED_CLUSTER') => {
masterConfig.value.manageType = type;
Expand Down
Loading

0 comments on commit a17aaef

Please sign in to comment.