Skip to content

Commit 97372fc

Browse files
committed
Add support for customizing PV reclaim policy
Signed-off-by: Dongbo Xiao <[email protected]>
1 parent c96ffa2 commit 97372fc

12 files changed

+91
-13
lines changed

kubernetes/create-weblogic-domain-inputs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ weblogicDomainStorageType: HOST_PATH
4646
# The following line must be uncomment and customized:
4747
#weblogicDomainStoragePath: /scratch/k8s_dir/domain1
4848

49+
# Reclaim policy of the domain's persistent storage
50+
weblogicDomainStorageReclaimPolicy: Retain
51+
4952
# Total storage allocated to the domain's persistent storage.
5053
weblogicDomainStorageSize: 10Gi
5154

kubernetes/create-weblogic-domain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#
1616

1717
script="${BASH_SOURCE[0]}"
18-
scriptDir="$( cd "$( dirname "${script}" )" && pwd )"
18+
scriptDir="$( cd "$(dirname "${script}")" > /dev/null 2>&1 ; pwd -P)"
1919
internalDir="${scriptDir}/internal"
2020

2121
# This is the script that the customers use to create a domain.

kubernetes/create-weblogic-operator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
44

55
script="${BASH_SOURCE[0]}"
6-
scriptDir="$( cd "$( dirname "${script}" )" && pwd )"
6+
scriptDir="$( cd "$(dirname "${script}")" > /dev/null 2>&1 ; pwd -P)"
77
internalDir="${scriptDir}/internal"
88

99
# This is the script that the customers use to create an operator.

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ function validateClusterName {
124124
clusterNameLC=$(toLower $clusterName)
125125
}
126126

