Skip to content

Commit 358e70a

Browse files
doxiaomarkxnelson
authored andcommitted
Domain sample update and cleanup (#614)
* Cleanup sample code and README plus update domain template for envs Signed-off-by: doxiao <[email protected]> * Move envs to serverPod and serverStartStae to domain level Signed-off-by: doxiao <[email protected]> * Move serverStartState back to admin server level to avoid empty adminServer element Signed-off-by: doxiao <[email protected]> * Remove unused functions and update README Signed-off-by: doxiao <[email protected]> * Minor edits to the README files Signed-off-by: doxiao <[email protected]> * Remove only the generated files Signed-off-by: doxiao <[email protected]> * Address a review comment Signed-off-by: doxiao <[email protected]> * refactor the create domain scripts to share common code * Fix a merge error Signed-off-by: doxiao <[email protected]> * Fix an error in commit 73a4df4 Signed-off-by: doxiao <[email protected]> * Customize base image in domain-home-in-image sample Signed-off-by: doxiao <[email protected]> * Correct the default base image Signed-off-by: doxiao <[email protected]> * Fix a problem in domain home in image case Signed-off-by: doxiao <[email protected]> * Minor correction Signed-off-by: doxiao <[email protected]> * Revert "Minor correction" This reverts commit ec9ee5c. * Remove what is already in another PR Signed-off-by: doxiao <[email protected]>
1 parent b44b86a commit 358e70a

File tree

12 files changed

+223
-385
lines changed

12 files changed

+223
-385
lines changed

kubernetes/samples/scripts/common/utility.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ function parseYaml {
4141
}' > $2
4242
}
4343

44+
#
45+
# Function to remove a file if it exists
46+
#
47+
function removeFileIfExists {
48+
if [ -f $1 ]; then
49+
rm $1
50+
fi
51+
}
52+
4453
#
4554
# Function to parse the common parameter inputs file
4655
#
@@ -203,4 +212,44 @@ function getKubernetesClusterIP {
203212
K8S_IP="${array[1]}"
204213
}
205214

215+
#
216+
# Function to create the domain recource
217+
#
218+
function createDomainResource {
219+
kubectl apply -f ${dcrOutput}
220+
DCR_AVAIL=`kubectl get domain -n ${namespace} | grep ${domainUID} | wc | awk ' { print $1; } '`
221+
if [ "${DCR_AVAIL}" != "1" ]; then
222+
fail "The domain resource ${domainUID} was not found"
223+
fi
224+
}
225+
226+
#
227+
# Function to create a domain
228+
#
229+
function createDomain {
230+
231+
# Setup the environment for running this script and perform initial validation checks
232+
initialize
233+
234+
# Generate files for creating the domain
235+
createFiles
236+
237+
# Check that the domain secret exists and contains the required elements
238+
validateDomainSecret
239+
240+
# Validate the domain's persistent volume claim
241+
if [ "$doValidation" == true ]; then
242+
validateDomainPVC
243+
fi
244+
245+
# Create the WebLogic domain home
246+
createDomainHome
247+
248+
if [ "${executeIt}" = true ]; then
249+
createDomainResource
250+
fi
251+
252+
# Print a summary
253+
printSummary
254+
}
206255

kubernetes/samples/scripts/common/validate.sh

Lines changed: 78 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -100,72 +100,6 @@ function validateNamespace {
100100
validateLowerCase "namespace" ${namespace}
101101
}
102102

103-
#
104-
# Function to validate that either the output dir does not exist,
105-
# or that if it does, it does not contain any generated yaml files
106-
# and does not contain an inputs file that differs from the one
107-
# the script is using
108-
# $1 - the output directory to validate
109-
# $2 - the name of the input file the create script is using
110-
# $3 - the name of the input file that is put into the output directory
111-
# $4-n - the names of the generated yaml files
112-
function validateOutputDir {
113-
local dir=$1
114-
shift
115-
if [ -e ${dir} ]; then
116-
# the output directory already exists
117-
if [ -d ${dir} ]; then
118-
# the output directory is a directory
119-
local in1=$1
120-
shift
121-
local in2=${1}
122-
shift
123-
internalValidateGeneratedYamlFilesDoNotExist ${dir} $@
124-
else
125-
validationError "${dir} exists but is not a directory."
126-
fi
127-
fi
128-
}
129-
130-
#
131-
# Internal function to validate that the inputs file does not exist in the
132-
# outputs directory or is the same as the inputs file the script is using
133-
# $1 - the output directory to validate
134-
# $2 - the name of the input file the create script is using
135-
# $3 - the name of the input file that is put into the output directory
136-
function internalValidateInputsFileDoesNotExistOrIsTheSame {
137-
local dir=$1
138-
local in1=$2
139-
local in2=$3
140-
local f="${dir}/${in2}"
141-
if [ -e ${f} ]; then
142-
if [ -f ${f} ]; then
143-
local differences=`diff -q ${f} ${in1}`
144-
if ! [ -z "${differences}" ]; then
145-
validationError "${f} is different than ${in1}"
146-
fi
147-
else
148-
validationError "${f} exists and is not a file."
149-
fi
150-
fi
151-
}
152-
153-
#
154-
# Internal unction to validate that the generated yaml files do not exist
155-
# in the outputs directory
156-
# $1 - the output directory to validate
157-
# $2-n - the names of the generated yaml files
158-
function internalValidateGeneratedYamlFilesDoNotExist {
159-
local dir=$1
160-
shift
161-
for var in "$@"; do
162-
local f="${dir}/${var}"
163-
if [ -e ${f} ]; then
164-
validationError "${f} exists."
165-
fi
166-
done
167-
}
168-
169103
#
170104
# Function to validate the version of the inputs file
171105
#
@@ -329,4 +263,82 @@ function validateLoadBalancer {
329263
fi
330264
}
331265

266+
#
267+
# Function to validate a kubernetes secret exists
268+
# $1 - the name of the secret
269+
# $2 - namespace
270+
function validateSecretExists {
271+
echo "Checking to see if the secret ${1} exists in namespace ${2}"
272+
local SECRET=`kubectl get secret ${1} -n ${2} | grep ${1} | wc | awk ' { print $1; }'`
273+
if [ "${SECRET}" != "1" ]; then
274+
validationError "The secret ${1} was not found in namespace ${2}"
275+
fi
276+
}
277+
278+
#
279+
# Function to validate the domain secret
280+
#
281+
function validateDomainSecret {
282+
# Verify the secret exists
283+
validateSecretExists ${weblogicCredentialsSecretName} ${namespace}
284+
failIfValidationErrors
285+
286+
# Verify the secret contains a username
287+
SECRET=`kubectl get secret ${weblogicCredentialsSecretName} -n ${namespace} -o jsonpath='{.data}'| grep username: | wc | awk ' { print $1; }'`
288+
if [ "${SECRET}" != "1" ]; then
289+
validationError "The domain secret ${weblogicCredentialsSecretName} in namespace ${namespace} does contain a username"
290+
fi
291+
292+
# Verify the secret contains a password
293+
SECRET=`kubectl get secret ${weblogicCredentialsSecretName} -n ${namespace} -o jsonpath='{.data}'| grep password: | wc | awk ' { print $1; }'`
294+
if [ "${SECRET}" != "1" ]; then
295+
validationError "The domain secret ${weblogicCredentialsSecretName} in namespace ${namespace} does contain a password"
296+
fi
297+
failIfValidationErrors
298+
}
299+
300+
#
301+
# Function to validate the common input parameters
302+
#
303+
function validateCommonInputs {
304+
# Parse the commonn inputs file
305+
parseCommonInputs
306+
307+
validateInputParamsSpecified \
308+
adminServerName \
309+
domainUID \
310+
clusterName \
311+
managedServerNameBase \
312+
namespace \
313+
t3PublicAddress \
314+
includeServerOutInPodLog \
315+
version
316+
317+
validateIntegerInputParamsSpecified \
318+
adminPort \
319+
configuredManagedServerCount \
320+
initialManagedServerReplicas \
321+
managedServerPort \
322+
t3ChannelPort \
323+
adminNodePort
324+
325+
validateBooleanInputParamsSpecified \
326+
productionModeEnabled \
327+
exposeAdminT3Channel \
328+
exposeAdminNodePort \
329+
includeServerOutInPodLog
330+
331+
export requiredInputsVersion="create-weblogic-sample-domain-inputs-v1"
332+
validateVersion
333+
334+
validateDomainUid
335+
validateNamespace
336+
validateAdminServerName
337+
validateManagedServerNameBase
338+
validateClusterName
339+
validateWeblogicCredentialsSecretName
340+
validateServerStartPolicy
341+
validateClusterType
342+
failIfValidationErrors
343+
}
332344

