|
|
@@ -1,5 +1,13 @@
|
|
|
package cn.seecoder.devmanage.controller;
|
|
|
|
|
|
+import cn.seecoder.api.k8s.DeploymentApi;
|
|
|
+import cn.seecoder.api.k8s.LimitRangeApi;
|
|
|
+import cn.seecoder.api.k8s.PodApi;
|
|
|
+import cn.seecoder.api.k8s.model.Deployment;
|
|
|
+import cn.seecoder.api.k8s.model.K8sObjectRequest;
|
|
|
+import cn.seecoder.api.k8s.model.LimitRange;
|
|
|
+import cn.seecoder.api.k8s.model.Pod;
|
|
|
+import cn.seecoder.common.util.SpringUtil;
|
|
|
import cn.seecoder.devmanage.model.po.LocalLog;
|
|
|
import cn.seecoder.devmanage.model.vo.LocalLogVo;
|
|
|
import cn.seecoder.devmanage.model.vo.Response;
|
|
|
@@ -7,9 +15,10 @@ import cn.seecoder.devmanage.service.HelloService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.context.annotation.Profile;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* For test purpose only.
|
|
|
* This controller does not go valid in production.
|
|
|
@@ -24,7 +33,7 @@ public class HelloController {
|
|
|
|
|
|
@GetMapping("/hello")
|
|
|
public ResponseEntity<Response<String>> hello() {
|
|
|
- return ResponseEntity.accepted().body(Response.buildSuccess("Hello Seecoder"));
|
|
|
+ return ResponseEntity.ok().body(Response.buildSuccess("Hello Seecoder"));
|
|
|
}
|
|
|
|
|
|
@PutMapping("/log")
|
|
|
@@ -35,7 +44,55 @@ public class HelloController {
|
|
|
Response.buildFailure(400, "Error: invalid date format.", null)
|
|
|
);
|
|
|
} else {
|
|
|
- return ResponseEntity.accepted().body(Response.buildSuccess(new LocalLogVo(localLog)));
|
|
|
+ return ResponseEntity.ok().body(Response.buildSuccess(new LocalLogVo(localLog)));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/deployment")
|
|
|
+ public ResponseEntity<Response<List<Deployment>>> getDeploymentByCondition(@RequestParam String namespace, @RequestParam(required = false) String name) {
|
|
|
+ DeploymentApi deploymentApi = SpringUtil.getBean(DeploymentApi.class);
|
|
|
+ K8sObjectRequest mysqlRequest = K8sObjectRequest.builder().namespace(namespace).name(name).build();
|
|
|
+ List<Deployment> deployments = deploymentApi.getByCondition(mysqlRequest);
|
|
|
+ return ResponseEntity.ok().body(Response.buildSuccess(deployments));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/limit")
|
|
|
+ public ResponseEntity<Response<List<LimitRange>>> getLimitRangeByCondition(@RequestParam String namespace, @RequestParam(required = false) String name) {
|
|
|
+ LimitRangeApi limitRangeApi = SpringUtil.getBean(LimitRangeApi.class);
|
|
|
+ K8sObjectRequest limitRequest = K8sObjectRequest.builder().namespace(namespace).name(name).build();
|
|
|
+ System.out.println(limitRequest);
|
|
|
+ List<LimitRange> limitRanges = limitRangeApi.getByCondition(limitRequest);
|
|
|
+ return ResponseEntity.ok().body(Response.buildSuccess(limitRanges));
|
|
|
+ }
|
|
|
+
|
|
|
+// @GetMapping("/limit")
|
|
|
+// public ResponseEntity<Response<V1LimitRangeList>> getLimitRangeByCondition(@RequestParam String namespace) {
|
|
|
+// try {
|
|
|
+// CoreV1Api coreV1Api = SpringUtil.getBean(CoreV1Api.class);
|
|
|
+// V1LimitRangeList objList = coreV1Api.listNamespacedLimitRange(
|
|
|
+// namespace,
|
|
|
+// PRETTY_FORMAT,
|
|
|
+// null,
|
|
|
+// null,
|
|
|
+// null,
|
|
|
+// new LabelSelector().toJsonString(),
|
|
|
+// null,
|
|
|
+// null,
|
|
|
+// null,
|
|
|
+// null);
|
|
|
+// return ResponseEntity.ok().body(Response.buildSuccess(objList));
|
|
|
+// } catch (ApiException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// return ResponseEntity.internalServerError()
|
|
|
+// .body(Response.buildFailure(500, "Server Api Exception", null));
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ @GetMapping("/pod")
|
|
|
+ public ResponseEntity<Response<List<Pod>>> getPodByCondition(@RequestParam String namespace, @RequestParam(required = false) String name) {
|
|
|
+ PodApi podApi = SpringUtil.getBean(PodApi.class);
|
|
|
+ K8sObjectRequest podRequest = K8sObjectRequest.builder().namespace(namespace).name(name).build();
|
|
|
+ List<Pod> pods = podApi.getByCondition(podRequest);
|
|
|
+ return ResponseEntity.ok().body(Response.buildSuccess(pods));
|
|
|
+ }
|
|
|
}
|