Skip to content

Commit 56f73e6

Browse files
committed
Fine tuning create domain and credentials samples
Signed-off-by: doxiao <[email protected]>
1 parent dab0d72 commit 56f73e6

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

kubernetes/samples/scripts/create-weblogic-domain/create-weblogic-credentials.sh

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
# The following pre-requisites must be handled prior to running this script:
99
# * The kubernetes namespace must already be created
1010
#
11+
# Secret name determination
12+
# 1) secretName - if specified
13+
# 2) domain1-weblogic-credentials - if secretName and domainUID are both not specified. This is the default out-of-the-box.
14+
# 3) <domainUID>-weblogic-credentials - if secretName is not specified, and domainUID is specified.
15+
# 4) <domainUID>-weblogic-credentials - if secretName is not specified, and domainUID is specified as "".
16+
#
17+
# The generated secret will be labeled with
18+
# weblogic.domainUID=$domainUID
19+
# and
20+
# weblogic.domainName=$domainUID
21+
# Where the $domainUID is the value of the -d command line option, unless the value supplied is an empty String ""
22+
#
1123

1224
script="${BASH_SOURCE[0]}"
1325

@@ -27,11 +39,12 @@ function validateKubectlAvailable {
2739
}
2840

2941
function usage {
30-
echo usage: ${script} -u username -p password [-d domainUID] [-n namespace] [-h]
42+
echo usage: ${script} -u username -p password [-d domainUID] [-n namespace] [-s sercretName] [-h]
3143
echo " -u username, must be specified."
3244
echo " -p password, must be specified."
33-
echo " -n namespace, optional."
34-
echo " -d domainUID, optional."
45+
echo " -n namespace, optional. The value is default if not specified"
46+
echo " -d domainUID, optional. The default value is `domain1`. When specified, the secret will be label with the domainUID unless the given value is an empty string."
47+
echo " -s secretName, optional. When not specified, the secret name will be determined based on the domainUID option"
3548
echo " -h Help"
3649
exit $1
3750
}
@@ -41,7 +54,7 @@ function usage {
4154
#
4255
domainUID=domain1
4356
namespace=default
44-
while getopts "hu:p:n:d:" opt; do
57+
while getopts "hu:p:n:d:s:" opt; do
4558
case $opt in
4659
u) username="${OPTARG}"
4760
;;
@@ -51,13 +64,22 @@ while getopts "hu:p:n:d:" opt; do
5164
;;
5265
d) domainUID="${OPTARG}"
5366
;;
67+
s) secretName="${OPTARG}"
68+
;;
5469
h) usage 0
5570
;;
5671
*) usage 1
5772
;;
5873
esac
5974
done
60-
secretName=$domainUID-weblogic-credentials
75+
76+
if [ -z $secretName ]; then
77+
if [ -z $domainUID ]; then
78+
secretName=weblogic-credentials
79+
else
80+
secretName=$domainUID-weblogic-credentials
81+
fi
82+
fi
6183

6284
if [ -z ${username} ]; then
6385
echo "${script}: -u must be specified."
@@ -84,13 +106,15 @@ kubectl -n $namespace create secret generic $secretName \
84106
--from-literal=username=$username \
85107
--from-literal=password=$password
86108

87-
# label the secret with domainUID
88-
kubectl label secret ${secretName} -n $namespace weblogic.domainUID=$domainUID weblogic.domainName=$domainUID
109+
# label the secret with domainUID if needed
110+
if [ ! -z $domainUID ]; then
111+
kubectl label secret ${secretName} -n $namespace weblogic.domainUID=$domainUID weblogic.domainName=$domainUID
112+
fi
89113

90114
# Verify the secret exists
91115
SECRET=`kubectl get secret ${secretName} -n ${namespace} | grep ${secretName} | wc | awk ' { print $1; }'`
92116
if [ "${SECRET}" != "1" ]; then
93117
fail "The secret ${secretName} was not found in namespace ${namespace}"
94118
fi
95119

96-
echo "The secret ${secretName} has been successfully created in namespace ${namespace}"
120+
echo "The secret ${secretName} has been successfully created in the ${namespace} namespace."

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Make a copy of the `create-domain-inputs.yaml` file, and run the create script,
2222

