Parcourir la source

fix: 错误的k8s api查询deployment状态

370774330@qq.com il y a 5 ans
Parent
commit
facc31f481

+ 11 - 7
web/src/main/java/seecoder/devcloud/web/service/impl/pipeline/DeploymentServiceImpl.java

@@ -1,11 +1,11 @@
 package seecoder.devcloud.web.service.impl.pipeline;
 
+import io.kubernetes.client.openapi.models.V1DeploymentStatus;
 import org.apache.http.HttpStatus;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import seecoder.devcloud.api.ApplicationProperties;
-import seecoder.devcloud.api.k8s.model.DeploymentStatus;
 import seecoder.devcloud.common.exceptions.AccessDeniedException;
 import seecoder.devcloud.common.exceptions.ServiceException;
 import seecoder.devcloud.core.pipeline.Pipeline;
@@ -25,6 +25,7 @@ import seecoder.devcloud.web.model.vo.pipeline.DeploymentInfoVO;
 import seecoder.devcloud.web.service.pipeline.DeploymentService;
 
 import java.sql.Timestamp;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -60,21 +61,24 @@ public class DeploymentServiceImpl implements DeploymentService {
     @Override
     public List<DeploymentInfoVO> retrieveDeploymentInfos(Integer projectId) throws AccessDeniedException {
         //projectAuthentication(projectId);
-        ProjectPO project = projectMapper.getProjectById(projectId);
         List<PipelinePO> pipelines = pipelineMapper.selectByProjectId(projectId);
-        // 获取项目所关联的所有流水线
+        if (pipelines.size()==0){
+            return new ArrayList<>();
+        }
         List<Integer> pipelineIds = pipelines.stream().map(PipelinePO::getId).collect(Collectors.toList());
-
         List<DeploymentPO> deployments = deploymentMapper.selectByPipelineIds(pipelineIds);
         return deployments.stream().map(x->{
             PipelineInspector inspector = PipelineInspectorFactory.init(x.getNamespace(),x.getDeployName());
             //获取状态
             String status = null;
-            DeploymentStatus deploymentStatus = inspector.inspectStatus();
-            if(deploymentStatus.isAvailable()){
+            V1DeploymentStatus deploymentStatus = inspector.inspectStatus();
+            if (deploymentStatus == null){
+                status = "部署不存在,请重新部署";
+            }
+            else if(deploymentStatus.getAvailableReplicas()==1){
                 status = "正常运行";
             } else{
-                status = "不可用: " + deploymentStatus.getProgressingMessage();
+                status = "不可用";
             }
             return DeploymentInfoVO.builder()
                     .pipelineId(x.getPipelineId())