Skip to content

Commit

Permalink
*修复injector挂载sermant会跟skywalking产生冲突的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
provenceee committed Jul 26, 2023
1 parent 3e4f10e commit 2e3c453
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
9 changes: 7 additions & 2 deletions sermant-injector/deployment/release/injector/values.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* 准入控制器接口
*
Expand Down Expand Up @@ -452,19 +455,21 @@ private void injectEnv(ArrayNode arrayNode, Map<String, String> env, JsonNode co
if (containerNode.hasNonNull(ENV_PATH)) {
Iterator<JsonNode> 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);
}
}
}

// agent磁盘路径
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));

Check failure on line 472 in sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 'env' has incorrect indentation level 12, expected level should be 16. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java:472:13: error: 'env' has incorrect indentation level 12, expected level should be 16. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)

// 注入jvm启动命令
addEnv(envArray, JVM_OPTIONS_KEY, jvmOptions);
Expand All @@ -489,6 +494,19 @@ private void injectEnv(ArrayNode arrayNode, Map<String, String> 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<String, String> env, JsonNode containerNode,
String containerPath) {
// 向容器新增volumeMounts节点
Expand Down
3 changes: 3 additions & 0 deletions sermant-injector/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2e3c453

Please sign in to comment.