kubernetes/samples/scripts/create-weblogic-domain-load-balancer/create-load-balancer.sh

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ fi
6262
# Function to initialize and validate the output directory
6363
# for the generated yaml files for this domain.
6464
#
65-
function initAndValidateOutputDir {
65+
function initOutputDir {
6666
lbOutputDir=${outputDir}/load-balancers/${domainUID}
6767

6868
if [ ! -z "${loadBalancer}" ]; then
6969
case ${loadBalancer} in
7070
"TRAEFIK")
71-
fileList="traefik.yaml \
72-
traefik-security.yaml "
71+
removeFileIfExists ${lbOutputDir}/traefik.yaml
72+
removeFileIfExists ${lbOutputDir}/traefik-security.yaml
7373
;;
7474
"APACHE")
75-
fileList="apache.yaml \
76-
apache-security.yaml "
75+
removeFileIfExists ${lbOutputDir}/apache.yaml
76+
removeFileIfExists ${lbOutputDir}/apache-security.yaml
7777
;;
7878
"VOYAGER")
79-
fileList="voyager-ingress.yaml \
80-
voyager-operator.yaml \
81-
voyager-operator-security.yaml"
79+
removeFileIfExists ${lbOutputDir}/voyager-ingress.yaml
80+
removeFileIfExists ${lbOutputDir}/voyager-operator.yaml \
81+
removeFileIfExists ${lbOutputDir}/voyager-operator-security.yaml
8282
;;
8383
"NONE")
8484
;;
@@ -87,11 +87,10 @@ function initAndValidateOutputDir {
8787
;;
8888
esac
8989
fi
90-
validateOutputDir \
91-
${lbOutputDir} \
92-
${valuesInputFile} \
93-
create-load-balancer-inputs.yaml \
94-
${fileList}
90+
91+
removeFileIfExists ${lbOutputDir}/${valuesInputFile}
92+
removeFileIfExists ${lbOutputDir}/create-load-balancer-inputs.yaml
93+
9594
}
9695

