Skip to content

Commit d5489aa

Browse files
authored
Merge pull request #159 from oracle/domain-pv-reclaim-policy-customization
Domain pv reclaim policy customization
2 parents a014a43 + cc96e45 commit d5489aa

File tree

9 files changed

+129
-4
lines changed

9 files changed

+129
-4
lines changed

kubernetes/create-weblogic-domain-inputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ 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+
# The valid values are: 'Retain', 'Delete', and 'Recycle'
51+
weblogicDomainStorageReclaimPolicy: Retain
52+
4953
# Total storage allocated to the domain's persistent storage.
5054
weblogicDomainStorageSize: 10Gi
5155

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 25 additions & 0 deletions
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 "ERROR - Invalid value for weblogicDomainStorageReclaimPolicy ${weblogicDomainStorageReclaimPolicy} with weblogicDomainStoragePath ${weblogicDomainStoragePath} that 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
#
@@ -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%

site/creating-domain.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ The following parameters must be provided in the input file:
120120
| t3PublicAddress | Public address for the t3 channel. | kubernetes |
121121
| weblogicCredentialsSecretName | Name of the Kubernetes secret for the Administration Server's username and password. | domain1-weblogic-credentials |
122122
| weblogicDomainStoragePath | Physical path of the storage for the domain. | no default |
123+
| weblogicDomainStorageReclaimPolicy | Kubernetes persistent volume reclaim policy for the domain persistent storage | Retain |
123124
| weblogicDomainStorageSize | Total storage allocated for the domain. | 10Gi |
124125
| weblogicDomainStorageType | Type of storage for the domain. Legal values are 'NFS' and 'HOST_PATH". | HOST_PATH |
125126
| weblogicDomainStorageNFSServer| The name of IP address of the NFS server for the domain's storage. | no default |

