diff --git a/sermant-injector/deployment/release/injector/templates/sermant-injector-configmap.yaml b/sermant-injector/deployment/release/injector/templates/sermant-injector-configmap.yaml index 15796a079e..b00e73dea5 100644 --- a/sermant-injector/deployment/release/injector/templates/sermant-injector-configmap.yaml +++ b/sermant-injector/deployment/release/injector/templates/sermant-injector-configmap.yaml @@ -10,12 +10,16 @@ data: SERMANT_AGENT_CONFIG_TYPE: {{ .Values.config.type }} # 配置中心地址 SERMANT_AGENT_CONFIG_ADDRESS: {{ .Values.config.endpoints }} + # 注册中心类型 + SERMANT_AGENT_SERVICE_TYPE: {{ .Values.registry.type }} # 注册中心地址 SERMANT_AGENT_SERVICE_ADDRESS: {{ .Values.registry.endpoints }} # agent镜像地址 SERMANT_AGENT_IMAGE_ADDR: {{ .Values.agent.image.addr }} # agent镜像拉取策略 SERMANT_AGENT_IMAGE_PULLPOLICY: {{ .Values.agent.image.pullPolicy }} + # injector注入行为 + SERMANT_AGENT_INJECT_ACTION: {{ .Values.injector.action }} {{- if not (and .Values.configMap.enabled .Values.configMap.namespaces) }} SERMANT_AGENT_CONFIGMAP: "" {{- end }} \ No newline at end of file diff --git a/sermant-injector/deployment/release/injector/values.yaml b/sermant-injector/deployment/release/injector/values.yaml index 91f5feb550..133fc3bfff 100644 --- a/sermant-injector/deployment/release/injector/values.yaml +++ b/sermant-injector/deployment/release/injector/values.yaml @@ -1,8 +1,10 @@ namespace: - # injector部署的namespace(注意: 必须和certificate.sh中的namespace保持一致) + # injector部署的namespace name: default injector: + # 当宿主应用已存在JAVA_TOOL_OPTIONS变量时,injector的注入行为,before为在原变量前注入(默认),after为在原变量后注入,ignore为不注入 + action: before # 实例数 replicas: 2 image: @@ -24,8 +26,11 @@ config: # 配置中心类型: ZOOKEEPER/KIE type: ZOOKEEPER # 配置中心地址 - endpoints: http://localhost:30110 + endpoints: http://localhost:2181 + registry: + # 注册中心类型:SERVICE_COMB/NACOS + type: SERVICE_COMB # 注册中心地址 endpoints: http://localhost:30100 diff --git a/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java b/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java index 407d2e2789..8e51ce1f36 100644 --- a/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java +++ b/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java @@ -210,6 +210,9 @@ public class SermantInjectorController { @Value("${sermant-agent.service.type:SERVICE_COMB}") private String serviceType; + @Value("${sermant-agent.inject.action:before}") + private String action; + /** * 准入控制器接口 * @@ -452,7 +455,12 @@ private void injectEnv(ArrayNode arrayNode, Map env, JsonNode co if (containerNode.hasNonNull(ENV_PATH)) { Iterator elements = containerNode.path(ENV_PATH).elements(); while (elements.hasNext()) { - envArray.add(elements.next()); + JsonNode next = elements.next(); + + // JAVA_TOOL_OPTIONS以injector注入为准 + if (!JVM_OPTIONS_KEY.equals(next.get(NAME_KEY).asText())) { + envArray.add(next); + } } } @@ -460,11 +468,8 @@ private void injectEnv(ArrayNode arrayNode, Map env, JsonNode co String realMountPath = getNotEmptyValue(env, ENV_MOUNT_PATH_KEY, mountPath, value -> value); // jvm启动命令 - String jvmOptions = JVM_OPTIONS_VALUE_PREFIX + realMountPath + JVM_OPTIONS_VALUE_SUFFIX; - String envJvmOptions = env.get(JVM_OPTIONS_KEY); - if (StringUtils.hasText(envJvmOptions)) { - jvmOptions = jvmOptions + envJvmOptions; - } + String jvmOptions = getJavaToolOptions(JVM_OPTIONS_VALUE_PREFIX + realMountPath + JVM_OPTIONS_VALUE_SUFFIX, + env.get(JVM_OPTIONS_KEY)); // 注入jvm启动命令 addEnv(envArray, JVM_OPTIONS_KEY, jvmOptions); @@ -489,6 +494,19 @@ private void injectEnv(ArrayNode arrayNode, Map env, JsonNode co } } + private String getJavaToolOptions(String injectOptions, String originOptions) { + if (!StringUtils.hasText(originOptions)) { + return injectOptions; + } + if ("after".equalsIgnoreCase(action)) { + return originOptions + injectOptions; + } + if ("ignore".equalsIgnoreCase(action)) { + return originOptions; + } + return injectOptions + originOptions; + } + private void injectVolumeMounts(ArrayNode arrayNode, Map env, JsonNode containerNode, String containerPath) { // 向容器新增volumeMounts节点 diff --git a/sermant-injector/src/main/resources/application.yml b/sermant-injector/src/main/resources/application.yml index 983c3585f7..0629fcd796 100644 --- a/sermant-injector/src/main/resources/application.yml +++ b/sermant-injector/src/main/resources/application.yml @@ -34,6 +34,9 @@ sermant-agent: address: http://localhost:30100 # sermant-agent 配置环境变量的configMap的名字 configMap: sermant-agent-env + inject: + # 当宿主应用已存在JAVA_TOOL_OPTIONS变量时,sermant的注入行为,before为在原变量前注入(默认),after为在原变量后注入,ignore为不注入 + action: before management: endpoint: