Skip to content

Commit 7d14a9f

Browse files
committed
Catch up to master, add tests for persistenceType and nfsServer, improve domain input parameter validation
2 parents e3c49f2 + aeebf7d commit 7d14a9f

12 files changed

+254
-94
lines changed

kubernetes/create-weblogic-domain-inputs.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ managedServerNameBase: managed-server
3636
# Port number for each managed server
3737
managedServerPort: 8001
3838

39+
# Persistent volume type, the value must be hostPath or nfs.
40+
# If using nfs, nfsServer must be specified.
41+
persistenceType: hostPath
42+
43+
# NFS server name or ip. Only used if persistenceType is nfs.
44+
nfsServer: nfsServer
45+
3946
# Physical path of the persistent volume storage
4047
persistencePath: /scratch/k8s_dir/persistentVolume001
4148

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 91 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ function validateClusterName {
129129
# When the parameter is not specified in the input file, it will default to use the value domainUid
130130
#
131131
function validateStorageClass {
132-
if [ -z $persistenceStorageClass ]; then
133-
persistenceStorageClass=$domainUid
132+
if [ -z "${persistenceStorageClass}" ]; then
133+
persistenceStorageClass=${domainUid}
134134
echo Defaulting the input parameter persistenceStorageClass to be $domainUid
135135
else
136136
validateLowerCase "persistenceStorageClass" ${persistenceStorageClass}
@@ -141,25 +141,51 @@ function validateStorageClass {
141141
# Function to validate the persistent volume claim name
142142
#
143143
function validatePersistentVolumeClaimName {
144-
validateLowerCase "persistenceVolumeClaimName" ${persistenceVolumeClaimName}
145-
146-
if [[ ${persistenceVolumeClaimName} != ${domainUid}-* ]] ; then
147-
echo persistenceVolumeClaimName specified does not starts with \'${domainUid}-\', appending it
148-
persistenceVolumeClaimName=${domainUid}-${persistenceVolumeClaimName}
149-
echo persistenceVolumeClaimName is now ${persistenceVolumeClaimName}
144+
validateInputParamsSpecified persistenceVolumeClaimName
145+
if [ ! -z "${persistenceVolumeClaimName}" ]; then
146+
validateLowerCase "persistenceVolumeClaimName" ${persistenceVolumeClaimName}
147+
if [[ "${persistenceVolumeClaimName}" != ${domainUid}-* ]] ; then
148+
echo persistenceVolumeClaimName specified does not starts with \'${domainUid}-\', appending it
149+
persistenceVolumeClaimName=${domainUid}-${persistenceVolumeClaimName}
150+
echo persistenceVolumeClaimName is now ${persistenceVolumeClaimName}
151+
fi
150152
fi
151153
}
152154

153155
#
154156
# Function to validate the persistent volume name
155157
#
156-
function validatePersistenVolumeName {
157-
validateLowerCase "persistenceVolumeName" ${persistenceVolumeName}
158+
function validatePersistentVolumeName {
159+
validateInputParamsSpecified persistenceVolumeName
160+
if [ ! -z "${persistenceVolumeName}" ]; then
161+
validateLowerCase "persistenceVolumeName" ${persistenceVolumeName}
162+
if [[ "${persistenceVolumeName}" != ${domainUid}-* ]] ; then
163+
echo persistenceVolumeName specified does not starts with \'${domainUid}-\', appending it
164+
persistenceVolumeName=${domainUid}-${persistenceVolumeName}
165+
echo persistenceVolumeName is now ${persistenceVolumeName}
166+
fi
167+
fi
168+
}
158169

159-
if [[ ${persistenceVolumeName} != ${domainUid}-* ]] ; then
160-
echo persistenceVolumeName specified does not starts with \'${domainUid}-\', appending it
161-
persistenceVolumeName=${domainUid}-${persistenceVolumeName}
162-
echo persistenceVolumeName is now ${persistenceVolumeName}
170+
#
171+
# Function to validate the persistence type
172+
#
173+
function validatePersistenceType {
174+
validateInputParamsSpecified persistenceType
175+
if [ ! -z "${persistenceType}" ]; then
176+
PERSISTENCE_TYPE_HOST_PATH="hostPath"
177+
PERSISTENCE_TYPE_NFS="nfs"
178+
case ${persistenceType} in
179+
${PERSISTENCE_TYPE_HOST_PATH})
180+
;;
181+
${PERSISTENCE_TYPE_NFS})
182+
validateInputParamsSpecified nfsServer
183+
;;
184+
*)
185+
validationError "Invalid value for persistenceType: ${persistenceType}. Valid values are hostPath and nfs."
186+
validationError "Invalid value for loadBalancer: ${loadBalancer}. Valid values are traefik and none."
187+
;;
188+
esac
163189
fi
164190
}
165191

@@ -174,18 +200,20 @@ function validateSecretName {
174200
# Function to validate the load balancer value
175201
#
176202
function validateLoadBalancer {
177-
LOAD_BALANCER_TRAEFIK="traefik"
178-
LOAD_BALANCER_NONE="none"
179-
180-
case ${loadBalancer} in
181-
${LOAD_BALANCER_TRAEFIK})
182-
;;
183-
${LOAD_BALANCER_NONE})
184-
;;
185-
*)
186-
validationError "Invalid valid for loadBalancer: ${loadBalancer}. Valid values are traefik and none."
187-
;;
188-
esac
203+
validateInputParamsSpecified loadBalancer
204+
if [ ! -z "${loadBalancer}" ]; then
205+
LOAD_BALANCER_TRAEFIK="traefik"
206+
LOAD_BALANCER_NONE="none"
207+
case ${loadBalancer} in
208+
${LOAD_BALANCER_TRAEFIK})
209+
;;
210+
${LOAD_BALANCER_NONE})
211+
;;
212+
*)
213+
validationError "Invalid value for loadBalancer: ${loadBalancer}. Valid values are traefik and none."
214+
;;
215+
esac
216+
fi
189217
}
190218

