diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties index dee57d6784..9dff79cf91 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties @@ -57,6 +57,7 @@ 1240003=错误的请求 1240004=Cookie过期或者不存在 1240005=服务认证失败 +1240006=配置异常:{0} ##系统错误-公共组件错误 1250001=Redis服务连接失败 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties index ae95ef5a65..435ab04ec4 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties @@ -57,6 +57,7 @@ 1240003=Bad Request 1240004=Cookies expire or do not exist 1240005=Service auth fail +1240006=Invalid config:{0} ## System error - common components 1250001=Redis service connection failed diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties index ae95ef5a65..435ab04ec4 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties @@ -57,6 +57,7 @@ 1240003=Bad Request 1240004=Cookies expire or do not exist 1240005=Service auth fail +1240006=Invalid config:{0} ## System error - common components 1250001=Redis service connection failed diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties index dee57d6784..9dff79cf91 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties @@ -57,6 +57,7 @@ 1240003=错误的请求 1240004=Cookie过期或者不存在 1240005=服务认证失败 +1240006=配置异常:{0} ##系统错误-公共组件错误 1250001=Redis服务连接失败 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties index dee57d6784..9dff79cf91 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties @@ -57,6 +57,7 @@ 1240003=错误的请求 1240004=Cookie过期或者不存在 1240005=服务认证失败 +1240006=配置异常:{0} ##系统错误-公共组件错误 1250001=Redis服务连接失败 diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java index 1bbe66b1a0..d81ee44f15 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java @@ -348,6 +348,8 @@ public class ErrorCode { public static final int SERVICE_UNAVAILABLE = 1240001; // 服务认证失败 public static final int SERVICE_AUTH_FAIL = 1240005; + // 配置异常:{0} + public static final int INVALID_CONFIG = 1240006; // ========= 系统错误-API通用 ==================// // IP:{}无访问权限 diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/IncorrectConfigException.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/IncorrectConfigException.java new file mode 100644 index 0000000000..8827c6fb64 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/IncorrectConfigException.java @@ -0,0 +1,16 @@ +package com.tencent.bk.job.common.exception; + +import lombok.Getter; +import lombok.ToString; + +/** + * 内部服务异常--配置异常 + */ +@Getter +@ToString +public class IncorrectConfigException extends InternalException { + + public IncorrectConfigException(String message, Integer errorCode, Object[] errorParams) { + super(message, errorCode, errorParams); + } +} diff --git a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/cos/service/EnvironmentService.java b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/cos/service/EnvironmentService.java index e0779d272b..09ed6fdff8 100644 --- a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/cos/service/EnvironmentService.java +++ b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/cos/service/EnvironmentService.java @@ -1,6 +1,8 @@ package com.tencent.bk.job.file.worker.cos.service; +import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.constant.JobConstants; +import com.tencent.bk.job.common.exception.IncorrectConfigException; import com.tencent.bk.job.common.util.ip.IpUtils; import com.tencent.bk.job.file.worker.config.WorkerConfig; import io.micrometer.core.instrument.util.StringUtils; @@ -37,8 +39,24 @@ public boolean isInK8s() { } private String getAccessHostInK8s() { - String podName = System.getenv("BK_JOB_POD_NAME"); + String podName = System.getenv("BK_JOB_FILE_WORKER_POD_NAME"); + if (StringUtils.isBlank(podName)) { + String message = "ENV BK_JOB_FILE_WORKER_POD_NAME cannot be blank!"; + throw new IncorrectConfigException( + message, + ErrorCode.INVALID_CONFIG, + new String[]{"ENV:BK_JOB_FILE_WORKER_POD_NAME"} + ); + } String fileWorkerServiceName = System.getenv("BK_JOB_FILE_WORKER_SERVICE_NAME"); + if (StringUtils.isBlank(fileWorkerServiceName)) { + String message = "ENV BK_JOB_FILE_WORKER_SERVICE_NAME cannot be blank!"; + throw new IncorrectConfigException( + message, + ErrorCode.INVALID_CONFIG, + new String[]{"ENV:BK_JOB_FILE_WORKER_SERVICE_NAME"} + ); + } String accessHost = podName + "." + fileWorkerServiceName; log.debug("accessHost={}", accessHost); return accessHost; diff --git a/support-files/kubernetes/charts/bk-job/templates/job-file-worker/statefulset.yaml b/support-files/kubernetes/charts/bk-job/templates/job-file-worker/statefulset.yaml index 3e284f16ac..3e8f8fdc8b 100644 --- a/support-files/kubernetes/charts/bk-job/templates/job-file-worker/statefulset.yaml +++ b/support-files/kubernetes/charts/bk-job/templates/job-file-worker/statefulset.yaml @@ -94,7 +94,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - - name: BK_JOB_POD_NAME + - name: BK_JOB_FILE_WORKER_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name