Skip to content

Commit dfca030

Browse files
committed
Merge branch 'add-podname-to-wmesidecar' into 'main'
passing pod name to the system property of wme side car, so that it can display the instance name in metrics See merge request weblogic-cloud/weblogic-kubernetes-operator!5052
2 parents 40e98bf + 1f6edc1 commit dfca030

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,34 @@ private void restoreMetricsExporterSidecarJavaOpts(V1Pod recipe, V1Pod currentPo
12751275
stream(podSpec.getContainers()).filter(c -> "monitoring-exporter".equals(c.getName()))
12761276
.findFirst().flatMap(c -> stream(c.getEnv()).filter(p -> "JDK_JAVA_OPTIONS".equals(p.getName()))
12771277
.findFirst()).ifPresent(p -> p.setName("JAVA_OPTS"));
1278+
1279+
}
1280+
1281+
private void removePodNameJavaOpt(V1Pod recipe, V1Pod currentPod) {
1282+
V1PodSpec podSpec = recipe.getSpec();
1283+
1284+
stream(podSpec.getContainers())
1285+
.filter(c -> "monitoring-exporter".equals(c.getName()))
1286+
.findFirst()
1287+
.ifPresent(container -> {
1288+
1289+
// find the JDK_JAVA_OPTIONS env var
1290+
stream(container.getEnv())
1291+
.filter(env -> "JDK_JAVA_OPTIONS".equals(env.getName()))
1292+
.findFirst()
1293+
.ifPresent(envVar -> {
1294+
String original = envVar.getValue();
1295+
if (original == null) {
1296+
return;
1297+
}
1298+
1299+
// remove `-DPOD_NAME=<whatever>` (and surrounding spaces)
1300+
String cleaned = original.replaceAll("\\s*-DPOD_NAME=\\S+", "")
1301+
.trim()
1302+
.replaceAll(" +", " "); // collapse double spaces
1303+
envVar.setValue(cleaned);
1304+
});
1305+
});
12781306
}
12791307

12801308
private void restoreLegacyIstioPortsConfig(V1Pod recipePod, V1Pod currentPod) {
@@ -1423,6 +1451,7 @@ private boolean canAdjustRecentOperatorMajorVersion3HashToMatch(V1Pod currentPod
14231451
// return true if any adjusted hash matches required hash
14241452
List<Pair<String, BiConsumer<V1Pod, V1Pod>>> adjustments = List.of(
14251453
Pair.of("restoreMetricsExporterSidecarPortTcpMetrics", this::restoreMetricsExporterSidecarPortTcpMetrics),
1454+
Pair.of("removePodNameJavaOpt", this::removePodNameJavaOpt),
14261455
Pair.of("restoreMetricsExporterSidecarJavaOpts", this::restoreMetricsExporterSidecarJavaOpts),
14271456
Pair.of("convertAuxImagesInitContainerVolumeAndMounts",
14281457
this::convertAuxImagesInitContainerVolumeAndMounts),
@@ -1685,6 +1714,7 @@ private String createJavaOptions() {
16851714
final List<String> args = new ArrayList<>();
16861715
args.add("-DDOMAIN=" + getDomainUid());
16871716
args.add("-DWLS_PORT=" + getWebLogicRestPort());
1717+
args.add("-DPOD_NAME=" + getPodName());
16881718
if (isWebLogicSecure()) {
16891719
args.add("-DWLS_SECURE=true");
16901720
}

0 commit comments

Comments
 (0)