mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-02 12:17:43 +08:00
[Improvement][K8S] Remove ResourceQuota (#14991)
* [Improvement][K8S] Remove ResourceQuota Signed-off-by: Gallardot <gallardot@apache.org> * chore: fix pg Signed-off-by: Gallardot <gallardot@apache.org> * chore: Clean up unused code Signed-off-by: Gallardot <gallardot@apache.org> * chore: naming conventions Signed-off-by: Gallardot <gallardot@apache.org> --------- Signed-off-by: Gallardot <gallardot@apache.org> Co-authored-by: xiangzihao <460888207@qq.com>
This commit is contained in:
parent
8665951981
commit
8c01fcf14b
@ -23,7 +23,6 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_NAME
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_CAN_USE_K8S_NAMESPACE_ERROR;
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_K8S_NAMESPACE_LIST_PAGING_ERROR;
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_UNAUTHORIZED_NAMESPACE_ERROR;
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_K8S_NAMESPACE_ERROR;
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_K8S_NAMESPACE_ERROR;
|
||||
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
@ -40,9 +39,7 @@ import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@ -104,56 +101,21 @@ public class K8sNamespaceController extends BaseController {
|
||||
* @param loginUser
|
||||
* @param namespace k8s namespace
|
||||
* @param clusterCode clusterCode
|
||||
* @param limitsCpu max cpu
|
||||
* @param limitsMemory max memory
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "createK8sNamespace", description = "CREATE_NAMESPACE_NOTES")
|
||||
@Parameters({
|
||||
@Parameter(name = "namespace", description = "NAMESPACE", required = true, schema = @Schema(implementation = String.class)),
|
||||
@Parameter(name = "clusterCode", description = "CLUSTER_CODE", required = true, schema = @Schema(implementation = long.class)),
|
||||
@Parameter(name = "limits_cpu", description = "LIMITS_CPU", required = false, schema = @Schema(implementation = double.class)),
|
||||
@Parameter(name = "limits_memory", description = "LIMITS_MEMORY", required = false, schema = @Schema(implementation = int.class))
|
||||
@Parameter(name = "clusterCode", description = "CLUSTER_CODE", required = true, schema = @Schema(implementation = long.class))
|
||||
})
|
||||
@PostMapping()
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(CREATE_K8S_NAMESPACE_ERROR)
|
||||
public Result createNamespace(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@RequestParam(value = "namespace") String namespace,
|
||||
@RequestParam(value = "clusterCode") Long clusterCode,
|
||||
@RequestParam(value = "limitsCpu", required = false) Double limitsCpu,
|
||||
@RequestParam(value = "limitsMemory", required = false) Integer limitsMemory) {
|
||||
@RequestParam(value = "clusterCode") Long clusterCode) {
|
||||
Map<String, Object> result =
|
||||
k8sNamespaceService.createK8sNamespace(loginUser, namespace, clusterCode, limitsCpu, limitsMemory);
|
||||
return returnDataList(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* update namespace,namespace and k8s not allowed update, because may create on k8s,can delete and create new instead
|
||||
*
|
||||
* @param loginUser
|
||||
* @param userName owner
|
||||
* @param limitsCpu max cpu
|
||||
* @param limitsMemory max memory
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "updateK8sNamespace", description = "UPDATE_NAMESPACE_NOTES")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "K8S_NAMESPACE_ID", required = true, schema = @Schema(implementation = int.class, example = "100")),
|
||||
@Parameter(name = "userName", description = "OWNER", required = false, schema = @Schema(implementation = String.class)),
|
||||
@Parameter(name = "limitsCpu", description = "LIMITS_CPU", required = false, schema = @Schema(implementation = double.class)),
|
||||
@Parameter(name = "limitsMemory", description = "LIMITS_MEMORY", required = false, schema = @Schema(implementation = int.class))})
|
||||
@PutMapping(value = "/{id}")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ApiException(UPDATE_K8S_NAMESPACE_ERROR)
|
||||
public Result updateNamespace(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@PathVariable(value = "id") int id,
|
||||
@RequestParam(value = "userName", required = false) String userName,
|
||||
@RequestParam(value = "tag", required = false) String tag,
|
||||
@RequestParam(value = "limitsCpu", required = false) Double limitsCpu,
|
||||
@RequestParam(value = "limitsMemory", required = false) Integer limitsMemory) {
|
||||
Map<String, Object> result =
|
||||
k8sNamespaceService.updateK8sNamespace(loginUser, id, userName, limitsCpu, limitsMemory);
|
||||
k8sNamespaceService.createK8sNamespace(loginUser, namespace, clusterCode);
|
||||
return returnDataList(result);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ import org.yaml.snakeyaml.Yaml;
|
||||
import io.fabric8.kubernetes.api.model.Namespace;
|
||||
import io.fabric8.kubernetes.api.model.NamespaceList;
|
||||
import io.fabric8.kubernetes.api.model.ObjectMeta;
|
||||
import io.fabric8.kubernetes.api.model.ResourceQuota;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
/**
|
||||
@ -41,14 +40,12 @@ public class K8sClientService {
|
||||
@Autowired
|
||||
private K8sManager k8sManager;
|
||||
|
||||
public ResourceQuota upsertNamespaceAndResourceToK8s(K8sNamespace k8sNamespace,
|
||||
String yamlStr) {
|
||||
public void upsertNamespaceAndResourceToK8s(K8sNamespace k8sNamespace) {
|
||||
if (!checkNamespaceToK8s(k8sNamespace.getNamespace(), k8sNamespace.getClusterCode())) {
|
||||
throw new RuntimeException(String.format(
|
||||
"namespace %s does not exist in k8s cluster, please create namespace in k8s cluster first",
|
||||
k8sNamespace.getNamespace()));
|
||||
}
|
||||
return upsertNamespacedResourceToK8s(k8sNamespace, yamlStr);
|
||||
}
|
||||
|
||||
public Optional<Namespace> deleteNamespaceToK8s(String name, Long clusterCode) {
|
||||
@ -65,33 +62,6 @@ public class K8sClientService {
|
||||
return getNamespaceFromK8s(name, clusterCode);
|
||||
}
|
||||
|
||||
private ResourceQuota upsertNamespacedResourceToK8s(K8sNamespace k8sNamespace,
|
||||
String yamlStr) {
|
||||
|
||||
KubernetesClient client = k8sManager.getK8sClient(k8sNamespace.getClusterCode());
|
||||
|
||||
// 创建资源
|
||||
ResourceQuota queryExist = client.resourceQuotas()
|
||||
.inNamespace(k8sNamespace.getNamespace())
|
||||
.withName(k8sNamespace.getNamespace())
|
||||
.get();
|
||||
|
||||
ResourceQuota body = yaml.loadAs(yamlStr, ResourceQuota.class);
|
||||
|
||||
if (queryExist != null) {
|
||||
if (k8sNamespace.getLimitsCpu() == null && k8sNamespace.getLimitsMemory() == null) {
|
||||
client.resourceQuotas().inNamespace(k8sNamespace.getNamespace())
|
||||
.withName(k8sNamespace.getNamespace())
|
||||
.delete();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return client.resourceQuotas().inNamespace(k8sNamespace.getNamespace())
|
||||
.withName(k8sNamespace.getNamespace())
|
||||
.createOrReplace(body);
|
||||
}
|
||||
|
||||
private Optional<Namespace> getNamespaceFromK8s(String name, Long clusterCode) {
|
||||
NamespaceList listNamespace =
|
||||
k8sManager.getK8sClient(clusterCode).namespaces().list();
|
||||
|
@ -46,24 +46,9 @@ public interface K8sNamespaceService {
|
||||
* @param loginUser login user
|
||||
* @param namespace namespace
|
||||
* @param clusterCode k8s not null
|
||||
* @param limitsCpu limits cpu, can null means not limit
|
||||
* @param limitsMemory limits memory, can null means not limit
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> createK8sNamespace(User loginUser, String namespace, Long clusterCode, Double limitsCpu,
|
||||
Integer limitsMemory);
|
||||
|
||||
/**
|
||||
* update K8s Namespace tag and resource limit
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param userName owner
|
||||
* @param limitsCpu max cpu
|
||||
* @param limitsMemory max memory
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> updateK8sNamespace(User loginUser, int id, String userName, Double limitsCpu,
|
||||
Integer limitsMemory);
|
||||
Map<String, Object> createK8sNamespace(User loginUser, String namespace, Long clusterCode);
|
||||
|
||||
/**
|
||||
* verify namespace and k8s
|
||||
|
@ -57,16 +57,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@Slf4j
|
||||
public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNamespaceService {
|
||||
|
||||
private static String resourceYaml = "apiVersion: v1\n"
|
||||
+ "kind: ResourceQuota\n"
|
||||
+ "metadata:\n"
|
||||
+ " name: ${name}\n"
|
||||
+ " namespace: ${namespace}\n"
|
||||
+ "spec:\n"
|
||||
+ " hard:\n"
|
||||
+ " ${limitCpu}\n"
|
||||
+ " ${limitMemory}\n";
|
||||
|
||||
@Autowired
|
||||
private K8sNamespaceMapper k8sNamespaceMapper;
|
||||
|
||||
@ -114,13 +104,10 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
||||
* @param loginUser login user
|
||||
* @param namespace namespace
|
||||
* @param clusterCode k8s not null
|
||||
* @param limitsCpu limits cpu, can null means not limit
|
||||
* @param limitsMemory limits memory, can null means not limit
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> createK8sNamespace(User loginUser, String namespace, Long clusterCode, Double limitsCpu,
|
||||
Integer limitsMemory) {
|
||||
public Map<String, Object> createK8sNamespace(User loginUser, String namespace, Long clusterCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (isNotAdmin(loginUser, result)) {
|
||||
log.warn("Only admin can create K8s namespace, current login user name:{}.", loginUser.getUserName());
|
||||
@ -139,18 +126,6 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
||||
return result;
|
||||
}
|
||||
|
||||
if (limitsCpu != null && limitsCpu < 0.0) {
|
||||
log.warn("Parameter limitsCpu is invalid.");
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.LIMITS_CPU);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (limitsMemory != null && limitsMemory < 0) {
|
||||
log.warn("Parameter limitsMemory is invalid.");
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.LIMITS_MEMORY);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (checkNamespaceExistInDb(namespace, clusterCode)) {
|
||||
log.warn("K8S namespace already exists.");
|
||||
putMsg(result, Status.K8S_NAMESPACE_EXIST, namespace, clusterCode);
|
||||
@ -183,18 +158,12 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
||||
k8sNamespaceObj.setNamespace(namespace);
|
||||
k8sNamespaceObj.setClusterCode(clusterCode);
|
||||
k8sNamespaceObj.setUserId(loginUser.getId());
|
||||
k8sNamespaceObj.setLimitsCpu(limitsCpu);
|
||||
k8sNamespaceObj.setLimitsMemory(limitsMemory);
|
||||
k8sNamespaceObj.setPodReplicas(0);
|
||||
k8sNamespaceObj.setPodRequestCpu(0.0);
|
||||
k8sNamespaceObj.setPodRequestMemory(0);
|
||||
k8sNamespaceObj.setCreateTime(now);
|
||||
k8sNamespaceObj.setUpdateTime(now);
|
||||
|
||||
if (!Constants.K8S_LOCAL_TEST_CLUSTER_CODE.equals(k8sNamespaceObj.getClusterCode())) {
|
||||
try {
|
||||
String yamlStr = genDefaultResourceYaml(k8sNamespaceObj);
|
||||
k8sClientService.upsertNamespaceAndResourceToK8s(k8sNamespaceObj, yamlStr);
|
||||
k8sClientService.upsertNamespaceAndResourceToK8s(k8sNamespaceObj);
|
||||
} catch (Exception e) {
|
||||
log.error("Namespace create to k8s error", e);
|
||||
putMsg(result, Status.K8S_CLIENT_OPS_ERROR, e.getMessage());
|
||||
@ -209,65 +178,6 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* update K8s Namespace tag and resource limit
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param userName owner
|
||||
* @param limitsCpu max cpu
|
||||
* @param limitsMemory max memory
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> updateK8sNamespace(User loginUser, int id, String userName, Double limitsCpu,
|
||||
Integer limitsMemory) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (isNotAdmin(loginUser, result)) {
|
||||
log.warn("Only admin can update K8s namespace, current login user name:{}.", loginUser.getUserName());
|
||||
return result;
|
||||
}
|
||||
|
||||
if (limitsCpu != null && limitsCpu < 0.0) {
|
||||
log.warn("Parameter limitsCpu is invalid.");
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.LIMITS_CPU);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (limitsMemory != null && limitsMemory < 0) {
|
||||
log.warn("Parameter limitsMemory is invalid.");
|
||||
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.LIMITS_MEMORY);
|
||||
return result;
|
||||
}
|
||||
|
||||
K8sNamespace k8sNamespaceObj = k8sNamespaceMapper.selectById(id);
|
||||
if (k8sNamespaceObj == null) {
|
||||
log.error("K8s namespace does not exist, namespaceId:{}.", id);
|
||||
putMsg(result, Status.K8S_NAMESPACE_NOT_EXIST, id);
|
||||
return result;
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
k8sNamespaceObj.setLimitsCpu(limitsCpu);
|
||||
k8sNamespaceObj.setLimitsMemory(limitsMemory);
|
||||
k8sNamespaceObj.setUpdateTime(now);
|
||||
|
||||
if (!Constants.K8S_LOCAL_TEST_CLUSTER_CODE.equals(k8sNamespaceObj.getClusterCode())) {
|
||||
try {
|
||||
String yamlStr = genDefaultResourceYaml(k8sNamespaceObj);
|
||||
k8sClientService.upsertNamespaceAndResourceToK8s(k8sNamespaceObj, yamlStr);
|
||||
} catch (Exception e) {
|
||||
log.error("Namespace update to k8s error", e);
|
||||
putMsg(result, Status.K8S_CLIENT_OPS_ERROR, e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// update to db
|
||||
k8sNamespaceMapper.updateById(k8sNamespaceObj);
|
||||
log.info("K8s namespace update complete, namespace:{}.", k8sNamespaceObj.getNamespace());
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* verify namespace and k8s
|
||||
*
|
||||
@ -338,42 +248,6 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
|
||||
return k8sNamespaceMapper.existNamespace(namespace, clusterCode) == Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* use cpu memory create yaml
|
||||
*
|
||||
* @param k8sNamespace
|
||||
* @return yaml file
|
||||
*/
|
||||
private String genDefaultResourceYaml(K8sNamespace k8sNamespace) {
|
||||
// resource use same name with namespace
|
||||
String name = k8sNamespace.getNamespace();
|
||||
String namespace = k8sNamespace.getNamespace();
|
||||
String cpuStr = null;
|
||||
if (k8sNamespace.getLimitsCpu() != null) {
|
||||
cpuStr = k8sNamespace.getLimitsCpu() + "";
|
||||
}
|
||||
|
||||
String memoryStr = null;
|
||||
if (k8sNamespace.getLimitsMemory() != null) {
|
||||
memoryStr = k8sNamespace.getLimitsMemory() + "Gi";
|
||||
}
|
||||
|
||||
String result = resourceYaml.replace("${name}", name)
|
||||
.replace("${namespace}", namespace);
|
||||
if (cpuStr == null) {
|
||||
result = result.replace("${limitCpu}", "");
|
||||
} else {
|
||||
result = result.replace("${limitCpu}", "limits.cpu: '" + cpuStr + "'");
|
||||
}
|
||||
|
||||
if (memoryStr == null) {
|
||||
result = result.replace("${limitMemory}", "");
|
||||
} else {
|
||||
result = result.replace("${limitMemory}", "limits.memory: " + memoryStr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* query unauthorized namespace
|
||||
*
|
||||
|
@ -19,7 +19,6 @@ package org.apache.dolphinscheduler.api.controller;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ -83,24 +82,6 @@ public class K8sNamespaceControllerTest extends AbstractControllerTest {
|
||||
logger.info("create queue return result:{}", mvcResult.getResponse().getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNamespace() throws Exception {
|
||||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("id", "1");
|
||||
paramsMap.add("owner", "owmer1");
|
||||
paramsMap.add("tag", "flink");
|
||||
|
||||
MvcResult mvcResult = mockMvc.perform(put("/k8s-namespace/{id}", 1)
|
||||
.header(SESSION_ID, sessionId)
|
||||
.params(paramsMap))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andReturn();
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
|
||||
logger.info("update queue return result:{}", mvcResult.getResponse().getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyNamespace() throws Exception {
|
||||
// queue value exist
|
||||
|
@ -81,9 +81,6 @@ public class K8SNamespaceServiceTest {
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
Mockito.when(
|
||||
k8sClientService.upsertNamespaceAndResourceToK8s(Mockito.any(K8sNamespace.class), Mockito.anyString()))
|
||||
.thenReturn(null);
|
||||
Mockito.when(k8sClientService.deleteNamespaceToK8s(Mockito.anyString(), Mockito.anyLong())).thenReturn(null);
|
||||
}
|
||||
|
||||
@ -108,37 +105,16 @@ public class K8SNamespaceServiceTest {
|
||||
public void createK8sNamespace() {
|
||||
// namespace is null
|
||||
Map<String, Object> result =
|
||||
k8sNamespaceService.createK8sNamespace(getLoginUser(), null, clusterCode, 10.0, 100);
|
||||
k8sNamespaceService.createK8sNamespace(getLoginUser(), null, clusterCode);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS));
|
||||
// k8s is null
|
||||
result = k8sNamespaceService.createK8sNamespace(getLoginUser(), namespace, null, 10.0, 100);
|
||||
result = k8sNamespaceService.createK8sNamespace(getLoginUser(), namespace, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS));
|
||||
// correct
|
||||
Mockito.when(clusterMapper.queryByClusterCode(Mockito.anyLong())).thenReturn(getCluster());
|
||||
result = k8sNamespaceService.createK8sNamespace(getLoginUser(), namespace, clusterCode, 10.0, 100);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
// null limit cpu and mem
|
||||
result = k8sNamespaceService.createK8sNamespace(getLoginUser(), namespace, clusterCode, null, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateK8sNamespace() {
|
||||
Mockito.when(k8sNamespaceMapper.selectById(1)).thenReturn(getNamespace());
|
||||
|
||||
Map<String, Object> result = k8sNamespaceService.updateK8sNamespace(getLoginUser(), 1, null, null, null);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
|
||||
result = k8sNamespaceService.updateK8sNamespace(getLoginUser(), 1, null, -1.0, 100);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS));
|
||||
|
||||
result = k8sNamespaceService.updateK8sNamespace(getLoginUser(), 1, null, 1.0, 100);
|
||||
result = k8sNamespaceService.createK8sNamespace(getLoginUser(), namespace, clusterCode);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
}
|
||||
|
@ -689,8 +689,6 @@ public final class Constants {
|
||||
*/
|
||||
public static final String NAMESPACE = "namespace";
|
||||
public static final String CLUSTER = "cluster";
|
||||
public static final String LIMITS_CPU = "limitsCpu";
|
||||
public static final String LIMITS_MEMORY = "limitsMemory";
|
||||
public static final Long K8S_LOCAL_TEST_CLUSTER_CODE = 0L;
|
||||
|
||||
/**
|
||||
|
@ -44,17 +44,6 @@ public class K8sNamespace {
|
||||
@TableField(value = "namespace")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
* total cpu limit
|
||||
*/
|
||||
@TableField(value = "limits_cpu")
|
||||
private Double limitsCpu;
|
||||
|
||||
/**
|
||||
* total memory limit,mi
|
||||
*/
|
||||
private Integer limitsMemory;
|
||||
|
||||
/**
|
||||
* owner
|
||||
*/
|
||||
@ -79,24 +68,6 @@ public class K8sNamespace {
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 1.00 = 1 cpu
|
||||
*/
|
||||
@TableField("pod_request_cpu")
|
||||
private Double podRequestCpu = 0.0;
|
||||
|
||||
/**
|
||||
* Mi
|
||||
*/
|
||||
@TableField("pod_request_memory")
|
||||
private Integer podRequestMemory = 0;
|
||||
|
||||
/**
|
||||
* replicas
|
||||
*/
|
||||
@TableField("pod_replicas")
|
||||
private Integer podReplicas = 0;
|
||||
|
||||
/**
|
||||
* cluster code
|
||||
*/
|
||||
|
@ -20,11 +20,11 @@
|
||||
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.K8sNamespaceMapper">
|
||||
|
||||
<sql id="baseSql">
|
||||
id, code, namespace, user_id, limits_memory, limits_cpu, pod_replicas, pod_request_cpu, pod_request_memory, cluster_code, create_time, update_time
|
||||
id, code, namespace, user_id, cluster_code, create_time, update_time
|
||||
</sql>
|
||||
|
||||
<sql id="baseSqlV2">
|
||||
${alias}.id, ${alias}.code, ${alias}.namespace, ${alias}.user_id, ${alias}.limits_memory, ${alias}.limits_cpu, ${alias}.pod_replicas, ${alias}.pod_request_cpu, ${alias}.pod_request_memory, ${alias}.cluster_code, ${alias}.create_time, ${alias}.update_time
|
||||
${alias}.id, ${alias}.code, ${alias}.namespace, ${alias}.user_id, ${alias}.cluster_code, ${alias}.create_time, ${alias}.update_time
|
||||
</sql>
|
||||
|
||||
<select id="queryK8sNamespacePaging" resultType="org.apache.dolphinscheduler.dao.entity.K8sNamespace">
|
||||
@ -76,4 +76,4 @@
|
||||
from t_ds_k8s_namespace
|
||||
where code = #{namespaceCode}
|
||||
</select>
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
@ -2024,13 +2024,8 @@ DROP TABLE IF EXISTS t_ds_k8s_namespace;
|
||||
CREATE TABLE t_ds_k8s_namespace (
|
||||
id int(11) NOT NULL AUTO_INCREMENT ,
|
||||
code bigint(20) NOT NULL,
|
||||
limits_memory int(11) DEFAULT NULL,
|
||||
namespace varchar(255) DEFAULT NULL,
|
||||
user_id int(11) DEFAULT NULL,
|
||||
pod_replicas int(11) DEFAULT NULL,
|
||||
pod_request_cpu decimal(14,3) DEFAULT NULL,
|
||||
pod_request_memory int(11) DEFAULT NULL,
|
||||
limits_cpu decimal(14,3) DEFAULT NULL,
|
||||
cluster_code bigint(20) NOT NULL,
|
||||
create_time datetime DEFAULT NULL ,
|
||||
update_time datetime DEFAULT NULL ,
|
||||
@ -2041,16 +2036,16 @@ CREATE TABLE t_ds_k8s_namespace (
|
||||
-- Records of t_ds_k8s_namespace
|
||||
-- ----------------------------
|
||||
INSERT INTO `t_ds_k8s_namespace`
|
||||
(`id`,`code`,`limits_memory`,`namespace`,`user_id`,`pod_replicas`,`pod_request_cpu`,`pod_request_memory`,`limits_cpu`,`cluster_code`,`create_time`,`update_time`)
|
||||
VALUES (1, 990001, 1000, 'flink_test', 1, 1, 0.1, 1, 100, 0, '2022-03-03 11:31:24.0', '2022-03-03 11:31:24.0');
|
||||
(`id`,`code`,`namespace`,`user_id`,`cluster_code`,`create_time`,`update_time`)
|
||||
VALUES (1, 990001, 'flink_test', 1, 0, '2022-03-03 11:31:24.0', '2022-03-03 11:31:24.0');
|
||||
|
||||
INSERT INTO `t_ds_k8s_namespace`
|
||||
(`id`,`code`,`limits_memory`,`namespace`,`user_id`,`pod_replicas`,`pod_request_cpu`,`pod_request_memory`,`limits_cpu`,`cluster_code`,`create_time`,`update_time`)
|
||||
VALUES (2, 990002, 500, 'spark_test', 2, 1, 10000, 1, 100, 0, '2021-03-03 11:31:24.0', '2021-03-03 11:31:24.0');
|
||||
(`id`,`code`,`namespace`,`user_id`,`cluster_code`,`create_time`,`update_time`)
|
||||
VALUES (2, 990002, 'spark_test', 2, 0, '2021-03-03 11:31:24.0', '2021-03-03 11:31:24.0');
|
||||
|
||||
INSERT INTO `t_ds_k8s_namespace`
|
||||
(`id`,`code`,`limits_memory`,`namespace`,`user_id`,`pod_replicas`,`pod_request_cpu`,`pod_request_memory`,`limits_cpu`,`cluster_code`,`create_time`,`update_time`)
|
||||
VALUES (3, 990003, 200, 'auth_test', 3, 1, 100, 1, 10000, 0, '2020-03-03 11:31:24.0', '2020-03-03 11:31:24.0');
|
||||
(`id`,`code`,`namespace`,`user_id`,`cluster_code`,`create_time`,`update_time`)
|
||||
VALUES (3, 990003, 'auth_test', 3, 0, '2020-03-03 11:31:24.0', '2020-03-03 11:31:24.0');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_ds_relation_namespace_user
|
||||
|
@ -2017,13 +2017,8 @@ DROP TABLE IF EXISTS `t_ds_k8s_namespace`;
|
||||
CREATE TABLE `t_ds_k8s_namespace` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`code` bigint(20) NOT NULL DEFAULT '0',
|
||||
`limits_memory` int(11) DEFAULT NULL,
|
||||
`namespace` varchar(255) DEFAULT NULL,
|
||||
`user_id` int(11) DEFAULT NULL,
|
||||
`pod_replicas` int(11) DEFAULT NULL,
|
||||
`pod_request_cpu` decimal(14,3) DEFAULT NULL,
|
||||
`pod_request_memory` int(11) DEFAULT NULL,
|
||||
`limits_cpu` decimal(14,3) DEFAULT NULL,
|
||||
`cluster_code` bigint(20) NOT NULL DEFAULT '0',
|
||||
`create_time` datetime DEFAULT NULL COMMENT 'create time',
|
||||
`update_time` datetime DEFAULT NULL COMMENT 'update time',
|
||||
|
@ -2001,13 +2001,8 @@ DROP TABLE IF EXISTS t_ds_k8s_namespace;
|
||||
CREATE TABLE t_ds_k8s_namespace (
|
||||
id serial NOT NULL,
|
||||
code bigint NOT NULL,
|
||||
limits_memory int DEFAULT NULL ,
|
||||
namespace varchar(255) DEFAULT NULL ,
|
||||
user_id int DEFAULT NULL,
|
||||
pod_replicas int DEFAULT NULL,
|
||||
pod_request_cpu NUMERIC(13,4) NULL,
|
||||
pod_request_memory int DEFAULT NULL,
|
||||
limits_cpu NUMERIC(13,4) NULL,
|
||||
cluster_code bigint NOT NULL,
|
||||
create_time timestamp DEFAULT NULL ,
|
||||
update_time timestamp DEFAULT NULL ,
|
||||
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
-- t_ds_k8s_namespace
|
||||
-- ALTER TABLE t_ds_k8s_namespace DROP COLUMN IF EXISTS limits_cpu;
|
||||
drop PROCEDURE if EXISTS drop_t_ds_k8s_namespace_col_limits_cpu;
|
||||
delimiter d//
|
||||
CREATE PROCEDURE drop_t_ds_k8s_namespace_col_limits_cpu()
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME='t_ds_k8s_namespace'
|
||||
AND TABLE_SCHEMA=(SELECT DATABASE())
|
||||
AND COLUMN_NAME='limits_cpu')
|
||||
THEN
|
||||
ALTER TABLE t_ds_k8s_namespace DROP COLUMN limits_cpu;
|
||||
END IF;
|
||||
END;
|
||||
d//
|
||||
delimiter ;
|
||||
CALL drop_t_ds_k8s_namespace_col_limits_cpu;
|
||||
DROP PROCEDURE drop_t_ds_k8s_namespace_col_limits_cpu;
|
||||
-- ALTER TABLE t_ds_k8s_namespace DROP COLUMN IF EXISTS limits_memory;
|
||||
drop PROCEDURE if EXISTS drop_t_ds_k8s_namespace_col_limits_memory;
|
||||
delimiter d//
|
||||
CREATE PROCEDURE drop_t_ds_k8s_namespace_col_limits_memory()
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME='t_ds_k8s_namespace'
|
||||
AND TABLE_SCHEMA=(SELECT DATABASE())
|
||||
AND COLUMN_NAME='limits_memory')
|
||||
THEN
|
||||
ALTER TABLE t_ds_k8s_namespace DROP COLUMN limits_memory;
|
||||
END IF;
|
||||
END;
|
||||
d//
|
||||
delimiter ;
|
||||
CALL drop_t_ds_k8s_namespace_col_limits_memory;
|
||||
DROP PROCEDURE drop_t_ds_k8s_namespace_col_limits_memory;
|
||||
-- ALTER TABLE t_ds_k8s_namespace DROP COLUMN IF EXISTS pod_replicas;
|
||||
drop PROCEDURE if EXISTS drop_t_ds_k8s_namespace_col_pod_replicas;
|
||||
delimiter d//
|
||||
CREATE PROCEDURE drop_t_ds_k8s_namespace_col_pod_replicas()
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME='t_ds_k8s_namespace'
|
||||
AND TABLE_SCHEMA=(SELECT DATABASE())
|
||||
AND COLUMN_NAME='pod_replicas')
|
||||
THEN
|
||||
ALTER TABLE t_ds_k8s_namespace DROP COLUMN pod_replicas;
|
||||
END IF;
|
||||
END;
|
||||
d//
|
||||
delimiter ;
|
||||
CALL drop_t_ds_k8s_namespace_col_pod_replicas;
|
||||
DROP PROCEDURE drop_t_ds_k8s_namespace_col_pod_replicas;
|
||||
-- ALTER TABLE t_ds_k8s_namespace DROP COLUMN IF EXISTS pod_request_cpu;
|
||||
drop PROCEDURE if EXISTS drop_t_ds_k8s_namespace_col_pod_request_cpu;
|
||||
delimiter d//
|
||||
CREATE PROCEDURE drop_t_ds_k8s_namespace_col_pod_request_cpu()
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME='t_ds_k8s_namespace'
|
||||
AND TABLE_SCHEMA=(SELECT DATABASE())
|
||||
AND COLUMN_NAME='pod_request_cpu')
|
||||
THEN
|
||||
ALTER TABLE t_ds_k8s_namespace DROP COLUMN pod_request_cpu;
|
||||
END IF;
|
||||
END;
|
||||
d//
|
||||
delimiter ;
|
||||
CALL drop_t_ds_k8s_namespace_col_pod_request_cpu;
|
||||
DROP PROCEDURE drop_t_ds_k8s_namespace_col_pod_request_cpu;
|
||||
-- ALTER TABLE t_ds_k8s_namespace DROP COLUMN IF EXISTS pod_request_memory;
|
||||
drop PROCEDURE if EXISTS drop_t_ds_k8s_namespace_col_pod_request_memory;
|
||||
delimiter d//
|
||||
CREATE PROCEDURE drop_t_ds_k8s_namespace_col_pod_request_memory()
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME='t_ds_k8s_namespace'
|
||||
AND TABLE_SCHEMA=(SELECT DATABASE())
|
||||
AND COLUMN_NAME='pod_request_memory')
|
||||
THEN
|
||||
ALTER TABLE t_ds_k8s_namespace DROP COLUMN pod_request_memory;
|
||||
END IF;
|
||||
END;
|
||||
d//
|
||||
delimiter ;
|
||||
CALL drop_t_ds_k8s_namespace_col_pod_request_memory;
|
||||
DROP PROCEDURE drop_t_ds_k8s_namespace_col_pod_request_memory;
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
-- t_ds_k8s_namespace
|
||||
ALTER TABLE "t_ds_k8s_namespace" DROP COLUMN IF EXISTS "limits_cpu";
|
||||
ALTER TABLE "t_ds_k8s_namespace" DROP COLUMN IF EXISTS "limits_memory";
|
||||
ALTER TABLE "t_ds_k8s_namespace" DROP COLUMN IF EXISTS "pod_replicas";
|
||||
ALTER TABLE "t_ds_k8s_namespace" DROP COLUMN IF EXISTS "pod_request_cpu";
|
||||
ALTER TABLE "t_ds_k8s_namespace" DROP COLUMN IF EXISTS "pod_request_memory";
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
@ -49,8 +49,6 @@ public class K8sNamespaceMapperTest extends BaseDaoTest {
|
||||
k8sNamespace.setNamespace("testNamespace");
|
||||
k8sNamespace.setClusterCode(100L);
|
||||
k8sNamespace.setClusterName("ds_null_k8s");
|
||||
k8sNamespace.setLimitsCpu(100.0);
|
||||
k8sNamespace.setLimitsMemory(100);
|
||||
k8sNamespace.setCreateTime(new Date());
|
||||
k8sNamespace.setUpdateTime(new Date());
|
||||
k8sNamespaceMapper.insert(k8sNamespace);
|
||||
@ -80,7 +78,6 @@ public class K8sNamespaceMapperTest extends BaseDaoTest {
|
||||
public void testUpdate() {
|
||||
// insertOne
|
||||
K8sNamespace k8sNamespace = insertOne();
|
||||
k8sNamespace.setLimitsMemory(200);
|
||||
// update
|
||||
int update = k8sNamespaceMapper.updateById(k8sNamespace);
|
||||
Assertions.assertEquals(update, 1);
|
||||
|
@ -50,17 +50,6 @@ export function createK8sNamespace(params: K8SReq): any {
|
||||
})
|
||||
}
|
||||
|
||||
export function updateK8sNamespace(params: K8SReq, id: number): any {
|
||||
return axios({
|
||||
url: `/k8s-namespace/${id}`,
|
||||
method: 'put',
|
||||
params: {
|
||||
...params,
|
||||
id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function delNamespaceById(id: number): any {
|
||||
return axios({
|
||||
url: '/k8s-namespace/delete',
|
||||
|
@ -26,18 +26,12 @@ interface K8SReq {
|
||||
clusterCode: string
|
||||
owner?: string
|
||||
tag?: string
|
||||
limitsCpu?: number | string
|
||||
limitsMemory?: number | string
|
||||
}
|
||||
|
||||
interface NamespaceItem extends K8SReq {
|
||||
id: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
podRequestCpu?: any
|
||||
podRequestMemory?: any
|
||||
podReplicas?: any
|
||||
onlineJobNum?: any
|
||||
}
|
||||
|
||||
interface NamespaceListRes {
|
||||
|
@ -23,14 +23,7 @@ import {
|
||||
watch
|
||||
} from 'vue'
|
||||
import Modal from '@/components/modal'
|
||||
import {
|
||||
NForm,
|
||||
NFormItem,
|
||||
NInput,
|
||||
NInputGroup,
|
||||
NInputGroupLabel,
|
||||
NSelect
|
||||
} from 'naive-ui'
|
||||
import { NForm, NFormItem, NInput, NSelect } from 'naive-ui'
|
||||
import { useModal } from './use-modal'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@ -59,8 +52,6 @@ const K8sNamespaceModal = defineComponent({
|
||||
if (props.statusRef === 0) {
|
||||
variables.model.namespace = ''
|
||||
variables.model.clusterCode = ''
|
||||
variables.model.limitsCpu = ''
|
||||
variables.model.limitsMemory = ''
|
||||
variables.model.userId = ''
|
||||
}
|
||||
ctx.emit('cancelModal', props.showModalRef)
|
||||
@ -85,15 +76,11 @@ const K8sNamespaceModal = defineComponent({
|
||||
if (props.statusRef === 0) {
|
||||
variables.model.namespace = ''
|
||||
variables.model.clusterCode = ''
|
||||
variables.model.limitsCpu = ''
|
||||
variables.model.limitsMemory = ''
|
||||
variables.model.userId = ''
|
||||
} else {
|
||||
variables.model.id = props.row.id
|
||||
variables.model.namespace = props.row.namespace
|
||||
variables.model.clusterCode = props.row.clusterCode
|
||||
variables.model.limitsCpu = props.row.limitsCpu + ''
|
||||
variables.model.limitsMemory = props.row.limitsMemory + ''
|
||||
variables.model.userId = props.row.userId
|
||||
}
|
||||
}
|
||||
@ -105,8 +92,6 @@ const K8sNamespaceModal = defineComponent({
|
||||
variables.model.id = props.row.id
|
||||
variables.model.namespace = props.row.namespace
|
||||
variables.model.clusterCode = props.row.clusterCode
|
||||
variables.model.limitsCpu = props.row.limitsCpu + ''
|
||||
variables.model.limitsMemory = props.row.limitsMemory + ''
|
||||
variables.model.userId = props.row.userId
|
||||
}
|
||||
)
|
||||
@ -118,11 +103,7 @@ const K8sNamespaceModal = defineComponent({
|
||||
return (
|
||||
<div>
|
||||
<Modal
|
||||
title={
|
||||
this.statusRef === 0
|
||||
? t('security.k8s_namespace.create_namespace')
|
||||
: t('security.k8s_namespace.edit_namespace')
|
||||
}
|
||||
title={t('security.k8s_namespace.create_namespace')}
|
||||
show={this.showModalRef}
|
||||
onCancel={this.cancelModal}
|
||||
onConfirm={this.confirmModal}
|
||||
@ -162,34 +143,6 @@ const K8sNamespaceModal = defineComponent({
|
||||
disabled={this.statusRef !== 0}
|
||||
/>
|
||||
</NFormItem>
|
||||
<NFormItem
|
||||
label={t('security.k8s_namespace.limit_cpu')}
|
||||
path='limitsCpu'
|
||||
>
|
||||
<NInputGroup>
|
||||
<NInput
|
||||
allowInput={this.trim}
|
||||
placeholder={t('security.k8s_namespace.limit_cpu_tips')}
|
||||
v-model={[this.model.limitsCpu, 'value']}
|
||||
/>
|
||||
<NInputGroupLabel>CORE</NInputGroupLabel>
|
||||
</NInputGroup>
|
||||
</NFormItem>
|
||||
<NFormItem
|
||||
label={t('security.k8s_namespace.limit_memory')}
|
||||
path='limitsMemory'
|
||||
>
|
||||
<NInputGroup>
|
||||
<NInput
|
||||
allowInput={this.trim}
|
||||
placeholder={t(
|
||||
'security.k8s_namespace.limit_memory_tips'
|
||||
)}
|
||||
v-model={[this.model.limitsMemory, 'value']}
|
||||
/>
|
||||
<NInputGroupLabel>GB</NInputGroupLabel>
|
||||
</NInputGroup>
|
||||
</NFormItem>
|
||||
</NForm>
|
||||
)
|
||||
}}
|
||||
|
@ -19,8 +19,7 @@ import { reactive, ref, SetupContext } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import {
|
||||
verifyNamespaceK8s,
|
||||
createK8sNamespace,
|
||||
updateK8sNamespace
|
||||
createK8sNamespace
|
||||
} from '@/service/modules/k8s-namespace'
|
||||
import { queryAllClusterList } from '@/service/modules/cluster'
|
||||
import { useAsyncState } from '@vueuse/core'
|
||||
@ -38,8 +37,6 @@ export function useModal(
|
||||
namespace: ref(''),
|
||||
clusterCode: ref(''),
|
||||
userId: ref(''),
|
||||
limitsCpu: ref(''),
|
||||
limitsMemory: ref(''),
|
||||
clusterOptions: []
|
||||
},
|
||||
saving: false,
|
||||
@ -72,9 +69,10 @@ export function useModal(
|
||||
variables.saving = true
|
||||
|
||||
try {
|
||||
statusRef === 0
|
||||
? await submitK8SNamespaceModal()
|
||||
: await updateK8SNamespaceModal()
|
||||
if (statusRef === 0) {
|
||||
submitK8SNamespaceModal()
|
||||
}
|
||||
|
||||
variables.saving = false
|
||||
} catch (err) {
|
||||
variables.saving = false
|
||||
@ -110,22 +108,12 @@ export function useModal(
|
||||
createK8sNamespace(variables.model).then(() => {
|
||||
variables.model.namespace = ''
|
||||
variables.model.clusterCode = ''
|
||||
variables.model.limitsCpu = ''
|
||||
variables.model.limitsMemory = ''
|
||||
variables.model.userId = ''
|
||||
ctx.emit('confirmModal', props.showModalRef)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const updateK8SNamespaceModal = () => {
|
||||
updateK8sNamespace(variables.model, variables.model.id).then(
|
||||
(ignored: any) => {
|
||||
ctx.emit('confirmModal', props.showModalRef)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
variables,
|
||||
handleValidate,
|
||||
|
@ -20,7 +20,7 @@ import { reactive, h, ref } from 'vue'
|
||||
import { NButton, NIcon, NPopconfirm, NSpace, NTooltip } from 'naive-ui'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { format } from 'date-fns'
|
||||
import { DeleteOutlined, EditOutlined } from '@vicons/antd'
|
||||
import { DeleteOutlined } from '@vicons/antd'
|
||||
import {
|
||||
queryNamespaceListPaging,
|
||||
delNamespaceById
|
||||
@ -39,12 +39,6 @@ import {
|
||||
export function useTable() {
|
||||
const { t } = useI18n()
|
||||
|
||||
const handleEdit = (row: NamespaceItem) => {
|
||||
variables.showModalRef = true
|
||||
variables.statusRef = 1
|
||||
variables.row = row
|
||||
}
|
||||
|
||||
const handleDelete = (row: NamespaceItem) => {
|
||||
delNamespaceById(row.id).then(() => {
|
||||
getTableData({
|
||||
@ -76,16 +70,6 @@ export function useTable() {
|
||||
key: 'clusterName',
|
||||
...COLUMN_WIDTH_CONFIG['name']
|
||||
},
|
||||
{
|
||||
title: t('security.k8s_namespace.limit_cpu'),
|
||||
key: 'limitsCpu',
|
||||
width: 140
|
||||
},
|
||||
{
|
||||
title: t('security.k8s_namespace.limit_memory'),
|
||||
key: 'limitsMemory',
|
||||
width: 140
|
||||
},
|
||||
{
|
||||
title: t('security.k8s_namespace.create_time'),
|
||||
key: 'createTime',
|
||||
@ -103,29 +87,6 @@ export function useTable() {
|
||||
render(row: NamespaceItem) {
|
||||
return h(NSpace, null, {
|
||||
default: () => [
|
||||
h(
|
||||
NTooltip,
|
||||
{},
|
||||
{
|
||||
trigger: () =>
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
circle: true,
|
||||
type: 'info',
|
||||
size: 'small',
|
||||
onClick: () => {
|
||||
handleEdit(row)
|
||||
}
|
||||
},
|
||||
{
|
||||
icon: () =>
|
||||
h(NIcon, null, { default: () => h(EditOutlined) })
|
||||
}
|
||||
),
|
||||
default: () => t('security.k8s_namespace.edit')
|
||||
}
|
||||
),
|
||||
h(
|
||||
NPopconfirm,
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user