diff --git a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go index e1cf6283..91823f29 100644 --- a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go +++ b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go @@ -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 ( @@ -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, diff --git a/pkg/inject/pkg/kube/inject/inject.go b/pkg/inject/pkg/kube/inject/inject.go index 220c68b0..b8894172 100644 --- a/pkg/inject/pkg/kube/inject/inject.go +++ b/pkg/inject/pkg/kube/inject/inject.go @@ -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 {