Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,13 @@
"Please input search text": "Please input search text",
"Unknown": "Unknown",
"{name} {action} successfully.": "{name} {action} successfully.",
"LocalRegistry": "LocalRegistry",
"Please input localRegistry": "Please input localRegistry",
"Image Repository": "Image Repository",
"Image Registry": "Image Registry",
"Select a configured Registry resource. Its address and access settings will be used to pull offline installation images, and components inherit this Registry by default.": "Select a configured Registry resource. Its address and access settings will be used to pull offline installation images, and components inherit this Registry by default.",
"Optionally select a configured Registry resource for image pulls. If none is selected, images are pulled from the official registries.": "Optionally select a configured Registry resource for image pulls. If none is selected, images are pulled from the official registries.",
"Select a configured Registry resource for image pulls. If none is selected, online installation uses the official registries.": "Select a configured Registry resource for image pulls. If none is selected, online installation uses the official registries.",
"Please select a Registry resource": "Please select a configured Registry resource",
"Please input image repository": "Please input image repository",
"CertSANs": "CertSANs",
"The registry for image of k8s's own components, if not input, the built-in image will be used.": "The registry for image of k8s's own components, if not input, the built-in image will be used.",
"k8s cluster certSANs ip or dns.": "k8s cluster certSANs ip or dns.",
Expand Down Expand Up @@ -451,7 +456,7 @@
"Target version error": "Target version error",
"TIP_CLUSTER_IMAGE_TYPE_DESC": "Select online and gcr.com will be automatically downloaded from k8s official website k8s. Pull the required image from Io; Select offline to specify a different mirror source.",
"TIP_CLUSTER_UPGRADE_DESC": "Cluster upgrade can span small versions, but it does not support upgrading that omits the next version. For example, you can upgrade from v1.20.2 to v1,20.13, or by v1.20.x to v1.21.x, but not from v1.20.x to v1.22.x",
"TIP_CLUSTER_LOCALREGISTRY": "The address of the warehouse where k8s its own component image is stored. If it is not filled in, the built-in image will be used",
"TIP_CLUSTER_IMAGE_REPOSITORY": "Repository prefix used to pull Kubernetes and cluster component images.",
"The registry for image, such as the insecure registry in the daemon.json of docker.": "The registry for image, such as the insecure registry in the daemon.json of docker.",
"Healthy Status": "Healthy Status",
"Registry Address": "Registry Address",
Expand Down
11 changes: 8 additions & 3 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,13 @@
"Please input search text": "请输入搜索内容",
"Unknown": "未知",
"{name} {action} successfully.": "{name} {action} 成功。",
"LocalRegistry": "镜像仓库",
"Please input localRegistry": "请输入镜像仓库",
"Image Repository": "镜像仓库",
"Image Registry": "镜像仓库(Registry)",
"Select a configured Registry resource. Its address and access settings will be used to pull offline installation images, and components inherit this Registry by default.": "请选择已配置的 Registry 资源。系统将使用该资源的地址及访问配置拉取离线安装镜像,组件默认继承此 Registry。",
"Optionally select a configured Registry resource for image pulls. If none is selected, images are pulled from the official registries.": "可选:选择已配置的 Registry 资源用于拉取镜像;未选择时使用官方镜像仓库。",
"Select a configured Registry resource for image pulls. If none is selected, online installation uses the official registries.": "请选择已配置的 Registry 资源用于拉取镜像;未选择时在线安装使用官方镜像仓库。",
"Please select a Registry resource": "请选择已配置的 Registry 资源",
"Please input image repository": "请输入镜像仓库",
"CertSANs": "",
"The registry for image of k8s's own components, if not input, the built-in image will be used.": "存放 k8s 自身组件镜像的仓库地址 ,不填则使用内置镜像。",
"k8s cluster certSANs ip or dns.": "k8s 集群 ca 证书签名的 ip 或者 dns。",
Expand Down Expand Up @@ -451,7 +456,7 @@
"Target version error": "目标版本错误",
"TIP_CLUSTER_IMAGE_TYPE_DESC": "选择“在线”,将自动从 k8s 官网 gcr.k8s.io 中拉取所需镜像;选择“离线”,可指定其他镜像来源。",
"TIP_CLUSTER_UPGRADE_DESC": "集群升级可以跨小版本,但不支持略过次版本的升级,如您可以从 v1.20.2 升级到 v1.20.13,或由 v1.20.x 升级到 v1.21.x,但不支持从 v1.20.x 升级到 v1.22.x",
"TIP_CLUSTER_LOCALREGISTRY": "存放 k8s 自身组件镜像的仓库地址,不填则使用内置镜像",
"TIP_CLUSTER_IMAGE_REPOSITORY": "用于拉取 Kubernetes 和集群组件镜像的仓库前缀。",
"The registry for image, such as the insecure registry in the daemon.json of docker.": "存放镜像仓库的地址,如:docker 的 daemon.json 文件中的 insecure registry。",
"Healthy Status": "健康状态",
"Registry Address": "仓库地址",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ function BaseDetail() {
dataIndex: 'kubernetesVersion',
},
{
label: t('LocalRegistry'),
label: t('Image Registry'),
dataIndex: 'offline',
render: (_, data) => {
const { offline, localRegistry = '' } = data;
return `${offline ? t('Offline') : t('Online')} ${localRegistry}`;
const { offline, imageRegistry = 'registry.k8s.io' } = data;
return `${offline ? t('Offline') : t('Online')} ${imageRegistry}`;
},
},
{
Expand Down
172 changes: 27 additions & 145 deletions src/pages/cluster/containers/Cluster/actions/Create/Cluster.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
* limitations under the License.
*/
import { observer } from 'mobx-react';
import BaseForm from 'components/Form';
import { toJS } from 'mobx';
import BaseForm from 'components/Form';
import { rootStore } from 'stores';
import { fqdn, path } from 'utils/regex';
import {
isIPv4,
isIpv6,
isDomain,
isDomainPath,
isIpPort,
isDomainPort,
isIp,
} from 'utils/validate';
Expand Down Expand Up @@ -60,8 +58,10 @@ export default class Cluster extends BaseForm {
this.registryStore = registryStore;
this.backupPointStore = backupPointStore;

await this.getCommonRegistry();
await this.getBackupPoint();
await Promise.all([
this.getBackupPoint(),
this.registryStore.fetchList({ limit: -1 }),
]);
await this.initVersions();
}

Expand Down Expand Up @@ -92,10 +92,6 @@ export default class Cluster extends BaseForm {
};
}