src/integration-tests/bash/cleanup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ OCOUNT=${#OPER_NAMESPACES[@]}
5151
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
5252
PROJECT_ROOT="$SCRIPTPATH/../../.."
5353
RESULT_ROOT=${RESULT_ROOT:-/scratch/$USER/wl_k8s_test_results}
54+
PV_ROOT=${PV_ROOT:-$RESULT_ROOT}
5455
RESULT_DIR="$RESULT_ROOT/acceptance_test_tmp"
5556
USER_PROJECTS_DIR="$RESULT_DIR/user-projects"
5657
TMP_DIR="$RESULT_DIR/cleanup_tmp"

src/integration-tests/bash/run.sh

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,11 @@ function run_create_domain_job {
768768
sed -i -e "s/^configuredManagedServerCount:.*/configuredManagedServerCount: 3/" $inputs
769769
fi
770770

771+
# we will test pv reclaim policy in domain6. We choose to do this way to void adding too many parameters in dom_define
772+
if [ "$DOMAIN_UID" == "domain6" ] ; then
773+
sed -i -e "s/^weblogicDomainStorageReclaimPolicy:.*/weblogicDomainStorageReclaimPolicy: Recycle/" $inputs
774+
fi
775+
771776
local outfile="${tmp_dir}/mkdir_physical_nfs.out"
772777
trace "Use a job to create the k8s host directory \"$PV_ROOT/acceptance_test_pv/$DOMAIN_STORAGE_DIR\" that we will use for the domain's persistent volume, see \"$outfile\" for job tracing."
773778

@@ -2250,6 +2255,32 @@ function test_create_domain_startup_control_admin {
22502255
declare_test_pass
22512256
}
22522257

2258+
2259+
function test_create_domain_pv_reclaim_policy_recycle {
2260+
declare_new_test 1 "$@"
2261+
2262+
if [ "$#" != 1 ] ; then
2263+
fail "requires 1 parameters: domainKey"
2264+
fi
2265+
2266+
local DOM_KEY=${1}
2267+
local DOMAIN_UID="`dom_get $1 DOMAIN_UID`"
2268+
local NAMESPACE="`dom_get $1 NAMESPACE`"
2269+
2270+
run_create_domain_job $DOMAIN_UID
2271+
verify_domain_created $DOMAIN_UID
2272+
shutdown_domain $DOM_KEY
2273+
2274+
kubectl delete pvc ${DOMAIN_UID}-weblogic-domain-pvc -n $NAMESPACE
2275+
2276+
local count=`kubectl get pv $DOMAIN_UID-weblogic-domain-pv -n $NAMESPACE |grep "^$DOMAIN_UID " | wc -l `
2277+
if [ ${count:=Error} != 0 ] ; then
2278+
fail "ERROR: pv for $DOMAIN_UID still exists after the pvc is deleted, exiting!"
2279+
fi
2280+
2281+
declare_test_pass
2282+
}
2283+
22532284
# scale domain $1 up and down, and optionally verify the scaling had no effect on domain $2
22542285
function test_cluster_scale {
22552286
declare_new_test 1 "$@"
@@ -2453,10 +2484,10 @@ function test_suite_init {
24532484
# 777 is needed because this script, k8s pods, and/or jobs may need access.
24542485

24552486
/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"
2487+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULT_ROOT/acceptance_test_tmp"
24572488

24582489
/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"
2490+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULT_ROOT/acceptance_test_tmp_archive"
24602491

24612492
/usr/local/packages/aime/ias/run_as_root "mkdir -p $PV_ROOT/acceptance_test_pv"
24622493
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_pv"
@@ -2524,6 +2555,7 @@ function test_suite {
25242555
dom_define domain3 oper1 test1 domain3 AUTO cluster-1 managed-server 7021 30041 30703 8031 30307 30317
25252556
dom_define domain4 oper2 test2 domain4 AUTO cluster-1 managed-server 7041 30051 30704 8041 30308 30318
25262557
dom_define domain5 oper1 default domain5 ADMIN cluster-1 managed-server 7051 30061 30705 8051 30309 30319
2558+
dom_define domain6 oper1 default domain6 AUTO cluster-1 managed-server 7061 30071 30706 8061 30310 30320
25272559

25282560
# create namespaces for domains (the operator job creates a namespace if needed)
25292561
# TODO have the op_define commands themselves create target namespace if it doesn't already exist, or test if the namespace creation is needed in the first place, and if so, ask MikeG to create them as part of domain create job
@@ -2588,9 +2620,12 @@ function test_suite {
25882620
# cycle domain1 down and back up, plus verify no impact on domain4
25892621
test_domain_lifecycle domain1 domain4
25902622

2591-
# create another domain in the default namespace with startupControl="ADMIN", and verify that only admin server is created
2623+
# create domain5 in the default namespace with startupControl="ADMIN", and verify that only admin server is created
25922624
test_create_domain_startup_control_admin domain5
25932625

2626+
# create domain6 in the default namespace with pvReclaimPolicy="Recycle", and verify that the PV is deleted once the domain and PVC are deleted
2627+
test_create_domain_pv_reclaim_policy_recycle domain6
2628+
25942629
# test managed server 1 pod auto-restart
25952630
test_wls_liveness_probe domain1
25962631

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: 40 additions & 0 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";
@@ -246,6 +247,41 @@ public void createDomain_with_missingWeblogicDomainStoragePath_failsAndReturnsEr
246247
failsAndPrints(paramMissingError(PARAM_WEBLOGIC_DOMAIN_STORAGE_PATH)));
247248
}
248249

250+
@Test
251+
public void createDomain_with_invalidWeblogicDomainStorageReclaimPolicy_failsAndReturnsError() throws Exception {
252+
String val = "invalid-storage-reclaim-policy";
253+
assertThat(
254+
execCreateDomain(newInputs().weblogicDomainStorageReclaimPolicy(val)),
255+
failsAndPrints(invalidEnumParamValueError(PARAM_WEBLOGIC_DOMAIN_STORAGE_RECLAIM_POLICY, val)));
256+
}
257+
258+
@Test
259+
public void createDomain_with_weblogicDomainStorageReclaimPolicyDeleteAndNonTmpWeblogicDomainStoragePath_failsAndReturnsError() throws Exception {
260+
assertThat(
261+
execCreateDomain(newInputs().weblogicDomainStorageReclaimPolicy(STORAGE_RECLAIM_POLICY_DELETE).weblogicDomainStoragePath("/scratch")),
262+
failsAndPrints(invalidRelatedParamValueError(PARAM_WEBLOGIC_DOMAIN_STORAGE_RECLAIM_POLICY, STORAGE_RECLAIM_POLICY_DELETE,
263+
PARAM_WEBLOGIC_DOMAIN_STORAGE_PATH, "/scratch")));
264+
}
265+
266+
@Test
267+
public void createDomain_with_weblogicDomainStorageReclaimPolicyRecycle_succeeds() throws Exception {
268+
GeneratedDomainYamlFiles
269+
.generateDomainYamlFiles(
270+
newInputs()
271+
.weblogicDomainStorageReclaimPolicy(STORAGE_RECLAIM_POLICY_RECYCLE))
272+
.remove();
273+
}
274+
275+
@Test
276+
public void createDomain_with_weblogicDomainStorageReclaimPolicyDelete_and_tmpWeblogicDomainStoragePath_succeeds() throws Exception {
277+
GeneratedDomainYamlFiles
278+
.generateDomainYamlFiles(
279+
newInputs()
280+
.weblogicDomainStorageReclaimPolicy(STORAGE_RECLAIM_POLICY_DELETE)
281+
.weblogicDomainStoragePath("/tmp/"))
282+
.remove();
283+
}
284+
249285
@Test
250286
public void createDomain_with_missingWeblogicDomainStorageSize_failsAndReturnsError() throws Exception {
251287
assertThat(
@@ -466,6 +502,10 @@ private String invalidEnumParamValueError(String param, String val) {
466502
return errorRegexp("Invalid.*" + param + ".*" + val);
467503
}
468504

505+
private String invalidRelatedParamValueError(String param, String val, String param2, String val2) {
506+
return errorRegexp("Invalid.*" + param + ".*" + val + " with " + param2 + ".*" + val2);
507+
}
508+
469509
private String paramMissingError(String param) {
470510
return errorRegexp(param + ".*missing");
471511
}

0 commit comments

Comments
 (0)