Skip to content

Commit

Permalink
Merge pull request #744 from oracle/domain-home-fix
Browse files Browse the repository at this point in the history
WIP:  Issue #721 fix.  When domain resource 'domainHome' is not set and 'domainHomeInImage' is 'true' look for a single WebLogic domain under '/u01/oracle/user_projects/domains', and use this as this location as the DOMAIN_HOME.
  • Loading branch information
rjeberhard committed Jan 8, 2019
2 parents 52dd30d + 5b24913 commit ebf39ea
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 31 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The fastest way to experience the operator is to follow the [Quick start guide](

| Issue | Description |
| --- | --- |
| [#721](https://github.com/oracle/weblogic-kubernetes-operator/issues/721) | Incorrect default `domainHome` when `domainHomeInImage` is true. |
| [#722](https://github.com/oracle/weblogic-kubernetes-operator/issues/722) | Server services not recreated when labels/annotations changed. |
| [#726](https://github.com/oracle/weblogic-kubernetes-operator/issues/726) | Clusters only support default channel. |

Expand Down
2 changes: 1 addition & 1 deletion docs/domains/Domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
"type": "string"
},
"domainHome": {
"description": "The folder for the Weblogic Domain. (Not required)Defaults to /shared/domains/domains/domainUID if domainHomeInImage is falseDefaults to /shared/domains/domain if domainHomeInImage is true",
"description": "The folder for the Weblogic Domain. (Not required)Defaults to /shared/domains/domains/domainUID if domainHomeInImage is falseDefaults to /u01/oracle/user_projects/domains/ if domainHomeInImage is true",
"type": "string"
},
"logHomeEnabled": {
Expand Down
2 changes: 1 addition & 1 deletion docs/domains/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@
"type": "string"
},
"domainHome": {
"description": "The folder for the Weblogic Domain. (Not required)Defaults to /shared/domains/domains/domainUID if domainHomeInImage is falseDefaults to /shared/domains/domain if domainHomeInImage is true",
"description": "The folder for the Weblogic Domain. (Not required)Defaults to /shared/domains/domains/domainUID if domainHomeInImage is falseDefaults to /u01/oracle/user_projects/domains/ if domainHomeInImage is true",
"type": "string"
},
"logHomeEnabled": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
// Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
// Licensed under the Universal Permissive License v 1.0 as shown at
// http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -321,13 +321,13 @@ public boolean isDomainHomeInImage() {
/**
* Returns the domain home
*
* <p>Defaults to either /shared/domain/ or /shared/domains/domainUID
* <p>Defaults to either /u01/oracle/user_projects/domains or /shared/domains/domainUID
*
* @return domain home
*/
public String getDomainHome() {
if (spec.getDomainHome() != null) return spec.getDomainHome();
if (spec.isDomainHomeInImage()) return "/shared/domain";
if (spec.isDomainHomeInImage()) return "/u01/oracle/user_projects/domains";
return "/shared/domains/" + getDomainUID();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
// Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
// Licensed under the Universal Permissive License v 1.0 as shown at
// http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -41,7 +41,7 @@ public class DomainSpec extends BaseConfiguration {
@Description(
"The folder for the Weblogic Domain. (Not required)"
+ "Defaults to /shared/domains/domains/domainUID if domainHomeInImage is false"
+ "Defaults to /shared/domains/domain if domainHomeInImage is true")
+ "Defaults to /u01/oracle/user_projects/domains/ if domainHomeInImage is true")
private String domainHome;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
// Licensed under the Universal Permissive License v 1.0 as shown at
// http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -1207,7 +1207,7 @@ public void domainHomeTest_standardHome2() {
public void domainHomeTest_standardHome3() {
configureDomain(domain).withDomainHomeInImage(true);

assertThat(domain.getDomainHome(), equalTo("/shared/domain"));
assertThat(domain.getDomainHome(), equalTo("/u01/oracle/user_projects/domains"));
}

@Test
Expand Down
6 changes: 5 additions & 1 deletion operator/src/main/resources/scripts/introspectDomain.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
# Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.

#
Expand Down Expand Up @@ -74,6 +74,10 @@ for dir_var in DOMAIN_HOME JAVA_HOME WL_HOME MW_HOME; do
[ ! -d "${!dir_var}" ] && trace "Error: missing ${dir_var} directory '${!dir_var}'." && exit 1
done

# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed

exportEffectiveDomainHome || exit 1

# start node manager

trace "Starting node manager"
Expand Down
20 changes: 13 additions & 7 deletions operator/src/main/resources/scripts/livenessProbe.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
#!/bin/bash

# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
# Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.

# Kubernetes periodically calls this liveness probe script to determine whether
# the pod should be restarted. The script checks a WebLogic Server state file which
# is updated by the node manager.

# if the livenessProbeSuccessOverride file is available, treat failures as success:
RETVAL=$(test -f /weblogic-operator/debug/livenessProbeSuccessOverride ; echo $?)

SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
source ${SCRIPTPATH}/traceUtils.sh
[ $? -ne 0 ] && echo "Error: missing file ${SCRIPTPATH}/traceUtils.sh" && exit $RETVAL

# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed:
exportEffectiveDomainHome || exit $RETVAL

DN=${DOMAIN_NAME?}
SN=${SERVER_NAME?}
DH=${DOMAIN_HOME?}

STATEFILE=${DH}/servers/${SN}/data/nodemanager/${SN}.state

# if the livenessProbeSuccessOverride file is available, treat failures as success
#
RETVAL=$(test -f /weblogic-operator/debug/livenessProbeSuccessOverride ; echo $?)

if [ "${MOCK_WLS}" != 'true' ]; then
if [ `jps -l | grep -c " weblogic.NodeManager"` -eq 0 ]; then
echo "Error: WebLogic NodeManager process not found."
trace "Error: WebLogic NodeManager process not found."
exit $RETVAL
fi
fi
if [ -f ${STATEFILE} ] && [ `grep -c "FAILED_NOT_RESTARTABLE" ${STATEFILE}` -eq 1 ]; then
echo "Error: WebLogic Server state is FAILED_NOT_RESTARTABLE."
trace "Error: WebLogic Server state is FAILED_NOT_RESTARTABLE."
exit $RETVAL
fi
exit 0
13 changes: 10 additions & 3 deletions operator/src/main/resources/scripts/readState.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#!/bin/bash

# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
# Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.

# Reads the current state of a server. The script checks a WebLogic Server state
# file which is updated by the node manager.

SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
source ${SCRIPTPATH}/traceUtils.sh
[ $? -ne 0 ] && echo "Error: missing file ${SCRIPTPATH}/traceUtils.sh" && exit 1

# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed:
exportEffectiveDomainHome || exit 1

DN=${DOMAIN_NAME?}
SN=${SERVER_NAME?}
DH=${DOMAIN_HOME?}

STATEFILE=/${DH}/servers/${SN}/data/nodemanager/${SN}.state

if [ `jps -l | grep -c " weblogic.NodeManager"` -eq 0 ]; then
echo "Error: WebLogic NodeManager process not found."
trace "Error: WebLogic NodeManager process not found."
exit 1
fi

if [ ! -f ${STATEFILE} ]; then
echo "Error: WebLogic Server state file not found."
trace "Error: WebLogic Server state file not found."
exit 2
fi

Expand Down
7 changes: 6 additions & 1 deletion operator/src/main/resources/scripts/startServer.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
# Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -174,6 +174,11 @@ trace "SERVER_OUT_IN_POD_LOG=${SERVER_OUT_IN_POD_LOG}"
trace "USER_MEM_ARGS=${USER_MEM_ARGS}"
trace "JAVA_OPTIONS=${JAVA_OPTIONS}"

#
# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed:
#
exportEffectiveDomainHome || exitOrLoop

#
# Check if introspector actually ran. This should never fail since
# the operator shouldn't try run a wl pod if the introspector failed.
Expand Down
63 changes: 62 additions & 1 deletion operator/src/main/resources/scripts/traceUtils.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
# Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.

#
Expand Down Expand Up @@ -103,3 +103,64 @@ function checkEnv() {
fi
return 0
}


#
# exportEffectiveDomainHome
# if DOMAIN_HOME='/u01/oracle/user_projects/domains':
# 1) look for a config.xml in DOMAIN_HOME/config and
# and in DOMAIN_HOME/*/config
# 2) Export DOMAIN_HOME to reflect the actual location
# 3) Trace an Error and return non-zero if not found or more than 1 found
#
function exportEffectiveDomainHome() {
local count=0
local cur_domain_home=""
local eff_domain_home=""
local found_configs=""

if [ ! "${DOMAIN_HOME?}" = "/u01/oracle/user_projects/domains" ]; then
# nothing to do
return 0
fi

local tfile=$(mktemp /tmp/homes.`basename $0`.XXXXXXXXX)
rm -f $tfile
ls -d ${DOMAIN_HOME} ${DOMAIN_HOME}/* > $tfile
exec 22<> $tfile

while read -u 22 cur_domain_home; do

config_path="${cur_domain_home}/config/config.xml"

if [ ! -f "${config_path}" ]; then
continue
fi

count=$((count + 1))

if [ $count -eq 1 ]; then
eff_domain_home="${cur_domain_home}"
found_configs="'${config_path}'"
else
found_configs="${found_configs}, '${config_path}'"
fi

done

rm -f $tfile

if [ $count -eq 1 ]; then
export DOMAIN_HOME="${eff_domain_home}"
return 0
fi

if [ $count -eq 0 ]; then
trace "Error: No config.xml found at DOMAIN_HOME/config/config.xml or DOMAIN_HOME/*/config/config.xml, DOMAIN_HOME='$DOMAIN_HOME'. Check your 'domainHome' setting in your WebLogic Operator Domain resource, and your pv/pvc mount location (if any)."
return 1
fi

# if we get this far, count is > 1
trace "Error: More than one config.xml found at DOMAIN_HOME/config/config.xml and DOMAIN_HOME/*/config/config.xml, DOMAIN_HOME='$DOMAIN_HOME': ${found_configs}. Configure your 'domainHome' setting in your WebLogic Operator Domain resource to reference a single WebLogic domain."
return 1
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
// Licensed under the Universal Permissive License v 1.0 as shown at
// http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -309,7 +309,7 @@ public void whenDomainHasEnvironmentItemsWithVariables_createAdminPodStartupWith
assertThat(
getCreatedPodSpecContainer().getEnv(),
allOf(
hasEnvVar("item1", "find uid1 at /shared/domain"),
hasEnvVar("item1", "find uid1 at /u01/oracle/user_projects/domains"),
hasEnvVar("item2", "ADMIN_SERVER is ADMIN_SERVER:7001")));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
// Licensed under the Universal Permissive License v 1.0 as shown at
// http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -33,7 +33,7 @@ public class ManagedPodHelperTest extends PodHelperTestBase {
private static final String VALUE1 = "value1";
private static final String VALUE2 = "value2";
private static final String RAW_VALUE_1 = "find uid1 at $(DOMAIN_HOME)";
private static final String END_VALUE_1 = "find uid1 at /shared/domain";
private static final String END_VALUE_1 = "find uid1 at /u01/oracle/user_projects/domains";
private static final String RAW_VALUE_2 = "$(SERVER_NAME) is not $(ADMIN_NAME):$(ADMIN_PORT)";
private static final String END_VALUE_2 = "ms1 is not ADMIN_SERVER:7001";
private static final String CLUSTER_NAME = "test-cluster";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
// Licensed under the Universal Permissive License v 1.0 as shown at
// http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -317,7 +317,7 @@ public void whenPodCreated_hasPredefinedEnvVariables() {
getCreatedPodSpecContainer().getEnv(),
allOf(
hasEnvVar("DOMAIN_NAME", DOMAIN_NAME),
hasEnvVar("DOMAIN_HOME", "/shared/domain"),
hasEnvVar("DOMAIN_HOME", "/u01/oracle/user_projects/domains"),
hasEnvVar("ADMIN_NAME", ADMIN_SERVER),
hasEnvVar("ADMIN_PORT", Integer.toString(ADMIN_PORT)),
hasEnvVar("SERVER_NAME", getServerName()),
Expand Down Expand Up @@ -594,7 +594,7 @@ V1ObjectMeta createPodMetadata() {
.putLabelsItem(RESOURCE_VERSION_LABEL, VersionConstants.DEFAULT_DOMAIN_VERSION)
.putLabelsItem(LabelConstants.DOMAINUID_LABEL, UID)
.putLabelsItem(LabelConstants.DOMAINNAME_LABEL, DOMAIN_NAME)
.putLabelsItem(LabelConstants.DOMAINHOME_LABEL, "/shared/domain")
.putLabelsItem(LabelConstants.DOMAINHOME_LABEL, "/u01/oracle/user_projects/domains")
.putLabelsItem(LabelConstants.SERVERNAME_LABEL, getServerName())
.putLabelsItem(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
AnnotationHelper.annotateForPrometheus(meta, listenPort);
Expand All @@ -612,7 +612,7 @@ V1Container createPodSpecContainer() {
.volumeMounts(PodDefaults.getStandardVolumeMounts(UID))
.command(createStartCommand())
.addEnvItem(envItem("DOMAIN_NAME", DOMAIN_NAME))
.addEnvItem(envItem("DOMAIN_HOME", "/shared/domain"))
.addEnvItem(envItem("DOMAIN_HOME", "/u01/oracle/user_projects/domains"))
.addEnvItem(envItem("ADMIN_NAME", ADMIN_SERVER))
.addEnvItem(envItem("ADMIN_PORT", Integer.toString(ADMIN_PORT)))
.addEnvItem(envItem("SERVER_NAME", getServerName()))
Expand Down

0 comments on commit ebf39ea

Please sign in to comment.