191219
#
@@ -231,7 +259,6 @@ function validateImagePullSecretName {
231259
# Function to validate the image pull secret exists
232260
#
233261
function validateImagePullSecret {
234-
235262
# The kubernetes secret for pulling images from the docker store is optional.
236263
# If it was specified, make sure it exists.
237264
validateSecretExists ${imagePullSecretName} ${namespace}
@@ -242,27 +269,29 @@ function validateImagePullSecret {
242269
# Function to validate the server startup control value
243270
#
244271
function validateStartupControl {
245-
STARTUP_CONTROL_NONE="NONE"
246-
STARTUP_CONTROL_ALL="ALL"
247-
STARTUP_CONTROL_ADMIN="ADMIN"
248-
STARTUP_CONTROL_SPECIFIED="SPECIFIED"
249-
STARTUP_CONTROL_AUTO="AUTO"
250-
251-
case ${startupControl} in
252-
${STARTUP_CONTROL_NONE})
253-
;;
254-
${STARTUP_CONTROL_ALL})
255-
;;
256-
${STARTUP_CONTROL_ADMIN})
257-
;;
258-
${STARTUP_CONTROL_SPECIFIED})
259-
;;
260-
${STARTUP_CONTROL_AUTO})
261-
;;
262-
*)
263-
validationError "Invalid valid for startupControl: ${startupControl}. Valid values are 'NONE', 'ALL', 'ADMIN', 'SPECIFIED', and 'AUTO'."
264-
;;
265-
esac
272+
validateInputParamsSpecified startupControl
273+
if [ ! -z "${startupControl}" ]; then
274+
STARTUP_CONTROL_NONE="NONE"
275+
STARTUP_CONTROL_ALL="ALL"
276+
STARTUP_CONTROL_ADMIN="ADMIN"
277+
STARTUP_CONTROL_SPECIFIED="SPECIFIED"
278+
STARTUP_CONTROL_AUTO="AUTO"
279+
case ${startupControl} in
280+
${STARTUP_CONTROL_NONE})
281+
;;
282+
${STARTUP_CONTROL_ALL})
283+
;;
284+
${STARTUP_CONTROL_ADMIN})
285+
;;
286+
${STARTUP_CONTROL_SPECIFIED})
287+
;;
288+
${STARTUP_CONTROL_AUTO})
289+
;;
290+
*)
291+
validationError "Invalid valid for startupControl: ${startupControl}. Valid values are 'NONE', 'ALL', 'ADMIN', 'SPECIFIED', and 'AUTO'."
292+
;;
293+
esac
294+
fi
266295
}
267296