9796
#
@@ -169,7 +168,7 @@ function initialize {
169168
validateNamespace
170169
validateClusterName
171170
validateLoadBalancer
172-
initAndValidateOutputDir
171+
initOutputDir
173172
failIfValidationErrors
174173
}
175174

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ The PV and PVC creation inputs can be customized by editing the `create-pv-pvc-i
6161

6262
## Shared versus dedicated PVC
6363

64-
By default, the `domainUID` is left empty in the inputs file so that the generated PV and PVC can be shared by multiple domain resources in the same Kubernetes namespaces.
64+
By default, the `domainUID` is left empty in the inputs file, which means the generated PV and PVC will not be associated with a particular domain, but can be shared by multiple domain resources in the same Kubernetes namespaces as the PV and PVC.
6565

66-
For the use cases where a dedicated PV and PVC is desired for a particular domain, the `domainUID` can be set, which will cause the generated PV and PVC to be associated with the specified `domainUID`. In the per domain PV and PVC case, the names of the generated YAML files and the Kubernetes PV and PVC objects are decorated with the `domainUID`, and the PV and PVC objects are also labeled with the `domainUID`.
66+
For the use cases where dedicated PV and PVC are desired for a particular domain, the `domainUID` needs to be set in the `create-pv-pvc-inputs.yaml` file. The presence of a non-empty domainUID in the inputs file will cause the generated PV and PVC to be associated with the specified `domainUID`. The association includes that the names of the generated YAML files and the Kubernetes PV and PVC objects are decorated with the `domainUID`, and the PV and PVC objects are also labeled with the `domainUID`.
6767

6868
## Verify the results
6969

kubernetes/samples/scripts/create-weblogic-domain-pv-pvc/create-pv-pvc.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fi
6464
# Function to initialize and validate the output directory
6565
# for the generated yaml files for this domain.
6666
#
67-
function initAndValidateOutputDir {
67+
function initOutputDir {
6868
pvOutputDir="$outputDir/pv-pvcs"
6969

7070
if [ -z ${domainUID} ]; then
@@ -78,13 +78,10 @@ function initAndValidateOutputDir {
7878
persistentVolumeName=${domainUID}-${baseName}-pv
7979
persistentVolumeClaimName=${domainUID}-${baseName}-pvc
8080
fi
81-
82-
validateOutputDir \
83-
${pvOutputDir} \
84-
${valuesInputFile} \
85-
create-pv-pvc-inputs.yaml \
86-
${pvOutput} \
87-
${pvcOutput}
81+
removeFileIfExists ${pvOutputDir}/{valuesInputFile}
82+
removeFileIfExists ${pvOutputDir}/{pvOutput}
83+
removeFileIfExists ${pvOutputDir}/{pvcOutput}
84+
removeFileIfExists ${pvOutputDir}/create-pv-pvc-inputs.yaml
8885
}
8986

9087
#
@@ -133,7 +130,7 @@ function initialize {
133130
validateNamespace
134131
validateWeblogicDomainStorageType
135132
validateWeblogicDomainStorageReclaimPolicy
136-
initAndValidateOutputDir
133+
initOutputDir
137134
failIfValidationErrors
138135
}
139136

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Make a copy of the `create-domain-inputs.yaml` file, and run the create script,
2424

2525
The script will perform the following steps:
2626

27-
* Create a directory for the generated properties and 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.
27+
* Create a directory for the generated properties and Kubernetes YAML files for this domain if it does not already exist. The pathname is `/path/to/weblogic-operator-output-directory/weblogic-domains/<domainUID>`. If the directory already exists, its contents will be removed.
2828
* Create a properties file, `domain.properties`, in the directory that is created above. This properties file will be used to create a sample WebLogic Server domain.
2929
* Clone the weblogic docker-images project via the `git clone https://github.com/oracle/docker-images.git` into the current directory.
3030
* Replace the built-in username and password in the `properties/docker_build/domain_security.properties` file with the `username` and `password` that are supplied in the command line via the `-u` and `-p` options. These credentials need to match the WebLogic domain admin credentials in the secret that is specified via `weblogicCredentialsSecretName` property in the `create-domain-inputs.yaml` file.
@@ -188,11 +188,11 @@ API Version: weblogic.oracle/v2
188188
Kind: Domain
189189
Metadata:
190190
Cluster Name:
191-
Creation Timestamp: 2018-12-11T01:33:27Z
191+
Creation Timestamp: 2018-12-11T21:27:35Z
192192
Generation: 1
193-
Resource Version: 46624
193+
Resource Version: 814010
194194
Self Link: /apis/weblogic.oracle/v2/namespaces/default/domains/domain1
195-
UID: c1f7be60-fce4-11e8-bc6c-0021f6985fb7
195+
UID: 93e55739-fd8b-11e8-b751-fa163e855ac8
196196
Spec:
197197
Admin Secret:
198198
Name: domain1-weblogic-credentials
@@ -246,6 +246,10 @@ Spec:
246246
Server Pod:
247247
Container Security Context:
248248
Env:
249+
Name: JAVA_OPTIONS
250+
Value: -Dweblogic.StdoutDebugEnabled=false
251+
Name: USER_MEM_ARGS
252+
Value: -Xms64m -Xmx256m
249253
Liveness Probe:
250254
Node Selector:
251255
Pod Annotations:
@@ -262,35 +266,27 @@ Spec:
262266
Server Start Policy: IF_NEEDED
263267
Status:
264268
Conditions:
265-
Last Transition Time: 2018-12-11T01:35:23.652Z
269+
Last Transition Time: 2018-12-11T21:28:59.537Z
266270
Reason: ServersReady
267271
Status: True
268272
Type: Available
269273
Servers:
270274
Health:
271-
Activation Time: 2018-12-11T01:34:59.546Z
275+
Activation Time: 2018-12-11T21:28:36.983Z
272276
Overall Health: ok
273277
Subsystems:
274278
Node Name: xxxxxxxx
275279
Server Name: admin-server
276280
State: RUNNING
277281
Cluster Name: cluster-1
278-
Health:
279-
Activation Time: 2018-12-11T01:36:46.132Z
280-
Overall Health: ok
281-
Subsystems:
282282
Node Name: xxxxxxxx
283283
Server Name: managed-server1
284-
State: RUNNING
284+
State: STARTING
285285
Cluster Name: cluster-1
286-
Health:
287-
Activation Time: 2018-12-11T01:36:47.865Z
288-
Overall Health: ok
289-
Subsystems:
290286
Node Name: xxxxxxxx
291287
Server Name: managed-server2
292-
State: RUNNING
293-
Start Time: 2018-12-11T01:33:27.339Z
288+
State: STARTING
289+
Start Time: 2018-12-11T21:27:35.869Z
294290
Events: <none>
295291
```
296292

0 commit comments

Comments
 (0)