Skip to content

Commit d7f4849

Browse files
authored
Merge pull request #584 from oracle/domain-sample-cleanup
Domain sample cleanup
2 parents 079b2f3 + fc91965 commit d7f4849

File tree

5 files changed

+184
-127
lines changed

5 files changed

+184
-127
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) 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."

0 commit comments

Comments
 (0)