Skip to content

Commit

Permalink
fix:修复java-agent注入时plugin.enable格式不对 (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Jan 31, 2024
1 parent 6c44f4b commit c477979
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/inject/pkg/kube/inject/apply/javaagent/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import (

// Java Agent 场景下的特殊 annonations 信息
const (
customJavaAgentVersion = "sidecar.polarismesh.cn/java-agent-version"
customJavaAgentPluginType = "sidecar.polarismesh.cn/java-agent-plugin-type"
customJavaAgentPluginConfig = "sidecar.polarismesh.cn/java-agent-plugin-config"
customJavaAgentVersion = "polarismesh.cn/java-agent/version"
customJavaAgentPluginFramework = "polarismesh.cn/java-agent/framework-name"
customJavaAgentPluginFrameworkVersion = "polarismesh.cn/java-agent/framework-version"
customJavaAgentPluginConfig = "polarismesh.cn/java-agent/config"
)

const (
Expand Down Expand Up @@ -92,11 +93,20 @@ func (pb *PodPatchBuilder) handleJavaAgentInit(opt *inject.PatchOptions, pod *co
}

// 需要将用户的框架信息注入到 javaagent-init 中,用于初始化相关的配置文件信息
pluginType, ok := annonations[customJavaAgentPluginType]
frameworkName, ok := annonations[customJavaAgentPluginFramework]
if !ok {
log.InjectScope().Warnf("handle polaris-javaagent-init inject for pod=[%s, %s] not found plugin type",
log.InjectScope().Warnf("handle polaris-javaagent-init inject for pod=[%s, %s] not found frameworkName",
pod.Namespace, pod.Name)
return fmt.Errorf("pod annonations not set %s", customJavaAgentPluginFramework)
}
frameworkVersion, ok := annonations[customJavaAgentPluginFrameworkVersion]
if !ok {
log.InjectScope().Warnf("handle polaris-javaagent-init inject for pod=[%s, %s] not found frameworkVersion",
pod.Namespace, pod.Name)
return fmt.Errorf("pod annonations not set %s", customJavaAgentPluginFrameworkVersion)
}

pluginType := frameworkName + frameworkVersion
add.Env = append(add.Env, corev1.EnvVar{
Name: "JAVA_AGENT_PLUGIN_TYPE",
Value: "plugins.enable=" + pluginType,
Expand Down
3 changes: 3 additions & 0 deletions pkg/inject/pkg/kube/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ func validateBool(value string) error {
// getSidecarMode 获取 sidecar 注入模式
func (wh *Webhook) getSidecarMode(namespace string, pod *corev1.Pod) utils.SidecarMode {
// 这里主要是处理北极星 sidecar, 优先级: pod.annotations > namespace.labels > configmap
if val, ok := pod.Annotations["polarismesh.cn/java-agent"]; ok && val == "true" {
return utils.SidecarForJavaAgent
}
sidecarMode := ""
// 1. pod.annotations
if val, ok := pod.Annotations[utils.PolarisSidecarMode]; ok {
Expand Down

0 comments on commit c477979

Please sign in to comment.