Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复injector挂载sermant会跟skywalking产生冲突的问题 #1261

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));

// 注入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