feat: 容器创建增加 CPU 权重设置 (#1377)

This commit is contained in:
ssongliu 2023-06-14 23:26:13 +08:00 committed by GitHub
parent 20dbd6c181
commit b7cda1d2f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 1 deletions

View File

@ -36,6 +36,7 @@ type ContainerCreate struct {
PublishAllPorts bool `json:"publishAllPorts"`
ExposedPorts []PortHelper `json:"exposedPorts"`
Cmd []string `json:"cmd"`
CPUShares int64 `josn:"cpuShares"`
NanoCPUs int64 `json:"nanoCPUs"`
Memory int64 `json:"memory"`
AutoRemove bool `json:"autoRemove"`

View File

@ -247,6 +247,9 @@ func (u *ContainerService) ContainerCreate(req dto.ContainerCreate) error {
if req.NanoCPUs != 0 {
hostConf.NanoCPUs = req.NanoCPUs * 1000000000
}
if req.CPUShares != 0 {
hostConf.CPUShares = req.CPUShares
}
if req.Memory != 0 {
hostConf.Memory = req.Memory
}

View File

@ -483,6 +483,9 @@ const message = {
cleanLog: 'Clean log',
newName: 'New name',
source: 'Resource rate',
cpuShare: 'CPU Share',
cpuShareHelper:
'The default CPU share for a container is 1024, which can be increased to give the container more CPU time.',
user: 'User',
command: 'Command',

View File

@ -490,6 +490,8 @@ const message = {
cleanLog: '清空日志',
newName: '新名称',
source: '资源使用率',
cpuShare: 'CPU 权重',
cpuShareHelper: '容器默认份额为 1024 CPU增大可使当前容器获得更多的 CPU 时间',
user: '用户',
command: '命令',

View File

@ -81,6 +81,10 @@
<el-form-item prop="autoRemove">
<el-checkbox v-model="form.autoRemove">{{ $t('container.autoRemove') }}</el-checkbox>
</el-form-item>
<el-form-item :label="$t('container.cpuShare')" prop="cpuShares">
<el-input style="width: 40%" v-model.number="form.cpuShares" />
<span class="input-help">{{ $t('container.cpuShareHelper') }}</span>
</el-form-item>
<el-form-item :label="$t('container.cpuQuota')" prop="nanoCPUs">
<el-input type="number" style="width: 40%" v-model.number="form.nanoCPUs">
<template #append>
@ -202,7 +206,7 @@
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { Rules } from '@/global/form-rules';
import { Rules, checkNumberRange } from '@/global/form-rules';
import i18n from '@/lang';
import { ElForm } from 'element-plus';
import DrawerHeader from '@/components/drawer-header/index.vue';
@ -221,6 +225,7 @@ const form = reactive({
cmd: [] as Array<string>,
publishAllPorts: false,
exposedPorts: [] as Array<Container.Port>,
cpuShares: 1024,
nanoCPUs: 0,
memory: 0,
memoryItem: 0,
@ -251,6 +256,7 @@ const handlReset = () => {
form.cmd = [];
form.publishAllPorts = false;
form.exposedPorts = [];
form.cpuShares = 1024;
form.nanoCPUs = 0;
form.memory = 0;
form.memoryItem = 0;
@ -272,6 +278,7 @@ const handleClose = () => {
const emit = defineEmits<{ (e: 'search'): void }>();
const rules = reactive({
cpuShares: [Rules.number, checkNumberRange(2, 262144)],
name: [Rules.requiredInput, Rules.name],
image: [Rules.requiredSelect],
nanoCPUs: [Rules.number],