|
|
@@ -0,0 +1,57 @@
|
|
|
+package nju.seec.SEECdemo.logic.api.k8s.util;
|
|
|
+
|
|
|
+import io.kubernetes.client.ApiClient;
|
|
|
+import io.kubernetes.client.Configuration;
|
|
|
+import io.kubernetes.client.apis.CoreV1Api;
|
|
|
+import io.kubernetes.client.util.Config;
|
|
|
+import nju.seec.SEECdemo.logic.vo.projecttemplate.ProjectTemplate;
|
|
|
+import nju.seec.SEECdemo.data.entity.resource.ResourceConfig;
|
|
|
+import nju.seec.SEECdemo.util.ApplicationProperties;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import nju.seec.SEECdemo.util.ApplicationProperties.K8s;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class BeanAnnouncement {
|
|
|
+
|
|
|
+ private final CoreV1Api coreV1Api;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public BeanAnnouncement(ApplicationProperties applicationProperties) {
|
|
|
+ K8s k8s = applicationProperties.getK8s();
|
|
|
+ String apiServer = k8s.getApiServer();
|
|
|
+ String token = k8s.getToken();
|
|
|
+
|
|
|
+ ApiClient apiClient = Config.fromToken(apiServer, token);
|
|
|
+ Configuration.setDefaultApiClient(apiClient);
|
|
|
+ this.coreV1Api = new CoreV1Api();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public CoreV1Api k8sApi(){
|
|
|
+ return coreV1Api;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 软工二的项目模板
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ public ProjectTemplate seecIITemplate() {
|
|
|
+ ProjectTemplate projectTemplate = new ProjectTemplate();
|
|
|
+ ResourceConfig resourceConfig = new ResourceConfig();
|
|
|
+ resourceConfig.setDefaultCPU(5);
|
|
|
+ resourceConfig.setMaxCPU(10);
|
|
|
+ resourceConfig.setMinCPU(5);
|
|
|
+ resourceConfig.setDefaultMemory(100);
|
|
|
+ resourceConfig.setMaxMemory(500);
|
|
|
+ resourceConfig.setMinMemory(100);
|
|
|
+ resourceConfig.setDefaultStorage(0);
|
|
|
+ resourceConfig.setMaxStorage(1000);
|
|
|
+ projectTemplate.setDefaultResourceConfig(resourceConfig);
|
|
|
+ projectTemplate.setName("软工二大作业");
|
|
|
+ projectTemplate.setDescription("部署单个应用到部署项目下,应用集中连接唯一的数据库");
|
|
|
+ return projectTemplate;
|
|
|
+ }
|
|
|
+}
|