2323
The script will perform the following steps:
2424

25-
* Create a directory for the generated Kubernetes YAML files for this domain. The pathname is `/path/to/weblogic-operator-output-directory/weblogic-domains/<domainUID>`.
25+
* Create a directory for the generated Kubernetes YAML files for this domain if it does not already exist. The pathname is `/path/to/weblogic-operator-output-directory/weblogic-domains/<domainUID>`. Note that the script fails if the directory is not empty when the `create-domain.sh` script is executed.
2626
* Create a Kubernetes job that will start up a utility WebLogic Server container and run offline WLST scripts, or WebLogic Deploy Tool (WDT) scripts, to create the domain on the shared storage.
2727
* Run the job and wait for the job to finish.
2828
* Create a Kubernetes domain custom resource YAML file, `domain-custom-resource.yaml`, in the directory that is created above. This YAML file can be used to create the Kubernetes resource using the `kubectl create -f` or `kubectl apply -f` command.

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ function createYamlFiles {
296296
fi
297297

298298
if [ -z "${logHome}" ]; then
299-
logHome="/shared/logs/${domainUID}"
299+
logHome="${domainPVMountPath}/logs/${domainUID}"
300300
fi
301301

302302
# Use the default value if not defined.
@@ -406,7 +406,7 @@ function createYamlFiles {
406406
}
407407

408408
# create domain configmap using what is in the createDomainFilesDir
409-
function create_domain_configmap {
409+
function createDomainConfigmap {
410410
# Use the default files if createDomainFilesDir is not specified
411411
if [ -z "${createDomainFilesDir}" ]; then
412412
createDomainFilesDir=${scriptDir}/wlst
@@ -447,13 +447,21 @@ function create_domain_configmap {
447447
rm -rf $externalFilesTmpDir
448448
}
449449

450+
#
451+
# Function to delete the create domain job config map and fail
452+
#
453+
function cleanupAndFail {
454+
deleteDomainConfigmap
455+
fail $1
456+
}
457+
450458
#
451459
# Function to run the job that creates the domain
452460
#
453461
function createDomainHome {
454462

455463
# create the config map for the job
456-
create_domain_configmap
464+
createDomainConfigmap
457465

458466
# There is no way to re-run a kubernetes job, so first delete any prior job
459467
JOB_NAME="${domainUID}-create-weblogic-sample-domain-job"
@@ -482,7 +490,7 @@ function createDomainHome {
482490
echo A failure was detected in the log file for job $JOB_NAME
483491
echo $JOB_ERRORS
484492
echo Check the log output for additional information
485-
fail "Exiting due to failure - the job has failed"
493+
cleanupAndFail "Exiting due to failure - the job has failed"
486494
fi
487495
fi
488496
done
@@ -493,7 +501,7 @@ function createDomainHome {
493501
echo The create domain job is not showing status completed after waiting 300 seconds
494502
echo Check the log output for errors
495503
kubectl logs jobs/$JOB_NAME -n ${namespace}
496-
fail "Exiting due to failure - the job status is not Completed!"
504+
cleanupAndFail "Exiting due to failure - the job status is not Completed!"
497505
fi
498506

499507
# Check for successful completion in log file
@@ -502,11 +510,22 @@ function createDomainHome {
502510
echo The log file for the create domain job does not contain a successful completion status
503511
echo Check the log output for errors
504512
kubectl logs $JOB_POD -n ${namespace}
505-
fail "Exiting due to failure - the job log file does not contain a successful completion status!"
513+
cleanupAndFail "Exiting due to failure - the job log file does not contain a successful completion status!"
506514
fi
507515

516+
# Delete the configmap for the create domain job
517+
deleteDomainConfigmap
518+
508519
}
509520

521+
#
522+
# Function to delete the config map used by the job
523+
#
524+
function deleteDomainConfigmap {
525+
# delete the configmap
526+
local cmName=${domainUID}-create-weblogic-sample-domain-job-cm
527+
kubectl delete configmap ${cmName} -n $namespace
528+
}
510529

511530
#
512531
# Function to output to the console a summary of the work completed

0 commit comments

Comments
 (0)