Skip to content

Commit b1762f1

Browse files
doxiaorussgold
authored andcommitted
Allow a server Pod env to refer to envs that are established internally
Signed-off-by: doxiao <[email protected]>
1 parent b1ba8bc commit b1762f1

File tree

1 file changed

+23
-4
lines changed
  • operator/src/main/java/oracle/kubernetes/operator/helpers

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,11 +877,18 @@ protected V1Pod computeManagedPodConfig(TuningParameters configMapHelper, Packet
877877
// come for free with the WLS docker container with the correct values.
878878
private static void overrideContainerWeblogicEnvVars(
879879
DomainSpec spec, String serverName, V1Container container) {
880+
// get the EnvVar that are externally specified
881+
List<V1EnvVar> envList = container.getEnv();
882+
String domainName = spec.getDomainName();
883+
String domainHome = "/shared/domain/" + domainName;
884+
String asName = spec.getAsName();
885+
String asPort = spec.getAsPort().toString();
886+
880887
// Override the domain name, domain directory, admin server name and admin server port.
881-
addEnvVar(container, "DOMAIN_NAME", spec.getDomainName());
882-
addEnvVar(container, "DOMAIN_HOME", "/shared/domain/" + spec.getDomainName());
883-
addEnvVar(container, "ADMIN_NAME", spec.getAsName());
884-
addEnvVar(container, "ADMIN_PORT", spec.getAsPort().toString());
888+
addEnvVar(container, "DOMAIN_NAME", domainName);
889+
addEnvVar(container, "DOMAIN_HOME", domainHome);
890+
addEnvVar(container, "ADMIN_NAME", asName);
891+
addEnvVar(container, "ADMIN_PORT", asPort);
885892
addEnvVar(container, "SERVER_NAME", serverName);
886893
// Hide the admin account's user name and password.
887894
// Note: need to use null v.s. "" since if you upload a "" to kubectl then download it,
@@ -892,6 +899,18 @@ private static void overrideContainerWeblogicEnvVars(
892899
// the default, e.g. 'weblogic' for the user name).
893900
addEnvVar(container, "ADMIN_USERNAME", null);
894901
addEnvVar(container, "ADMIN_PASSWORD", null);
902+
903+
// resolve tokens in externally specified env that refers to internal env via $(XXX)
904+
for (V1EnvVar ev : envList) {
905+
String oldValue = ev.getValue();
906+
if (oldValue == null) continue;
907+
String newValue = oldValue.replace("$(DOMAIN_NAME)", domainName);
908+
newValue = newValue.replace("$(DOMAIN_HOME)", domainHome);
909+
newValue = newValue.replace("$(ADMIN_NAME)", asName);
910+
newValue = newValue.replace("$(ADMIN_PORT)", asPort);
911+
newValue = newValue.replace("$(SERVER_NAME)", serverName);
912+
if (!(oldValue.equals(newValue))) ev.setValue(newValue);
913+
}
895914
}
896915

897916
// Add an environment variable to a container

0 commit comments

Comments
 (0)