127+
#
128+
# Function to validate the weblogic domain storage reclaim policy
129+
#
130+
function validateWeblogicDomainStorageReclaimPolicy {
131+
validateInputParamsSpecified weblogicDomainStorageReclaimPolicy
132+
if [ ! -z "${weblogicDomainStorageReclaimPolicy}" ]; then
133+
case ${weblogicDomainStorageReclaimPolicy} in
134+
"Retain")
135+
;;
136+
"Delete")
137+
if [ "${weblogicDomainStoragePath:0:5}" != "/tmp/" ]; then
138+
validationError "Invalid value for weblogicDomainStorageReclaimPolicy: ${weblogicDomainStorageReclaimPolicy} when weblogicDomainStoragePath is not /tmp/."
139+
fi
140+
;;
141+
"Recycle")
142+
;;
143+
*)
144+
validationError "Invalid value for weblogicDomainStorageReclaimPolicy: ${weblogicDomainStorageReclaimPolicy}. Valid values are Retain, Delete and Recycle."
145+
;;
146+
esac
147+
fi
148+
}
149+
127150
#
128151
# Function to validate the weblogic domain storage type
129152
#
@@ -134,7 +157,7 @@ function validateWeblogicDomainStorageType {
134157
"HOST_PATH")
135158
;;
136159
"NFS")
137-
validateInputParamsSpecified weblogicDomainStorageNFSServer
160+
validateInputParamsSpecified weblogicDomainStorageNFSServer
138161
;;
139162
*)
140163
validationError "Invalid value for weblogicDomainStorageType: ${weblogicDomainStorageType}. Valid values are HOST_PATH and NFS."
@@ -333,6 +356,7 @@ function initialize {
333356
validateNamespace
334357
validateClusterName
335358
validateWeblogicDomainStorageType
359+
validateWeblogicDomainStorageReclaimPolicy
336360
validateWeblogicCredentialsSecretName
337361
validateWeblogicImagePullSecretName
338362
validateLoadBalancer
@@ -383,6 +407,7 @@ function createYamlFiles {
383407
sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${domainPVOutput}
384408
sed -i -e "s:%NAMESPACE%:$namespace:g" ${domainPVOutput}
385409
sed -i -e "s:%WEBLOGIC_DOMAIN_STORAGE_PATH%:${weblogicDomainStoragePath}:g" ${domainPVOutput}
410+
sed -i -e "s:%WEBLOGIC_DOMAIN_STORAGE_RECLAIM_POLICY%:${weblogicDomainStorageReclaimPolicy}:g" ${domainPVOutput}
386411
sed -i -e "s:%WEBLOGIC_DOMAIN_STORAGE_SIZE%:${weblogicDomainStorageSize}:g" ${domainPVOutput}
387412
sed -i -e "s:%HOST_PATH_PREFIX%:${hostPathPrefix}:g" ${domainPVOutput}
388413
sed -i -e "s:%NFS_PREFIX%:${nfsPrefix}:g" ${domainPVOutput}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ spec:
1313
storage: %WEBLOGIC_DOMAIN_STORAGE_SIZE%
1414
accessModes:
1515
- ReadWriteMany
16-
persistentVolumeReclaimPolicy: Retain
16+
# Valid values are Retain, Delete or Recycle
17+
persistentVolumeReclaimPolicy: %WEBLOGIC_DOMAIN_STORAGE_RECLAIM_POLICY%
1718
%HOST_PATH_PREFIX%hostPath:
1819
%NFS_PREFIX%nfs:
1920
%NFS_PREFIX%server: %WEBLOGIC_DOMAIN_STORAGE_NFS_SERVER%

src/integration-tests/bash/run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ function state_dump {
383383
# use a job to archive PV, /scratch mounts to PV_ROOT in the K8S cluster
384384
trace "Archiving pv directory using a kubernetes job. Look for it on k8s cluster in $PV_ROOT/acceptance_test_pv_archive"
385385
local outfile=${DUMP_DIR}/archive_pv_job.out
386-
$SCRIPTPATH/job.sh "/scripts/archive.sh /scratch/acceptance_test_pv /scratch/acceptance_test_pv_archive" > ${outfile} 2>&1
386+
$SCRIPTPATH/job.sh "/scripts/archive.sh $PV_ROOT/acceptance_test_pv $PV_ROOT/acceptance_test_pv_archive" > ${outfile} 2>&1
387387
if [ "$?" = "0" ]; then
388388
trace Job complete.
389389
else
@@ -773,7 +773,7 @@ function run_create_domain_job {
773773

774774
# Note that the job.sh job mounts PV_ROOT to /scratch and runs as UID 1000,
775775
# so PV_ROOT must already exist and have 777 or UID=1000 permissions.
776-
$SCRIPTPATH/job.sh "mkdir -p /scratch/acceptance_test_pv/$DOMAIN_STORAGE_DIR" > ${outfile} 2>&1
776+
$SCRIPTPATH/job.sh "mkdir -p $PV_ROOT/acceptance_test_pv/$DOMAIN_STORAGE_DIR" > ${outfile} 2>&1
777777
if [ "$?" = "0" ]; then
778778
cat ${outfile} | sed 's/^/+/g'
779779
trace Job complete. Directory created on k8s cluster.
@@ -2453,10 +2453,10 @@ function test_suite_init {
24532453
# 777 is needed because this script, k8s pods, and/or jobs may need access.
24542454

24552455
/usr/local/packages/aime/ias/run_as_root "mkdir -p $RESULT_ROOT/acceptance_test_tmp"
2456-
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_tmp"
2456+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULTPV_ROOT/acceptance_test_tmp"
24572457

24582458
/usr/local/packages/aime/ias/run_as_root "mkdir -p $RESULT_ROOT/acceptance_test_tmp_archive"
2459-
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_tmp_archive"
2459+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULT_ROOT/acceptance_test_tmp_archive"
24602460

24612461
/usr/local/packages/aime/ias/run_as_root "mkdir -p $PV_ROOT/acceptance_test_pv"
24622462
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_pv"

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class CreateDomainInputs {
2929
public static final String LOAD_BALANCER_TRAEFIK = "TRAEFIK";
3030
public static final String STORAGE_TYPE_HOST_PATH = "HOST_PATH";
3131
public static final String STORAGE_TYPE_NFS = "NFS";
32+
public static final String STORAGE_RECLAIM_POLICY_RETAIN = "Retain";
33+
public static final String STORAGE_RECLAIM_POLICY_DELETE = "Delete";
34+
public static final String STORAGE_RECLAIM_POLICY_RECYCLE = "Recycle";
3235
public static final String STARTUP_CONTROL_NONE = "NONE";
3336
public static final String STARTUP_CONTROL_ALL = "ALL";
3437
public static final String STARTUP_CONTROL_ADMIN = "ADMIN";
@@ -47,6 +50,7 @@ public class CreateDomainInputs {
4750
private String initialManagedServerReplicas = "";
4851
private String managedServerNameBase = "";
4952
private String managedServerPort = "";
53+
private String weblogicDomainStorageReclaimPolicy = "";
5054
private String weblogicDomainStorageNFSServer = "";
5155
private String weblogicDomainStoragePath = "";
5256
private String weblogicDomainStorageSize = "";
@@ -286,6 +290,19 @@ public CreateDomainInputs weblogicDomainStorageSize(String weblogicDomainStorage
286290
return this;
287291
}
288292

293+
public String getWeblogicDomainStorageReclaimPolicy() {
294+
return weblogicDomainStorageReclaimPolicy;
295+
}
296+
297+
public void setWeblogicDomainStorageReclaimPolicy(String weblogicDomainStorageReclaimPolicy) {
298+
this.weblogicDomainStorageReclaimPolicy = convertNullToEmptyString(weblogicDomainStorageReclaimPolicy);
299+
}
300+
301+
public CreateDomainInputs weblogicDomainStorageReclaimPolicy(String weblogicDomainStorageReclaimPolicy) {
302+
setWeblogicDomainStorageReclaimPolicy(weblogicDomainStorageReclaimPolicy);
303+
return this;
304+
}
305+
289306
public String getWeblogicDomainStorageType() {
290307
return weblogicDomainStorageType;
291308
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void defaultInputsFile_hasCorrectContents() throws Exception {
6161
.namespace("default")
6262
.weblogicDomainStorageNFSServer("")
6363
.weblogicDomainStoragePath("")
64+
.weblogicDomainStorageReclaimPolicy(STORAGE_RECLAIM_POLICY_RETAIN)
6465
.weblogicDomainStorageSize("10Gi")
6566
.weblogicDomainStorageType(STORAGE_TYPE_HOST_PATH)
6667
.productionModeEnabled("true")

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class CreateDomainInputsValidationTest {
2828
private static final String PARAM_INITIAL_MANAGED_SERVER_REPLICAS = "initialManagedServerReplicas";
2929
private static final String PARAM_MANAGED_SERVER_NAME_BASE = "managedServerNameBase";
3030
private static final String PARAM_MANAGED_SERVER_PORT = "managedServerPort";
31+
private static final String PARAM_WEBLOGIC_DOMAIN_STORAGE_RECLAIM_POLICY = "weblogicDomainStorageReclaimPolicy";
3132
private static final String PARAM_WEBLOGIC_DOMAIN_STORAGE_NFS_SERVER = "weblogicDomainStorageNFSServer";
3233
private static final String PARAM_WEBLOGIC_DOMAIN_STORAGE_PATH = "weblogicDomainStoragePath";
3334
private static final String PARAM_WEBLOGIC_DOMAIN_STORAGE_SIZE = "weblogicDomainStorageSize";
@@ -215,11 +216,37 @@ public void createDomain_with_invalidManagedServerPort_failsAndReturnsError() th
215216
}
216217

217218
@Test
218-
public void createDomain_with_weblogicDomainStorageTypeNfsAndMissingWeblogicDomainStorageNFSServer_failsAndReturnsError() throws Exception {
219+
public void createDomain_with_invalidWeblogicDomainStorageReclaimPolicy_failsAndReturnsError() throws Exception {
220+
String val = "invalid-storage-reclaim-policy";
221+
assertThat(
222+
execCreateDomain(newInputs().weblogicDomainStorageReclaimPolicy(val)),
223+
failsAndPrints(invalidEnumParamValueError(PARAM_WEBLOGIC_DOMAIN_STORAGE_RECLAIM_POLICY, val)));
224+
}
225+
226+
@Test
227+
public void createDomain_with_weblogicDomainStorageReclaimPolicyDeleteAndNonTmoWeblogicDomainStoragePath_failsAndReturnsError() throws Exception {
219228
assertThat(
229+
execCreateDomain(newInputs().weblogicDomainStorageReclaimPolicy(STORAGE_RECLAIM_POLICY_DELETE).weblogicDomainStoragePath("/scratch")),
230+
failsAndPrints(invalidRelatedParamValueError(PARAM_WEBLOGIC_DOMAIN_STORAGE_RECLAIM_POLICY, STORAGE_RECLAIM_POLICY_DELETE,
231+
PARAM_WEBLOGIC_DOMAIN_STORAGE_PATH, "/scratch")));
232+
}
233+
234+
@Test
235+
public void createDomain_with_weblogicDomainStorageReclaimPolicyDelete_and_tmpWeblogicDomainStoragePath_succeeds() throws Exception {
236+
GeneratedDomainYamlFiles
237+
.generateDomainYamlFiles(
238+
newInputs()
239+
.weblogicDomainStorageReclaimPolicy(STORAGE_RECLAIM_POLICY_DELETE)
240+
.weblogicDomainStoragePath("/tmp/"))
241+
.remove();
242+
}
243+
244+
@Test
245+
public void createDomain_with_weblogicDomainStorageTypeNfsAndMissingWeblogicDomainStorageNFSServer_failsAndReturnsError() throws Exception {
246+
assertThat(
220247
execCreateDomain(newInputs().weblogicDomainStorageType(STORAGE_TYPE_NFS).weblogicDomainStorageNFSServer("")),
221248
failsAndPrints(paramMissingError(PARAM_WEBLOGIC_DOMAIN_STORAGE_NFS_SERVER)));
222-
}
249+
}
223250

224251
@Test
225252
public void createDomain_with_invalidWeblogicDomainStorageType_failsAndReturnsError() throws Exception {
@@ -466,6 +493,10 @@ private String invalidEnumParamValueError(String param, String val) {
466493
return errorRegexp("Invalid.*" + param + ".*" + val);
467494
}
468495

496+
private String invalidRelatedParamValueError(String param, String val, String param2, String val2) {
497+
return errorRegexp("Invalid.*" + param + ".*" + val + " with " + param2 + ".*" + val2);
498+
}
499+
469500
private String paramMissingError(String param) {
470501
return errorRegexp(param + ".*missing");
471502
}

src/test/scripts/unit-test-create-weblogic-domain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# create domain script that generates the yaml files.
99

1010
script="${BASH_SOURCE[0]}"
11-
scriptDir="$( cd "$( dirname "${script}" )" && pwd )"
11+
scriptDir="$( cd "$(dirname "${script}")" > /dev/null 2>&1 ; pwd -P)"
1212
kubernetesDir="${scriptDir}/../../../kubernetes"
1313
internalDir="${kubernetesDir}/internal"
1414

0 commit comments

Comments
 (0)