Skip to content

Commit 68df750

Browse files
committed
Allow a server Pod env to refer to envs that are established internally
Signed-off-by: doxiao <[email protected]>
1 parent a060ae5 commit 68df750

File tree

1 file changed

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

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,18 @@ protected V1Pod computeManagedPodConfig(TuningParameters configMapHelper, Packet
745745
// Override the weblogic domain and admin server related environment variables that
746746
// come for free with the WLS docker container with the correct values.
747747
private static void overrideContainerWeblogicEnvVars(DomainSpec spec, String serverName, V1Container container) {
748+
// get the EnvVar that are externally specified
749+
List<V1EnvVar> envList = container.getEnv();
750+
String domainName = spec.getDomainName();
751+
String domainHome = "/shared/domain/" + domainName;
752+
String asName = spec.getAsName();
753+
String asPort = spec.getAsPort().toString();
754+
748755
// Override the domain name, domain directory, admin server name and admin server port.
749-
addEnvVar(container, "DOMAIN_NAME", spec.getDomainName());
750-
addEnvVar(container, "DOMAIN_HOME", "/shared/domain/" + spec.getDomainName());
751-
addEnvVar(container, "ADMIN_NAME", spec.getAsName());
752-
addEnvVar(container, "ADMIN_PORT", spec.getAsPort().toString());
756+
addEnvVar(container, "DOMAIN_NAME", domainName);
757+
addEnvVar(container, "DOMAIN_HOME", domainHome);
758+
addEnvVar(container, "ADMIN_NAME", asName);
759+
addEnvVar(container, "ADMIN_PORT", asPort);
753760
addEnvVar(container, "SERVER_NAME", serverName);
754761
// Hide the admin account's user name and password.
755762
// Note: need to use null v.s. "" since if you upload a "" to kubectl then download it,
@@ -760,6 +767,19 @@ private static void overrideContainerWeblogicEnvVars(DomainSpec spec, String ser
760767
// the default, e.g. 'weblogic' for the user name).
761768
addEnvVar(container, "ADMIN_USERNAME", null);
762769
addEnvVar(container, "ADMIN_PASSWORD", null);
770+
771+
// resolve tokens in externally specified env that refers to internal env via $(XXX)
772+
for (V1EnvVar ev : envList) {
773+
String oldValue = ev.getValue();
774+
if (oldValue == null) continue;
775+
String newValue = oldValue.replace("$(DOMAIN_NAME)", domainName);
776+
newValue = newValue.replace("$(DOMAIN_HOME)", domainHome);
777+
newValue = newValue.replace("$(ADMIN_NAME)", asName);
778+
newValue = newValue.replace("$(ADMIN_PORT)", asPort);
779+
newValue = newValue.replace("$(SERVER_NAME)", serverName);
780+
if (!(oldValue.equals(newValue))) ev.setValue(newValue);
781+
}
782+
763783
}
764784

765785
// Add an environment variable to a container

0 commit comments

Comments
 (0)