async getCommonRegistry() {
await this.registryStore.fetchList();
}

async getBackupPoint() {
await this.backupPointStore.fetchList();
}
Expand Down Expand Up @@ -133,9 +129,11 @@ export default class Cluster extends BaseForm {
const versions = isOffLine ? this.offlineVersions : this.onlineVersions;
const [firstVersion] = versions;
const currentVersions = this.getCurrentVersionsByK8s(firstVersion);
const imageRegistry = '';

await this.updateContext({
offline: isOffLine,
imageRegistry,
kubernetesVersions: versions,
kubernetesVersion: firstVersion?.value,
...currentVersions,
Expand All @@ -144,6 +142,7 @@ export default class Cluster extends BaseForm {
kubernetesVersion: firstVersion?.value,
...currentVersions,
});
this.updateFormValue('imageRegistry', imageRegistry);
};

updateFormVersions(versions) {
Expand Down Expand Up @@ -190,6 +189,13 @@ export default class Cluster extends BaseForm {
return options;
}

get registryOptions() {
return toJS(this.registryStore.list.data || []).map(({ name, host, scheme }) => ({
value: name,
label: `${name} (${scheme}://${host})`,
}));
}

get onlineVersions() {
const data = this.store.onlineVersion;
return data.map(({ version, version_control, archs }) => ({
Expand Down Expand Up @@ -218,14 +224,6 @@ export default class Cluster extends BaseForm {
}));
}

get getRegistryOptions() {
const data = toJS(this.registryStore.list.data);
return (data || []).map(({ host }) => ({
value: host,
label: host,
}));
}

// eslint-disable-next-line no-unused-vars
checkVip = (rule, value) =>
// const existNodeList = nodeStore.list.data.some((v) => v.ip === value);
Expand Down Expand Up @@ -339,53 +337,10 @@ export default class Cluster extends BaseForm {
return Promise.reject(t('The selected node and schema are inconsistent'));
};

checkk8sRegistry = (rule, value) => {
if (!value) return Promise.resolve(true);

const checkFunc = (item) => {
if (!item) return true;
if (
isDomain(item) ||
isDomainPath(item) ||
isIPv4(item) ||
isIpPort(item)
) {
return true;
}
return false;
};

if (!checkFunc(value)) {
return Promise.reject(t('Please enter a legal registry'));
}

return Promise.resolve(true);
};

checkRegistry = (rule, value) => {
if (!value) return Promise.resolve(true);

const checkFunc = (item) => {
if (!item) return true;
if (
isDomain(item) ||
isDomainPath(item) ||
isIPv4(item) ||
isIpPort(item)
) {
return true;
}
return false;
};

const isInValide = value.some((it) => !checkFunc(it.value));

if (isInValide) {
return Promise.reject(t('Please enter a legal registry'));
}

return Promise.resolve(true);
};
checkImageRegistry = (rule, value) =>
!value && this.isOffLine
? Promise.reject(t('Please select a Registry resource'))
: Promise.resolve(true);

checkLabels = (rule, value = []) => {
const checkFunc = (item) => {
Expand All @@ -405,56 +360,12 @@ export default class Cluster extends BaseForm {
return Promise.resolve(true);
};

updateInsecureRegistry = (value, type) => {
const checkFunc = (item) => {
if (!item) return false;
if (
isDomain(item) ||
isIPv4(item) ||
isIpPort(item) ||
isDomainPath(item)
) {
return true;
}
return false;
};

const getInsecureRegistry = (isDocker) =>
isDocker ? 'dockerInsecureRegistry' : 'containerdInsecureRegistry';

let updateFormKey = getInsecureRegistry(this.isDocker);
if (type) {
updateFormKey = getInsecureRegistry(type === 'docker');
}

if (checkFunc(value)) {
this.updateFormValue(updateFormKey, [
{ index: 0, value, disabled: true },
]);
}
};

onK8SRegistryChange = (e) => {
this.updateInsecureRegistry(e);
};

get localRegistryValue() {
return this.getFormInstance().getFieldValue('localRegistry');
}

onRunTimeTypeChange = (type) => {
if (this.isOffLine) {
this.updateInsecureRegistry(this.localRegistryValue, type);
}
};

onK8SVersionChange = async (value) => {
const isAfter20 = versionCompare('v1.20.0', value) <= 0;
const isAfter24 = versionCompare('v1.24.0', value) <= 0;

const containerRuntimeType = isAfter20 ? 'containerd' : 'docker';
this.updateFormValue('containerRuntimeType', containerRuntimeType);
this.updateInsecureRegistry(this.localRegistryValue, containerRuntimeType);
this.setState({
containerRuntimeType,
});
Expand Down Expand Up @@ -526,20 +437,18 @@ export default class Cluster extends BaseForm {
onChange: this.handleImgType,
},
{
name: 'localRegistry',
label: t('LocalRegistry'),
type: 'select-input',
placeholder: t('Please input localRegistry'),
options: this.getRegistryOptions,
maxLength: 256,
validator: this.checkk8sRegistry,
onChange: this.onK8SRegistryChange,
name: 'imageRegistry',
label: t('Image Registry'),
type: 'select',
options: this.registryOptions,
validator: this.checkImageRegistry,
required: this.isOffLine,
extra: this.isOffLine
? t(
'The images are pulled from the local server by default. You can also fill in another private registry. The components will inherit the registry by default. Please ensure that the required images are stored in the registry. You can also set an independent registry for a specific component, and the component image will be pulled from this address.'
'Select a configured Registry resource. Its address and access settings will be used to pull offline installation images, and components inherit this Registry by default.'
)
: t(
'The images are pulled from the official registry by default, for example, k8s images are pulled from k8s.gcr.io and calico images are pulled from docker.io. You can also fill in another private registry. The components will inherit the registry by default. Please ensure that the required images are stored in the registry. You can also set an independent registry for a specific component, and the component image will be pulled from this address.'
'Optionally select a configured Registry resource for image pulls. If none is selected, images are pulled from the official registries.'
),
},
{
Expand Down Expand Up @@ -618,7 +527,6 @@ export default class Cluster extends BaseForm {
type: 'select',
required: true,
options: runtimeOption,
onChange: this.onRunTimeTypeChange,
tip: t(
'K8S version before the v1.20.0, container runtime default docker, and then default containerd, after v1.24.0 not support docker.'
),
Expand Down Expand Up @@ -649,19 +557,6 @@ export default class Cluster extends BaseForm {
hidden: !this.isDocker,
tip: t('The root dir in daemon.json.'),
},
{
name: 'dockerInsecureRegistry',
label: t('Docker Registry'),
type: 'array-input',
isInput: true,
width: '100%',
hidden: !this.isDocker,
placeholder: t('Please input registry'),
tip: t(
'The registry for image, such as the insecure registry in the daemon.json of docker.'
),
validator: this.checkRegistry,
},
// containerd
{
name: 'containerdVersion',
Expand All @@ -680,19 +575,6 @@ export default class Cluster extends BaseForm {
hidden: this.isDocker,
tip: t('Root dir in config.toml'),
},
{
name: 'containerdInsecureRegistry',
label: t('Containerd Registry'),
type: 'array-input',
isInput: true,
width: '100%',
hidden: this.isDocker,
validator: this.checkRegistry,
placeholder: t('Please input registry'),
tip: t(
'The registry containerd image, registry.mirrors in the config.toml.'
),
},
],
// 网络
[
Expand Down
Loading
Loading