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 fcc9a8d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/Codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ jobs:
sh apache-servicecomb-service-center-2.1.0-linux-amd64/start-service-center.sh
- name: download zookeeper
run: |
curl -o apache-zookeeper-3.8.0-bin.tar.gz -L https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
tar -zxf apache-zookeeper-3.8.0-bin.tar.gz
bash apache-zookeeper-3.8.0-bin/bin/zkServer.sh start apache-zookeeper-3.8.0-bin/conf/zoo_sample.cfg
curl -o apache-zookeeper-3.6.3-bin.tar.gz -L https://archive.apache.org/dist/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
tar -zxf apache-zookeeper-3.6.3-bin.tar.gz
bash apache-zookeeper-3.6.3-bin/bin/zkServer.sh start apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg
- name: Build with Maven
run: mvn test
- name: Generate code coverage report
Expand Down
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

0 comments on commit fcc9a8d

Please sign in to comment.