@@ -43,6 +43,7 @@ const (
4343)
4444
4545var oldAgentVersions = map [string ]struct {}{
46+ "1.7.0-RC5" : {},
4647 "1.7.0-RC4" : {},
4748 "1.7.0-RC3" : {},
4849 "1.7.0-RC2" : {},
@@ -52,7 +53,8 @@ var oldAgentVersions = map[string]struct{}{
5253}
5354
5455const (
55- ActiveJavaAgentCmd = "-javaagent:/app/lib/.polaris/java_agent/polaris-java-agent-%s/polaris-agent-core-bootstrap.jar"
56+ ActiveJavaAgentCmd = "-javaagent:/app/lib/.polaris/java_agent/polaris-java-agent/polaris-agent-core-bootstrap.jar"
57+ OldActiveJavaAgentCmd = "-javaagent:/app/lib/.polaris/java_agent/polaris-java-agent-%s/polaris-agent-core-bootstrap.jar"
5658)
5759
5860func init () {
@@ -154,7 +156,7 @@ func (pb *PodPatchBuilder) handleJavaAgentInit(opt *inject.PatchOptions, pod *co
154156 Value : defaultParam ["PolarisDiscoverPort" ],
155157 },
156158 corev1.EnvVar {
157- Name : "POLARIS_CONFIG_PORT " ,
159+ Name : "POLARIS_CONFIG_IP " ,
158160 Value : defaultParam ["PolarisConfigIP" ],
159161 },
160162 corev1.EnvVar {
@@ -192,45 +194,78 @@ func (pb *PodPatchBuilder) handleJavaAgentInit(opt *inject.PatchOptions, pod *co
192194 }
193195 }
194196 }
195- }
196-
197- // 查看用户是否自定义了相关配置信息
198- // 需要根据用户的自定义参数信息,将 agent 的特定 application.properties 文件注入到 javaagent-init 中
199- if properties , ok := annonations [customJavaAgentPluginConfig ]; ok {
200- customProperties := map [string ]string {}
201- if err := json .Unmarshal ([]byte (properties ), & customProperties ); err != nil {
202- return err
197+ // 查看用户是否自定义了相关配置信息
198+ // 需要根据用户的自定义参数信息,将 agent 的特定 application.properties 文件注入到 javaagent-init 中
199+ if properties , ok := annonations [customJavaAgentPluginConfig ]; ok {
200+ customProperties := map [string ]string {}
201+ if err := json .Unmarshal ([]byte (properties ), & customProperties ); err != nil {
202+ return err
203+ }
204+ // 先从 configmap 中获取 java-agent 不同 plugin-type 的默认配置信息
205+ for k , v := range customProperties {
206+ defaultProperties [k ] = v
207+ }
203208 }
204- // 先从 configmap 中获取 java-agent 不同 plugin-type 的默认配置信息
205- for k , v := range customProperties {
206- defaultProperties [k ] = v
209+
210+ exportAgentPluginConf := ""
211+ for key , value := range defaultProperties {
212+ exportAgentPluginConf += fmt .Sprintf ("%s=%s\n " , key , value )
207213 }
208- }
209214
210- exportAgentPluginConf := ""
211- for key , value := range defaultProperties {
212- exportAgentPluginConf += fmt .Sprintf ("%s=%s\n " , key , value )
215+ add .Env = append (add .Env , corev1.EnvVar {
216+ Name : "JAVA_AGENT_PLUGIN_CONF" ,
217+ Value : exportAgentPluginConf ,
218+ })
213219 }
214-
215- add .Env = append (add .Env , corev1.EnvVar {
216- Name : "JAVA_AGENT_PLUGIN_CONF" ,
217- Value : exportAgentPluginConf ,
218- })
219220 return nil
220221}
221222
222223func nameOfPluginDefault (v string ) string {
223224 return v + "-default-properties"
224225}
225226
227+ func updateJavaEnvVar (envVar corev1.EnvVar , cmd string , version string ) corev1.EnvVar {
228+ return corev1.EnvVar {
229+ Name : "JAVA_TOOL_OPTIONS" ,
230+ Value : envVar .Value + " " + cmd + version ,
231+ }
232+ }
233+
226234func (pb * PodPatchBuilder ) updateContainer (opt * inject.PatchOptions , sidecarMode utils.SidecarMode , pod * corev1.Pod ,
227235 target []corev1.Container , basePath string ) []inject.Rfc6902PatchOperation {
228236
229237 patchs := make ([]inject.Rfc6902PatchOperation , 0 , len (target ))
230238
239+ annonations := pod .Annotations
240+ if val , ok := annonations [customJavaAgentVersion ]; ok && val != "" {
241+ opt .ExternalInfo [customJavaAgentVersion ] = val
242+ } else {
243+ annonations [customJavaAgentVersion ] = "latest"
244+ }
245+
246+ defaultProperties := make (map [string ]string )
247+ var javaToolOptionsValue string
248+
231249 for index , container := range target {
232250 envs := container .Env
233251 javaEnvIndex := - 1
252+ if _ , valid := oldAgentVersions [annonations [customJavaAgentVersion ]]; ! valid {
253+ if properties , ok := annonations [customJavaAgentPluginConfig ]; ok {
254+ customProperties := map [string ]string {}
255+ if properties != "" {
256+ json .Unmarshal ([]byte (properties ), & customProperties )
257+ }
258+ // 先从 configmap 中获取 java-agent 不同 plugin-type 的默认配置信息
259+ for k , v := range customProperties {
260+ defaultProperties [k ] = v
261+ }
262+ }
263+ }
264+
265+ for key , value := range defaultProperties {
266+ javaToolOptionsValue += fmt .Sprintf (" -D%s=%s" , key , value )
267+ }
268+
234269 if len (envs ) != 0 {
235270 for i := range envs {
236271 if envs [i ].Name == "JAVA_TOOL_OPTIONS" {
@@ -239,19 +274,22 @@ func (pb *PodPatchBuilder) updateContainer(opt *inject.PatchOptions, sidecarMode
239274 }
240275 }
241276 if javaEnvIndex != - 1 {
242- oldVal := envs [ javaEnvIndex ]. Value
243- envs [javaEnvIndex ] = corev1. EnvVar {
244- Name : "JAVA_TOOL_OPTIONS" ,
245- Value : oldVal + " " + fmt .Sprintf (ActiveJavaAgentCmd , opt .ExternalInfo [customJavaAgentVersion ]),
277+ if _ , valid := oldAgentVersions [ annonations [ customJavaAgentVersion ]]; ! valid {
278+ envs [javaEnvIndex ] = updateJavaEnvVar ( envs [ javaEnvIndex ], ActiveJavaAgentCmd , javaToolOptionsValue )
279+ } else {
280+ envs [ javaEnvIndex ] = updateJavaEnvVar ( envs [ javaEnvIndex ], fmt .Sprintf (OldActiveJavaAgentCmd , opt .ExternalInfo [customJavaAgentVersion ]), "" )
246281 }
247282 }
248283 }
249284 if javaEnvIndex == - 1 {
250285 // 注入 java agent 需要用到的参数信息
251- container .Env = append (container .Env , corev1.EnvVar {
252- Name : "JAVA_TOOL_OPTIONS" ,
253- Value : fmt .Sprintf (ActiveJavaAgentCmd , opt .ExternalInfo [customJavaAgentVersion ]),
254- })
286+ var newEnvVar corev1.EnvVar
287+ if _ , valid := oldAgentVersions [annonations [customJavaAgentVersion ]]; ! valid {
288+ newEnvVar = updateJavaEnvVar (corev1.EnvVar {}, ActiveJavaAgentCmd , javaToolOptionsValue )
289+ } else {
290+ newEnvVar = updateJavaEnvVar (corev1.EnvVar {}, fmt .Sprintf (OldActiveJavaAgentCmd , opt .ExternalInfo [customJavaAgentVersion ]), "" )
291+ }
292+ container .Env = append (container .Env , newEnvVar )
255293 }
256294
257295 // container 需要新挂载磁盘
0 commit comments