From a15ab195c64fe38c9bb19c348ebd6b752d66a00e Mon Sep 17 00:00:00 2001 From: lazy <65394407+liuzg-coder@users.noreply.github.com> Date: Wed, 1 Nov 2023 07:28:06 -0500 Subject: [PATCH] extract variables (#13284) --- .../apache/dubbo/common/constants/CommonConstants.java | 4 ++++ .../java/org/apache/dubbo/config/ReferenceConfig.java | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index c3aea739ee..b75b5a53d0 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -646,4 +646,8 @@ public interface CommonConstants { String SERVICE_DEPLOYER_ATTRIBUTE_KEY = "serviceDeployer"; String DUBBO_MANUAL_REGISTER_KEY = "dubbo.application.manual-register"; + + String POD_NAMESPACE = "POD_NAMESPACE"; + + String CLUSTER_DOMAIN = "CLUSTER_DOMAIN"; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 9d8280d312..343f8d0ac1 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -66,6 +66,7 @@ import java.util.Set; import java.util.TreeSet; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_DOMAIN; import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR_CHAR; @@ -77,6 +78,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.MESH_ENABLE; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.POD_NAMESPACE; import static org.apache.dubbo.common.constants.CommonConstants.PROXY_CLASS_REF; import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN; @@ -504,21 +506,21 @@ public class ReferenceConfig extends ReferenceConfigBase { // get pod namespace from env if annotation not present the provider namespace if (StringUtils.isEmpty(podNamespace)) { - if (StringUtils.isEmpty(System.getenv("POD_NAMESPACE"))) { + if (StringUtils.isEmpty(System.getenv(POD_NAMESPACE))) { if (logger.isWarnEnabled()) { logger.warn(CONFIG_FAILED_LOAD_ENV_VARIABLE, "", "", "Can not get env variable: POD_NAMESPACE, it may not be running in the K8S environment , " + "finally use 'default' replace."); } podNamespace = "default"; } else { - podNamespace = System.getenv("POD_NAMESPACE"); + podNamespace = System.getenv(POD_NAMESPACE); } } // In mesh mode, providedBy equals K8S Service name. String providedBy = referenceParameters.get(PROVIDED_BY); // cluster_domain default is 'cluster.local',generally unchanged. - String clusterDomain = Optional.ofNullable(System.getenv("CLUSTER_DOMAIN")).orElse(DEFAULT_CLUSTER_DOMAIN); + String clusterDomain = Optional.ofNullable(System.getenv(CLUSTER_DOMAIN)).orElse(DEFAULT_CLUSTER_DOMAIN); // By VirtualService and DestinationRule, envoy will generate a new route rule,such as 'demo.default.svc.cluster.local:80',the default port is 80. Integer meshPort = Optional.ofNullable(getProviderPort()).orElse(DEFAULT_MESH_PORT); // DubboReference default is -1, process it.