268297
#
@@ -334,13 +363,11 @@ function initialize {
334363
managedServerNameBase \
335364
persistencePath \
336365
persistenceSize \
337-
persistenceVolumeClaimName \
338366
persistenceVolumeName \
367+
persistenceVolumeClaimName \
339368
secretName \
340369
namespace \
341-
loadBalancer \
342370
javaOptions \
343-
startupControl \
344371
t3PublicAddress
345372

346373
validateIntegerInputParamsSpecified \
@@ -362,7 +389,8 @@ function initialize {
362389
validateNamespace
363390
validateClusterName
364391
validateStorageClass
365-
validatePersistenVolumeName
392+
validatePersistenceType
393+
validatePersistentVolumeName
366394
validatePersistentVolumeClaimName
367395
validateSecretName
368396
validateImagePullSecretName
@@ -398,12 +426,23 @@ function createYamlFiles {
398426
echo Generating ${domainPVOutput}
399427

400428
cp ${domainPVInput} ${domainPVOutput}
429+
if [ "${persistenceType}" == "nfs" ]; then
430+
hostPathPrefix="${disabledPrefix}"
431+
nfsPrefix="${enabledPrefix}"
432+
sed -i -e "s:%NFS_SERVER%:${nfsServer}:g" ${domainPVOutput}
433+
else
434+
hostPathPrefix="${enabledPrefix}"
435+
nfsPrefix="${disabledPrefix}"
436+
fi
437+
401438
sed -i -e "s:%DOMAIN_UID%:${domainUid}:g" ${domainPVOutput}
402439
sed -i -e "s:%NAMESPACE%:$namespace:g" ${domainPVOutput}
403440
sed -i -e "s:%PERSISTENT_VOLUME%:${persistenceVolumeName}:g" ${domainPVOutput}
404441
sed -i -e "s:%PERSISTENT_VOLUME_PATH%:${persistencePath}:g" ${domainPVOutput}
405442
sed -i -e "s:%PERSISTENT_VOLUME_SIZE%:${persistenceSize}:g" ${domainPVOutput}
406443
sed -i -e "s:%STORAGE_CLASS_NAME%:${persistenceStorageClass}:g" ${domainPVOutput}
444+
sed -i -e "s:%HOST_PATH_PREFIX%:${hostPathPrefix}:g" ${domainPVOutput}
445+
sed -i -e "s:%NFS_PREFIX%:${nfsPrefix}:g" ${domainPVOutput}
407446

408447
# Generate the yaml to create the persistent volume claim
409448
echo Generating ${domainPVCOutput}

kubernetes/internal/create-weblogic-operator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function initAndValidateOutputDir {
161161
# Function to validate the image pull secret name
162162
#
163163
function validateImagePullSecretName {
164-
if [ ! -z ${imagePullSecretName} ]; then
164+
if [ ! -z "${imagePullSecretName}" ]; then
165165
validateLowerCase imagePullSecretName ${imagePullSecretName}
166166
imagePullSecretPrefix=""
167167
validateImagePullSecret

kubernetes/internal/weblogic-domain-persistent-volume-template.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ spec:
1414
accessModes:
1515
- ReadWriteMany
1616
persistentVolumeReclaimPolicy: Retain
17-
hostPath:
17+
%HOST_PATH_PREFIX%hostPath:
18+
%NFS_PREFIX%nfs:
19+
%NFS_PREFIX%server: %NFS_SERVER%
1820
path: "%PERSISTENT_VOLUME_PATH%"

src/integration-tests/bash/run.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,24 @@ function get_cluster_replicas {
885885
echo $replicas
886886
}
887887

888+
function get_startup_control {
889+
if [ "$#" != 1 ] ; then
890+
fail "requires 1 parameter: domainkey"
891+
fi
892+
893+
local NAMESPACE="`dom_get $1 NAMESPACE`"
894+
local DOMAIN_UID="`dom_get $1 DOMAIN_UID`"
895+
896+
local startup_control_cmd="kubectl get domain $DOMAIN_UID -n $NAMESPACE -o jsonpath='{.spec.startupControl}'"
897+
local startup_control=`eval $startup_control_cmd`
898+
899+
if [ -z ${startup_control} ]; then
900+
fail "startupControl not found in domain $DOMAIN_UID"
901+
fi
902+
903+
echo $startup_control
904+
}
905+
888906
function verify_managed_servers_ready {
889907
if [ "$#" != 1 ] ; then
890908
fail "requires 1 parameter: domainkey"
@@ -1888,7 +1906,6 @@ function verify_domain_created {
18881906

18891907
local NAMESPACE="`dom_get $1 NAMESPACE`"
18901908
local DOMAIN_UID="`dom_get $1 DOMAIN_UID`"
1891-
local STARTUP_CONTROL="`dom_get $1 STARTUP_CONTROL`"
18921909
local MS_BASE_NAME="`dom_get $1 MS_BASE_NAME`"
18931910

18941911
trace "verify domain $DOMAIN_UID in $NAMESPACE namespace"
@@ -1908,8 +1925,10 @@ function verify_domain_created {
19081925
trace "verify the service and pod of admin server"
19091926
verify_service_and_pod_created $DOM_KEY 0
19101927

1928+
local startup_control=`get_startup_control $DOM_KEY`
1929+
19111930
local verify_as_only=false
1912-
if [ "$STARTUP_CONTROL" = "ADMIN" ] ; then
1931+
if [ "${startup_control}" = "ADMIN" ] ; then
19131932
verify_as_only=true
19141933
fi
19151934

@@ -2218,6 +2237,22 @@ function test_operator_lifecycle {
22182237
declare_test_pass
22192238
}
22202239

2240+
function test_create_domain_startup_control_admin {
2241+
declare_new_test 1 "$@"
2242+
2243+
if [ "$#" != 1 ] ; then
2244+
fail "requires 1 parameters: domainKey"
2245+
fi
2246+
2247+
local DOM_KEY=${1}
2248+
local DOMAIN_UID="`dom_get $1 DOMAIN_UID`"
2249+
2250+
run_create_domain_job $DOMAIN_UID
2251+
verify_domain_created $DOMAIN_UID
2252+
2253+
declare_test_pass
2254+
}
2255+
22212256
# scale domain $1 up and down, and optionally verify the scaling had no effect on domain $2
22222257
function test_cluster_scale {
22232258
declare_new_test 1 "$@"
@@ -2557,8 +2592,7 @@ function test_suite {
25572592
test_domain_lifecycle domain1 domain4
25582593

25592594
# create another domain in the default namespace with startupControl="ADMIN", and verify that only admin server is created
2560-
run_create_domain_job domain5
2561-
verify_domain_created domain5
2595+
test_create_domain_startup_control_admin domain5
25622596

25632597
# test managed server 1 pod auto-restart
25642598
test_wls_liveness_probe domain1

src/test/java/oracle/kubernetes/operator/create/CreateDomainGeneratedFilesOptionalFeaturesDisabledTest.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import io.kubernetes.client.models.V1ConfigMap;
1010
import io.kubernetes.client.models.V1Job;
11+
import io.kubernetes.client.models.V1PersistentVolume;
1112
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
1213
import static oracle.kubernetes.operator.create.YamlUtils.*;
1314
import static org.hamcrest.MatcherAssert.assertThat;
@@ -377,20 +378,14 @@ public void generatesCorrect_traefikSecurityYaml_traefikDashboardClusterRoleBind
377378

378379
@Test
379380
public void generatesCorrect_weblogicDomainPersistentVolumeYaml_weblogicDomainPersistentVolume() throws Exception {
381+
V1PersistentVolume want =
382+
generatedFiles.getWeblogicDomainPersistentVolumeYaml().getExpectedBaseCreateWeblogicDomainPersistentVolume();
383+
want.getSpec()
384+
.hostPath(newHostPathVolumeSource()
385+
.path(inputs.getPersistencePath()));
380386
assertThat(
381387
generatedFiles.getWeblogicDomainPersistentVolumeYaml().getWeblogicDomainPersistentVolume(),
382-
yamlEqualTo(
383-
newPersistentVolume()
384-
.metadata(newObjectMeta()
385-
.name(getDomainScope() + "-" + inputs.getPersistenceVolumeName())
386-
.putLabelsItem("weblogic.domainUID", inputs.getDomainUid()))
387-
.spec(newPersistentVolumeSpec()
388-
.storageClassName(inputs.getDomainUid())
389-
.putCapacityItem("storage", inputs.getPersistenceSize())
390-
.addAccessModesItem("ReadWriteMany")
391-
.persistentVolumeReclaimPolicy("Retain")
392-
.hostPath(newHostPathVolumeSource()
393-
.path(inputs.getPersistencePath())))));
388+
yamlEqualTo(want));
394389
}
395390

396391
@Test
@@ -400,7 +395,7 @@ public void generatesCorrect_weblogicDomainPersistentVolumeClaimYaml_weblogicDom
400395
yamlEqualTo(
401396
newPersistentVolumeClaim()
402397
.metadata(newObjectMeta()
403-
.name(getDomainScope() + "-" + inputs.getPersistenceVolumeClaimName())
398+
.name(inputs.getDomainUid() + "-" + inputs.getPersistenceVolumeClaimName())
404399
.namespace(inputs.getNamespace())
405400
.putLabelsItem("weblogic.domainUID", inputs.getDomainUid()))
406401
.spec(newPersistentVolumeClaimSpec()
@@ -415,11 +410,7 @@ private String getTraefikScope() {
415410
}
416411

417412
private String getClusterLCScope() {
418-
return getDomainScope() + "-" + getClusterNameLC();
419-
}
420-
421-
public String getDomainScope() {
422-
return inputs.getDomainUid();
413+
return inputs.getDomainUid() + "-" + getClusterNameLC();
423414
}
424415

425416
private String getClusterNameLC() {

0 commit comments

Comments
 (0)