Browse Source

配置

pull/10/head
fanshuai 1 year ago
parent
commit
934c44f8a1
2 changed files with 38 additions and 14 deletions
  1. +24
    -10
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
  2. +14
    -4
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java

+ 24
- 10
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java View File

@@ -14,9 +14,12 @@ 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.InputStreamReader;
import java.util.HashMap;
@@ -30,13 +33,13 @@ import java.util.Map;
* @date 2021/6/18 14:14
*/
@Slf4j
@Component
public class K8sClientUtil {
@Value("${k8s.http}")
private String http;

@Value("${k8s.token}")
private String token;

/**
* k8s-api客户端
*/
@@ -50,18 +53,29 @@ public class K8sClientUtil {
* 3. service-account namespace
* 4. master endpoints(ip, port) from pre-set environment variables
*/
public K8sClientUtil() {
try {
// @Autowired
// public K8sClientUtil() {
// try {
// 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异常");
// }
// }
@PostConstruct
public void init() {
// try {
this.apiClient = new ClientBuilder().
setBasePath("https://172.20.32.181:6443").setVerifyingSsl(false).
setAuthentication(new AccessTokenAuthentication("eyJhbGciOiJSUzI1NiIsImtpZCI6IjRWcFBPWl9YSFFxQ2tVanRuNHdRT1dnUlJNTnB2bG5TQlVSRjNKdExWNDQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImFkbWluLXNlcnZpY2UtYWNjb3VudC10b2tlbi14ZDk5eiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbi1zZXJ2aWNlLWFjY291bnQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJmMGEzNmYyMS01MjQyLTQ4MTAtYWVmZS0xOTEwOTZlZjc5YmUiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmYXVsdDphZG1pbi1zZXJ2aWNlLWFjY291bnQifQ.fo-Wf0-5-IRC5fhRh65yfqCJqKfE9MrNFIXL2fd1CqVAHD7JBpWO2IsFiSmz9Bm7VfLmFAp2NB7DjW4ZLjC7ODiGhpSseBP8x4ceFuHL6pRGUsEBvHQBBBuQcGhNOcsxIDHnDqUdUzoLprj223lMZNTQowITuqYFU4GVbethyEuS6G5Wh9KHI3KYHFtG4_AeWBgI5Ppz8pDrhHzSFWTFbzxQ3RPGEwF0V-9wEtdrSYnfETi3rdRWif9W4a0RW8HwD9Gf7UCYcyFOs7e5_3-IvmctS85g87PYIfHXMhu_kOw-_Il4bkwPEK5uiBFDw0M1-s9YP-F9r5sXXvOJlsAr1g")).build();
} catch (Exception e) {
log.error("构建K8s-Client异常", e);
throw new RuntimeException("构建K8s-Client异常");
}
setBasePath(http).setVerifyingSsl(false).
setAuthentication(new AccessTokenAuthentication(token)).build();
// } catch (Exception e) {
// log.error("构建K8s-Client异常", e);
// throw new RuntimeException("构建K8s-Client异常");
// }
}


/**
* 构建集群外通过UA访问的客户端
* loading the out-of-cluster config, a kubeconfig from file-system


+ 14
- 4
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java View File

@@ -5,9 +5,9 @@ import io.minio.*;
import io.minio.errors.MinioException;
import io.minio.messages.Item;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
@@ -21,11 +21,21 @@ import java.util.zip.ZipOutputStream;

@Component
public class MinioUtil {

@Value("${minio.endpoint}")
private String minioEndpoint;

@Value("${minio.accessKey}")
private String minioAccessKey;

@Value("${minio.secretKey}")
private String minioSecretKey;
private MinioClient minioClient;
public MinioUtil() {
@PostConstruct
public void init() {
this.minioClient = MinioClient.builder()
.endpoint("http://172.20.32.181:30164")
.credentials("admin", "qazxc123456.")
.endpoint(minioEndpoint)
.credentials(minioAccessKey, minioSecretKey)
.build();
}
public void createBucket(String bucketName) throws Exception {


Loading…
Cancel
Save