diff --git a/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/Consts.java b/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/Consts.java index ce4d209308..b541180b9c 100644 --- a/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/Consts.java +++ b/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/Consts.java @@ -27,6 +27,8 @@ public class Consts { // k8s命名空间 public static final String KEY_KUBERNETES_NAMESPACE = "KUBERNETES_NAMESPACE"; + // k8s默认命名空间 + public static final String VALUE_NAMESPACE_DEFAULT = "default"; // 服务启动依赖关系定义字符串 public static final String KEY_STARTUP_DEPENDENCIES_STR = "BK_JOB_STARTUP_DEPENDENCIES_STR"; // 当前服务名称 diff --git a/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/ServiceDependModel.java b/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/ServiceDependModel.java index 04567f2b2d..198f6c7d5b 100644 --- a/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/ServiceDependModel.java +++ b/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/ServiceDependModel.java @@ -30,7 +30,7 @@ @Data public class ServiceDependModel { @Parameter(names = {"-n", "--namespace"}, description = "当前服务所在的命名空间") - private String namespace = "default"; + private String namespace; @Parameter(names = {"-s", "--service"}, description = "当前服务名称") private String serviceName; diff --git a/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/StartupController.java b/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/StartupController.java index 856fd9a26a..d264f5d0a6 100644 --- a/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/StartupController.java +++ b/src/backend/job-tools/k8s-startup-controller/src/main/java/com/tencent/bk/job/k8s/StartupController.java @@ -139,6 +139,10 @@ static ServiceDependModel parseDependModelFromArgsOrEnv(String[] args) { Consts.KEY_KUBERNETES_NAMESPACE, namespace ); + if (StringUtils.isBlank(namespace)) { + namespace = Consts.VALUE_NAMESPACE_DEFAULT; + log.warn("use default namespace:{}", namespace); + } serviceDependModel.setNamespace(namespace); } String serviceName = serviceDependModel.getServiceName();