Skip to content

Commit ff07d32

Browse files
committed
update the domain home in image sample to keep server logs on PV
1 parent 974bfc8 commit ff07d32

File tree

8 files changed

+145
-204
lines changed

8 files changed

+145
-204
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
# The WebLogic Domain Home
1717
domainHome: %DOMAIN_HOME%
1818
# If the domain home is in the image
19-
domainHomeInImage: false
19+
domainHomeInImage: %DOMAIN_HOME_IN_IMAGE%
2020
# The Operator currently does not support other images
2121
image: "%WEBLOGIC_IMAGE%"
2222
# imagePullPolicy defaults to "Always" if image version is :latest

kubernetes/samples/scripts/common/utility.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,102 @@ function getKubernetesClusterIP {
212212
K8S_IP="${array[1]}"
213213
}
214214

215+
#
216+
# Function to initialize the input parameters.
217+
# For some parameters, use the default value if not defined.
218+
#
219+
function initializeInput {
220+
domainName=${domainUID}
221+
222+
enabledPrefix="" # uncomment the feature
223+
disabledPrefix="# " # comment out the feature
224+
225+
if [ "${exposeAdminT3Channel}" = true ]; then
226+
exposeAdminT3ChannelPrefix="${enabledPrefix}"
227+
else
228+
exposeAdminT3ChannelPrefix="${disabledPrefix}"
229+
fi
230+
231+
if [ "${exposeAdminNodePort}" = true ]; then
232+
exposeAdminNodePortPrefix="${enabledPrefix}"
233+
else
234+
exposeAdminNodePortPrefix="${disabledPrefix}"
235+
fi
236+
237+
if [ -z "${domainPVMountPath}" ]; then
238+
domainPVMountPath="/shared"
239+
fi
240+
241+
if [ -z "${logHome}" ]; then
242+
logHome="${domainPVMountPath}/logs/${domainUID}"
243+
fi
244+
245+
if [ -z "${persistentVolumeClaimName}" ]; then
246+
persistentVolumeClaimName="${domainUID}-weblogic-sample-pvc"
247+
fi
248+
249+
if [ -z "${weblogicCredentialsSecretName}" ]; then
250+
weblogicCredentialsSecretName="${domainUID}-weblogic-credentials"
251+
fi
252+
}
253+
254+
#
255+
# Function to generate the yaml file for creating the domain resource
256+
# $1 - domain home in image
257+
#
258+
function generateDomainYaml {
259+
if [ "$#" != 1 ]; then
260+
fail "The function must be called with domainHomeInImage parameter."
261+
fi
262+
263+
domainHomeInImage="${1}"
264+
if [ "true" != "${domainHomeInImage}" ] && [ "false" != "${domainHomeInImage}" ]; then
265+
fail "The value of domainHomeInImage must be true or false: ${domainHomeInImage}"
266+
fi
267+
268+
echo Generating ${dcrOutput}
269+
270+
cp ${dcrInput} ${dcrOutput}
271+
sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${dcrOutput}
272+
sed -i -e "s:%NAMESPACE%:$namespace:g" ${dcrOutput}
273+
sed -i -e "s:%DOMAIN_HOME%:${domainHome}:g" ${dcrOutput}
274+
sed -i -e "s:%DOMAIN_HOME_IN_IMAGE%:${domainHomeInImage}:g" ${dcrOutput}
275+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_POLICY%:${imagePullPolicy}:g" ${dcrOutput}
276+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
277+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${dcrOutput}
278+
sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${dcrOutput}
279+
sed -i -e "s:%INCLUDE_SERVER_OUT_IN_POD_LOG%:${includeServerOutInPodLog}:g" ${dcrOutput}
280+
sed -i -e "s:%LOG_HOME%:${logHome}:g" ${dcrOutput}
281+
sed -i -e "s:%SERVER_START_POLICY%:${serverStartPolicy}:g" ${dcrOutput}
282+
sed -i -e "s:%JAVA_OPTIONS%:${javaOptions}:g" ${dcrOutput}
283+
sed -i -e "s:%DOMAIN_PVC_NAME%:${persistentVolumeClaimName}:g" ${dcrOutput}
284+
sed -i -e "s:%DOMAIN_ROOT_DIR%:${domainPVMountPath}:g" ${dcrOutput}
285+
sed -i -e "s:%EXPOSE_ADMIN_PORT_PREFIX%:${exposeAdminNodePortPrefix}:g" ${dcrOutput}
286+
sed -i -e "s:%ADMIN_NODE_PORT%:${adminNodePort}:g" ${dcrOutput}
287+
sed -i -e "s:%EXPOSE_T3_CHANNEL_PREFIX%:${exposeAdminT3ChannelPrefix}:g" ${dcrOutput}
288+
sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${dcrOutput}
289+
sed -i -e "s:%INITIAL_MANAGED_SERVER_REPLICAS%:${initialManagedServerReplicas}:g" ${dcrOutput}
290+
291+
if [ "${domainHomeInImage}" == "true" ]; then
292+
if [ -z $domainHomeImageBuildPath ]; then
293+
domainHomeImageBuildPath="./docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt"
294+
fi
295+
imageName="`basename ${domainHomeImageBuildPath} | sed 's/^[0-9]*-//'`"
296+
297+
# now we know which image to use, update the domain yaml file
298+
if [ -z $image ]; then
299+
sed -i -e "s|%WEBLOGIC_IMAGE%|${imageName}|g" ${dcrOutput}
300+
else
301+
sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${dcrOutput}
302+
fi
303+
else
304+
sed -i -e "s:%WEBLOGIC_IMAGE%:${image}:g" ${dcrOutput}
305+
fi
306+
307+
# Remove any "...yaml-e" files left over from running sed
308+
rm -f ${domainOutputDir}/*.yaml-e
309+
}
310+
215311
#
216312
# Function to create the domain recource
217313
#

kubernetes/samples/scripts/common/validate.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,15 @@ function validateCommonInputs {
395395
failIfValidationErrors
396396
}
397397

398+
#
399+
# Function to validate the domain's persistent volume claim has been created
400+
#
401+
function validateDomainPVC {
402+
# Check if the persistent volume claim is already available
403+
checkPvcExists ${persistentVolumeClaimName} ${namespace}
404+
if [ "${PVC_EXISTS}" = "false" ]; then
405+
validationError "The domain persistent volume claim ${persistentVolumeClaimName} does not exist in namespace ${namespace}"
406+
fi
407+
failIfValidationErrors
408+
}
409+

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# WebLogic sample domain home in Docker image
22

3-
The sample scripts demonstrate the creation of a WebLogic domain home in a Docker image. The scripts also generate the domain YAML file, which can then be used to start the Kubernetes artifacts of the corresponding domain. Optionally, the scripts start up the domain, and WebLogic Server pods and services.
3+
The sample scripts demonstrate the creation of a WebLogic domain home in a Docker image. The log home is on an existing Kubernetes persistent volume (PV) and persistent volume claim (PVC). The scripts also generate the domain YAML file, which can then be used to start the Kubernetes artifacts of the corresponding domain. Optionally, the scripts start up the domain, and WebLogic Server pods and services.
44

55
## Prerequisites
66

7+
Before you begin, read this guide, [Domain Resource](../../../../../site/domain-resource.md)
8+
79
The following prerequisites must be handled prior to running the create domain script:
810
* The WDT sample requires that JAVA_HOME is set to a java JDK version 1.8 or greater
911
* Make sure the WebLogic operator is running.
1012
* The operator requires WebLogic Server 12.2.1.3.0 with patch 28076014 applied. Refer to [Weblogic Docker images](../../../../../site/weblogic-docker-images.md) for details on how to create one. If a different `domainHomeImageBase` (see Configuration table below) is specified, the specified image needs to be built locally or pulled from a repository.
1113
* Create a Kubernetes namespace for the domain unless the intention is to use the default namespace.
14+
* In the same Kubernetes namespace, create the Kubernetes persistent volume where the log home will be hosted, and the Kubernetes persistent volume claim for the domain. For samples to create a PV and PVC, see [Create sample PV and PVC](../../create-weblogic-domain-pv-pvc/README.md).
1215
* Create the Kubernetes secrets `username` and `password` of the admin account in the same Kubernetes namespace as the domain.
1316

1417
## Use the script to create a domain
@@ -49,6 +52,7 @@ usage: create-domain.sh -o dir -i file -u username -p password [-k] [-e] [-h]
4952
-u Username used in building the Docker image for WebLogic domain in image.
5053
-p Password used in building the Docker image for WebLogic domain in image.
5154
-e Also create the resources in the generated YAML files, optional.
55+
-v Validate the existence of persistentVolumeClaim, optional.
5256
-k Keep what has been previously cloned from https://github.com/oracle/docker-images.git, optional.
5357
If not specified, this script will always remove existing project and clone again.
5458
-h Help
@@ -81,6 +85,7 @@ The following parameters can be provided in the inputs file.
8185
| `configuredManagedServerCount` | Number of Managed Server instances to generate for the domain. | `5` |
8286
| `domainHomeImageBase` | Base WebLogic binary image used to build the WebLogic domain image. The operator requires WebLogic Server 12.2.1.3.0 with patch 28076014 applied. Refer to [Weblogic Docker images](../../../../../site/weblogic-docker-images.md) for details on how to create one. If a different `domainHomeImageBase` (see Configuration table below) is specified, the specified image needs to be built locally or pulled from a repository before the `create-domain.sh` script is executed. | |
8387
| `domainHomeImageBuildPath` | Location of the WebLogic "domain home in image" Docker image in `https://github.com/oracle/docker-images.git` project. If not specified, use "./docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt". Another possible value is "./docker-images/OracleWebLogic/samples/12213-domain-home-in-image" which uses WLST scripts, instead of WDT, to generate the domain configuration. | `./docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt` |
88+
| `domainPVMountPath` | Mount path of the domain persistent volume. | `/shared` |
8489
| `domainUID` | Unique ID that will be used to identify this particular domain. Used as the name of the generated WebLogic domain as well as the name of the Kubernetes domain resource. This ID must be unique across all domains in a Kubernetes cluster. This ID cannot contain any character that is not valid in a Kubernetes service name. | `domain1` |
8590
| `exposeAdminNodePort` | Boolean indicating if the Administration Server is exposed outside of the Kubernetes cluster. | `false` |
8691
| `exposeAdminT3Channel` | Boolean indicating if the T3 administrative channel is exposed outside the Kubernetes cluster. | `false` |
@@ -90,9 +95,11 @@ The following parameters can be provided in the inputs file.
9095
| `includeServerOutInPodLog` | Boolean indicating whether to include server .out to the pod's stdout. | `true` |
9196
| `initialManagedServerReplicas` | Number of Managed Servers to initially start for the domain. | `2` |
9297
| `javaOptions` | Java options for starting the Administration and Managed Servers. A Java option can have references to one or more of the following pre-defined variables to obtain WebLogic domain information: `$(DOMAIN_NAME)`, `$(DOMAIN_HOME)`, `$(ADMIN_NAME)`, `$(ADMIN_PORT)`, and `$(SERVER_NAME)`. | `-Dweblogic.StdoutDebugEnabled=false` |
98+
| `logHome` | The in-pod name of the directory to store the domain, node manager, server logs, and server .out files in. If not specified, the value is derived from the `domainUID` as `/shared/logs/<domainUID>`. | `/shared/logs/domain1` |
9399
| `managedServerNameBase` | Base string used to generate Managed Server names. | `managed-server` |
94100
| `managedServerPort` | Port number for each Managed Server. | `8001` |
95101
| `namespace` | Kubernetes namespace in which to create the domain. | `default` |
102+
| `persistentVolumeClaimName` | Name of the persistent volume claim. If not specified, the value is derived from the `domainUID` as `<domainUID>-weblogic-sample-pvc` | `domain1-weblogic-sample-pvc` |
96103
| `productionModeEnabled` | Boolean indicating if production mode is enabled for the domain. | `true` |
97104
| `serverStartPolicy` | Determines which WebLogic Servers will be started up. Legal values are `NEVER`, `IF_NEEDED`, `ADMIN_ONLY`. | `IF_NEEDED` |
98105
| `t3ChannelPort` | Port for the T3 channel of the NetworkAccessPoint. | `30012` |

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/create-domain-inputs.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ weblogicCredentialsSecretName: domain1-weblogic-credentials
6464
# The default is true.
6565
includeServerOutInPodLog: true
6666

67+
# The in-pod name of the directory to store the domain, node manager, server logs, and server .out
68+
# files in.
69+
# If not specified, the value is derived from the domainUID as /shared/logs/<domainUID>
70+
logHome: /shared/logs/domain1
71+
6772
# Port for the T3Channel of the NetworkAccessPoint
6873
t3ChannelPort: 30012
6974

@@ -88,6 +93,13 @@ namespace: default
8893
# Java Option for Weblogic Server
8994
javaOptions: -Dweblogic.StdoutDebugEnabled=false
9095

96+
# Name of the persistent volume claim
97+
# If not specified, the value is derived from the domainUID as <domainUID>-weblogic-sample-pvc
98+
persistentVolumeClaimName: domain1-weblogic-sample-pvc
99+
100+
# Mount path of the domain persistent volume.
101+
domainPVMountPath: /shared
102+
91103
# Base WebLogic binary image used to build the WebLogic domain image
92104
# The operator requires WebLogic Server 12.2.1.3.0 with patch 28076014 applied. See README.md for more help.
93105
# domainHomeImageBase:

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/create-domain.sh

Lines changed: 13 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# * The WDT sample requires that JAVA_HOME is set to a java JDK version 1.8 or greater
1313
# * The kubernetes namespace must already be created
1414
# * The kubernetes secrets 'username' and 'password' of the admin account have been created in the namespace
15+
# * The host directory that will be used as the persistent volume must already exist
16+
# and have the appropriate file permissions set.
17+
# * The kubernetes persisitent volume must already be created
18+
# * The kubernetes persisitent volume claim must already be created
1519
#
1620

1721
# Initialize
@@ -21,12 +25,13 @@ source ${scriptDir}/../../common/utility.sh
2125
source ${scriptDir}/../../common/validate.sh
2226

2327
function usage {
24-
echo usage: ${script} -o dir -i file -u username -p password [-k] [-e] [-h]
28+
echo usage: ${script} -o dir -i file -u username -p password [-k] [-e] [-v] [-h]
2529
echo " -i Parameter inputs file, must be specified."
2630
echo " -o Output directory for the generated properties and YAML files, must be specified."
2731
echo " -u Username used in building the Docker image for WebLogic domain in image."
2832
echo " -p Password used in building the Docker image for WebLogic domain in image."
2933
echo " -e Also create the resources in the generated YAML files, optional."
34+
echo " -v Validate the existence of persistentVolumeClaim, optional."
3035
echo " -k Keep what has been previously from cloned https://github.com/oracle/docker-images.git, optional. "
3136
echo " If not specified, this script will always remove existing project directory and clone again."
3237
echo " -h Help"
@@ -36,6 +41,7 @@ function usage {
3641
#
3742
# Parse the command line options
3843
#
44+
doValidation=false
3945
executeIt=false
4046
cloneIt=true
4147
while getopts "evhki:o:u:p:" opt; do
@@ -44,6 +50,8 @@ while getopts "evhki:o:u:p:" opt; do
4450
;;
4551
o) outputDir="${OPTARG}"
4652
;;
53+
v) doValidation=true
54+
;;
4755
e) executeIt=true
4856
;;
4957
u) username="${OPTARG}"
@@ -133,7 +141,7 @@ function initialize {
133141
validationError "The template file ${domainPropertiesInput} for creating a WebLogic domain was not found"
134142
fi
135143

136-
dcrInput="${scriptDir}/domain-template.yaml"
144+
dcrInput="${scriptDir}/../../common/domain-template.yaml"
137145
if [ ! -f ${dcrInput} ]; then
138146
validationError "The template file ${dcrInput} for creating the domain resource was not found"
139147
fi
@@ -172,14 +180,13 @@ function createFiles {
172180
domainPropertiesOutput="${domainOutputDir}/domain.properties"
173181
dcrOutput="${domainOutputDir}/domain.yaml"
174182

175-
enabledPrefix="" # uncomment the feature
176-
disabledPrefix="# " # comment out the feature
183+
initializeInput
177184

178185
if [ -z "${domainHomeImageBase}" ]; then
179186
fail "Please specify domainHomeImageBase in your input YAML"
180187
fi
181188

182-
domainName=${domainUID}
189+
domainHome="/u01/oracle/user_projects/domains/${domainName}"
183190

184191
# Generate the properties file that will be used when creating the weblogic domain
185192
echo Generating ${domainPropertiesOutput}
@@ -198,64 +205,7 @@ function createFiles {
198205
sed -i -e "s:%T3_CHANNEL_PORT%:${t3ChannelPort}:g" ${domainPropertiesOutput}
199206
sed -i -e "s:%T3_PUBLIC_ADDRESS%:${t3PublicAddress}:g" ${domainPropertiesOutput}
200207

201-
# Generate the yaml to create the domain resource
202-
echo Generating ${dcrOutput}
203-
204-
if [ "${exposeAdminT3Channel}" = true ]; then
205-
exposeAdminT3ChannelPrefix="${enabledPrefix}"
206-
else
207-
exposeAdminT3ChannelPrefix="${disabledPrefix}"
208-
fi
209-
210-
if [ "${exposeAdminNodePort}" = true ]; then
211-
exposeAdminNodePortPrefix="${enabledPrefix}"
212-
else
213-
exposeAdminNodePortPrefix="${disabledPrefix}"
214-
fi
215-
216-
domainHome="/u01/oracle/user_projects/domains/${domainName}"
217-
218-
if [ -z "${weblogicCredentialsSecretName}" ]; then
219-
weblogicCredentialsSecretName="${domainUID}-weblogic-credentials"
220-
fi
221-
222-
cp ${dcrInput} ${dcrOutput}
223-
sed -i -e "s:%NAMESPACE%:$namespace:g" ${dcrOutput}
224-
sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${dcrOutput}
225-
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${dcrOutput}
226-
sed -i -e "s:%DOMAIN_HOME%:${domainHome}:g" ${dcrOutput}
227-
sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${dcrOutput}
228-
sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${dcrOutput}
229-
sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${dcrOutput}
230-
sed -i -e "s:%INCLUDE_SERVER_OUT_IN_POD_LOG%:${includeServerOutInPodLog}:g" ${dcrOutput}
231-
sed -i -e "s:%SERVER_START_POLICY%:${serverStartPolicy}:g" ${dcrOutput}
232-
sed -i -e "s:%EXPOSE_ADMIN_PORT_PREFIX%:${exposeAdminNodePortPrefix}:g" ${dcrOutput}
233-
sed -i -e "s:%ADMIN_NODE_PORT%:${adminNodePort}:g" ${dcrOutput}
234-
sed -i -e "s:%EXPOSE_T3_CHANNEL_PREFIX%:${exposeAdminT3ChannelPrefix}:g" ${dcrOutput}
235-
sed -i -e "s:%JAVA_OPTIONS%:${javaOptions}:g" ${dcrOutput}
236-
sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${dcrOutput}
237-
sed -i -e "s:%INITIAL_MANAGED_SERVER_REPLICAS%:${initialManagedServerReplicas}:g" ${dcrOutput}
238-
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
239-
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_POLICY%:${imagePullPolicy}:g" ${dcrOutput}
240-
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${dcrOutput}
241-
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
242-
243-
domainHomeImageBuildPathDefault="./docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt"
244-
if [ -z $domainHomeImageBuildPath ]; then
245-
domainHomeImageBuildPath=${domainHomeImageBuildPathDefault}
246-
fi
247-
248-
imageName="`basename ${domainHomeImageBuildPath} | sed 's/^[0-9]*-//'`"
249-
250-
# now we know which image to use, update the domain yaml file
251-
if [ -z $image ]; then
252-
sed -i -e "s|%IMAGE_NAME%|${imageName}|g" ${dcrOutput}
253-
else
254-
sed -i -e "s|%IMAGE_NAME%|${image}|g" ${dcrOutput}
255-
fi
256-
257-
# Remove any "...yaml-e" files left over from running sed
258-
rm -f ${domainOutputDir}/*.yaml-e
208+
generateDomainYaml true
259209
}
260210

261211
#

0 commit comments

Comments
 (0)