Skip to content

Commit

Permalink
Normalized formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvenga committed Nov 14, 2022
1 parent 55a3fe9 commit a0dfef9
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ public void PatchContainer(V1Container container, PatchingContext context)
&& GetFirstOrDefaultEnvVar(container.Env, "CONTRAST_EXISTING_JAVA_TOOL_OPTIONS") is null)
{
var contrastAgentArgument = GetContrastAgentArgument(context);

//Parse and patch the existing JAVA_TOOL_OPTIONS
container.Env.AddOrUpdate(new V1EnvVar("CONTRAST_EXISTING_JAVA_TOOL_OPTIONS", currentJavaToolOptions));

try
{
var options = JavaArgumentParser.ParseArguments(currentJavaToolOptions).ToList();

//Patch contrast-agent.jar to the correct path
var contrastJavaAgentIndex = options.FindIndex(x => x.StartsWith("-javaagent", StringComparison.OrdinalIgnoreCase) && x.Contains("contrast-agent.jar", StringComparison.OrdinalIgnoreCase));
var contrastJavaAgentIndex = options.FindIndex(x => x.StartsWith("-javaagent", StringComparison.OrdinalIgnoreCase)
&& x.Contains("contrast-agent.jar", StringComparison.OrdinalIgnoreCase));
if (contrastJavaAgentIndex >= 0)
{
options[contrastJavaAgentIndex] = contrastAgentArgument;
Expand All @@ -45,11 +49,12 @@ public void PatchContainer(V1Container container, PatchingContext context)
{
options.Insert(0, contrastAgentArgument);
}

container.Env.AddOrUpdate(new V1EnvVar("JAVA_TOOL_OPTIONS", string.Join(' ', options)));
}
catch (Exception e)
{
Logger.Warn(e, $"Failed to parse existing JAVA_TOOL_OPTIONS, unable to patch!");
Logger.Warn(e, "Failed to parse existing JAVA_TOOL_OPTIONS, unable to patch!");
}
}
}
Expand All @@ -59,9 +64,8 @@ public void PatchContainer(V1Container container, PatchingContext context)
return collection.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));
}

private string GetContrastAgentArgument(PatchingContext context) => $"-javaagent:{context.ContrastMountPath}/contrast-agent.jar";
private static string GetContrastAgentArgument(PatchingContext context) => $"-javaagent:{context.ContrastMountPath}/contrast-agent.jar";

public string GetMountPath() => "/opt/contrast";

}
}

0 comments on commit a0dfef9

Please sign in to comment.