|
|
@@ -1,13 +1,13 @@
|
|
|
package seecoder.devcloud.core.pipeline.inspector;
|
|
|
|
|
|
-import seecoder.devcloud.api.k8s.DeploymentApi;
|
|
|
-import seecoder.devcloud.api.k8s.K8sConstants;
|
|
|
-import seecoder.devcloud.api.k8s.NamespaceApi;
|
|
|
-import seecoder.devcloud.api.k8s.model.DeploymentStatus;
|
|
|
-import seecoder.devcloud.api.k8s.model.Namespace;
|
|
|
+import io.kubernetes.client.openapi.models.V1DeploymentStatus;
|
|
|
+import seecoder.devcloud.api.k8s.*;
|
|
|
+import seecoder.devcloud.api.k8s.model.*;
|
|
|
import seecoder.devcloud.common.util.SpringUtil;
|
|
|
import seecoder.devcloud.core.pipeline.Context;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @author PuHong Weng
|
|
|
* @date 2021/3/23
|
|
|
@@ -23,24 +23,49 @@ public class PipelineInspector {
|
|
|
|
|
|
private final DeploymentApi deploymentApi;
|
|
|
|
|
|
+ private final ServiceApi serviceApi;
|
|
|
+
|
|
|
+ private final IngressApi ingressApi;
|
|
|
+
|
|
|
public PipelineInspector(Context context) {
|
|
|
this.context = context;
|
|
|
this.deploymentApi = SpringUtil.getBean(DeploymentApi.class);
|
|
|
namespaceApi = SpringUtil.getBean(NamespaceApi.class);
|
|
|
+ serviceApi = SpringUtil.getBean(ServiceApi.class);
|
|
|
+ ingressApi = SpringUtil.getBean(IngressApi.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
- public DeploymentStatus inspectStatus(){
|
|
|
+ public V1DeploymentStatus inspectStatus(){
|
|
|
String name = context.getDeployName() + K8sConstants.DEPLOYMENT_SUFFIX;
|
|
|
DeploymentStatus status = deploymentApi.getStatus(context.getNamespace(),name);
|
|
|
- return status;
|
|
|
+ List<Deployment> deployments = deploymentApi.getByCondition(K8sObjectRequest.builder()
|
|
|
+ .namespace(context.getNamespace())
|
|
|
+ .name(name)
|
|
|
+ .build());
|
|
|
+ //默认都是1个副本
|
|
|
+ return deployments.size() == 0? null : deployments.get(0).getStatus();
|
|
|
}
|
|
|
|
|
|
|
|
|
public void delete(){
|
|
|
- Namespace namespace = new Namespace();
|
|
|
- namespace.setName(context.getNamespace());
|
|
|
- namespaceApi.delete(namespace);
|
|
|
+ String namespace = context.getNamespace();
|
|
|
+ String deployName = context.getDeployName();
|
|
|
+ //删除deployment
|
|
|
+ Deployment deployment = new Deployment();
|
|
|
+ deployment.setNamespace(namespace);
|
|
|
+ deployment.setName(deployName+K8sConstants.DEPLOYMENT_SUFFIX);
|
|
|
+ deploymentApi.delete(deployment);
|
|
|
+ //删除service
|
|
|
+ Service service = new Service();
|
|
|
+ service.setNamespace(namespace);
|
|
|
+ service.setName(deployName+K8sConstants.SERVICE_SUFFIX);
|
|
|
+ serviceApi.delete(service);
|
|
|
+ //删除ingress
|
|
|
+ Ingress ingress = new Ingress();
|
|
|
+ ingress.setNamespace(namespace);
|
|
|
+ ingress.setName(deployName+K8sConstants.INGRESS_SUFFIX);
|
|
|
+ ingressApi.delete(ingress);
|
|
|
}
|
|
|
|
|
|
|