|
|
|
@@ -1,20 +1,26 @@ |
|
|
|
package com.ruoyi.platform.utils; |
|
|
|
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.reflect.TypeToken; |
|
|
|
import io.kubernetes.client.Exec; |
|
|
|
import io.kubernetes.client.custom.IntOrString; |
|
|
|
import io.kubernetes.client.custom.Quantity; |
|
|
|
import io.kubernetes.client.openapi.ApiClient; |
|
|
|
import io.kubernetes.client.openapi.ApiException; |
|
|
|
import io.kubernetes.client.openapi.Configuration; |
|
|
|
import io.kubernetes.client.openapi.ApiResponse; |
|
|
|
import io.kubernetes.client.openapi.apis.CoreV1Api; |
|
|
|
import io.kubernetes.client.openapi.models.*; |
|
|
|
import io.kubernetes.client.util.Config; |
|
|
|
import io.kubernetes.client.util.ClientBuilder; |
|
|
|
import io.kubernetes.client.util.Watch; |
|
|
|
import io.kubernetes.client.util.credentials.AccessTokenAuthentication; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.poi.ss.formula.functions.T; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
@@ -42,12 +48,13 @@ public class K8sClientUtil { |
|
|
|
* 3. service-account namespace |
|
|
|
* 4. master endpoints(ip, port) from pre-set environment variables |
|
|
|
*/ |
|
|
|
// @Autowired |
|
|
|
public K8sClientUtil() { |
|
|
|
@Autowired |
|
|
|
public K8sClientUtil(@Value("${k8s.http}") String http, @Value("${k8s.token}") String token) { |
|
|
|
try { |
|
|
|
apiClient = Config.defaultClient(); |
|
|
|
Configuration.setDefaultApiClient(apiClient); |
|
|
|
} catch (Exception e) { |
|
|
|
this.apiClient = new ClientBuilder(). |
|
|
|
setBasePath(http).setVerifyingSsl(false). |
|
|
|
setAuthentication(new AccessTokenAuthentication(token)).build(); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("构建K8s-Client异常", e); |
|
|
|
throw new RuntimeException("构建K8s-Client异常"); |
|
|
|
} |
|
|
|
@@ -128,7 +135,7 @@ public class K8sClientUtil { |
|
|
|
for (V1Service svc : v1ServiceList.getItems()) { |
|
|
|
if (StringUtils.equals(svc.getMetadata().getName(), serviceName)) { |
|
|
|
// PVC 已存在 |
|
|
|
return svc; |
|
|
|
return svc; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|