Skip to content

Commit 6f56f07

Browse files
author
Tom Barnes
committed
Merge remote-tracking branch 'origin/master' into int-test-leasing
2 parents ea06893 + 8d0db3f commit 6f56f07

File tree

11 files changed

+193
-76
lines changed

11 files changed

+193
-76
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
@@ -828,6 +828,11 @@ function run_create_domain_job {
828828
sed -i -e "s/^configuredManagedServerCount:.*/configuredManagedServerCount: 3/" $inputs
829829
fi
830830

831+
# we will test pv reclaim policy in domain6. We choose to do this way to void adding too many parameters in dom_define
832+
if [ "$DOMAIN_UID" == "domain6" ] ; then
833+
sed -i -e "s/^weblogicDomainStorageReclaimPolicy:.*/weblogicDomainStorageReclaimPolicy: Recycle/" $inputs
834+
fi
835+
831836
local outfile="${tmp_dir}/mkdir_physical_nfs.out"
832837
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."
833838

@@ -2310,6 +2315,32 @@ function test_create_domain_startup_control_admin {
23102315
declare_test_pass
23112316
}
23122317

2318+
2319+
function test_create_domain_pv_reclaim_policy_recycle {
2320+
declare_new_test 1 "$@"
2321+
2322+
if [ "$#" != 1 ] ; then
2323+
fail "requires 1 parameters: domainKey"
2324+
fi
2325+
2326+
local DOM_KEY=${1}
2327+
local DOMAIN_UID="`dom_get $1 DOMAIN_UID`"
2328+
local NAMESPACE="`dom_get $1 NAMESPACE`"
2329+
2330+
run_create_domain_job $DOMAIN_UID
2331+
verify_domain_created $DOMAIN_UID
2332+
shutdown_domain $DOM_KEY
2333+
2334+
kubectl delete pvc ${DOMAIN_UID}-weblogic-domain-pvc -n $NAMESPACE
2335+
2336+
local count=`kubectl get pv $DOMAIN_UID-weblogic-domain-pv -n $NAMESPACE |grep "^$DOMAIN_UID " | wc -l `
2337+
if [ ${count:=Error} != 0 ] ; then
2338+
fail "ERROR: pv for $DOMAIN_UID still exists after the pvc is deleted, exiting!"
2339+
fi
2340+
2341+
declare_test_pass
2342+
}
2343+
23132344
# scale domain $1 up and down, and optionally verify the scaling had no effect on domain $2
23142345
function test_cluster_scale {
23152346
declare_new_test 1 "$@"
@@ -2524,10 +2555,10 @@ function test_suite_init {
25242555
# 777 is needed because this script, k8s pods, and/or jobs may need access.
25252556

25262557
/usr/local/packages/aime/ias/run_as_root "mkdir -p $RESULT_ROOT/acceptance_test_tmp"
2527-
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_tmp"
2558+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULT_ROOT/acceptance_test_tmp"
25282559

25292560
/usr/local/packages/aime/ias/run_as_root "mkdir -p $RESULT_ROOT/acceptance_test_tmp_archive"
2530-
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_tmp_archive"
2561+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULT_ROOT/acceptance_test_tmp_archive"
25312562

25322563
/usr/local/packages/aime/ias/run_as_root "mkdir -p $PV_ROOT/acceptance_test_pv"
25332564
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_pv"
@@ -2595,6 +2626,7 @@ function test_suite {
25952626
dom_define domain3 oper1 test1 domain3 AUTO cluster-1 managed-server 7021 30041 30703 8031 30307 30317
25962627
dom_define domain4 oper2 test2 domain4 AUTO cluster-1 managed-server 7041 30051 30704 8041 30308 30318
25972628
dom_define domain5 oper1 default domain5 ADMIN cluster-1 managed-server 7051 30061 30705 8051 30309 30319
2629+
dom_define domain6 oper1 default domain6 AUTO cluster-1 managed-server 7061 30071 30706 8061 30310 30320
25982630

25992631
# create namespaces for domains (the operator job creates a namespace if needed)
26002632
# 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
@@ -2659,9 +2691,12 @@ function test_suite {
26592691
# cycle domain1 down and back up, plus verify no impact on domain4
26602692
test_domain_lifecycle domain1 domain4
26612693

2662-
# create another domain in the default namespace with startupControl="ADMIN", and verify that only admin server is created
2694+
# create domain5 in the default namespace with startupControl="ADMIN", and verify that only admin server is created
26632695
test_create_domain_startup_control_admin domain5
26642696

2697+
# create domain6 in the default namespace with pvReclaimPolicy="Recycle", and verify that the PV is deleted once the domain and PVC are deleted
2698+
test_create_domain_pv_reclaim_policy_recycle domain6
2699+
26652700
# test managed server 1 pod auto-restart
26662701
test_wls_liveness_probe domain1
26672702

src/main/java/oracle/kubernetes/operator/Main.java

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ else if (StartupControlConstants.AUTO_STARTUPCONTROL.equals(sc)) {
903903
info.setServerStartupInfo(ssic);
904904
LOGGER.exiting();
905905
return doNext(scaleDownIfNecessary(info, servers,
906-
checkServerServices(info, new ManagedServerUpIteratorStep(ssic, next))),
906+
new ClusterServicesStep(info, new ManagedServerUpIteratorStep(ssic, next))),
907907
packet);
908908
case StartupControlConstants.ADMIN_STARTUPCONTROL:
909909
case StartupControlConstants.NONE_STARTUPCONTROL:
@@ -912,7 +912,7 @@ else if (StartupControlConstants.AUTO_STARTUPCONTROL.equals(sc)) {
912912
info.setServerStartupInfo(null);
913913
LOGGER.exiting();
914914
return doNext(scaleDownIfNecessary(info, servers,
915-
checkServerServices(info, next)),
915+
new ClusterServicesStep(info, next)),
916916
packet);
917917
}
918918
}
@@ -949,84 +949,18 @@ private static List<V1EnvVar> startInAdminMode(List<V1EnvVar> env) {
949949
return env;
950950
}
951951

952-
private static Step checkServerServices(DomainPresenceInfo info, Step next) {
953-
Collection<String> allServers = new ArrayList<>();
954-
Collection<ServerStartupInfo> ssic = new ArrayList<>();
955-
956-
WlsDomainConfig scan = info.getScan();
957-
958-
// Iterate all servers
959-
for (WlsClusterConfig wlsClusterConfig : scan.getClusterConfigs().values()) {
960-
for (WlsServerConfig wlsServerConfig : wlsClusterConfig.getServerConfigs()) {
961-
String serverName = wlsServerConfig.getListenAddress();
962-
if (!allServers.contains(serverName)) {
963-
allServers.add(serverName);
964-
ssic.add(new ServerStartupInfo(wlsServerConfig, wlsClusterConfig, null, null));
965-
}
966-
}
967-
}
968-
for (Map.Entry<String, WlsServerConfig> wlsServerConfig : scan.getServerConfigs().entrySet()) {
969-
String serverName = wlsServerConfig.getKey();
970-
if (!allServers.contains(serverName)) {
971-
allServers.add(serverName);
972-
ssic.add(new ServerStartupInfo(wlsServerConfig.getValue(), null, null, null));
973-
}
974-
}
975-
976-
return new ManagedServerServicesStep(info, ssic, next);
977-
}
978-
979-
private static class ManagedServerServicesStep extends Step {
952+
private static class ClusterServicesStep extends Step {
980953
private final DomainPresenceInfo info;
981-
private final Collection<ServerStartupInfo> ssic;
982954

983-
public ManagedServerServicesStep(DomainPresenceInfo info, Collection<ServerStartupInfo> ssic, Step next) {
955+
public ClusterServicesStep(DomainPresenceInfo info, Step next) {
984956
super(next);
985957
this.info = info;
986-
this.ssic = ssic;
987958
}
988959

989960
@Override
990961
public NextAction apply(Packet packet) {
991962
Collection<StepAndPacket> startDetails = new ArrayList<>();
992963

993-
for (ServerStartupInfo ssi : ssic) {
994-
Packet p = packet.clone();
995-
WlsServerConfig serverConfig = ssi.serverConfig;
996-
ServerStartup serverStartup = ssi.serverStartup;
997-
String serverName = serverConfig.getName();
998-
p.put(ProcessingConstants.SERVER_SCAN, serverConfig);
999-
p.put(ProcessingConstants.CLUSTER_SCAN, ssi.clusterConfig);
1000-
p.put(ProcessingConstants.ENVVARS, ssi.envVars);
1001-
1002-
DomainSpec spec = info.getDomain().getSpec();
1003-
Integer nodePort = null;
1004-
if (serverStartup == null) {
1005-
List<ServerStartup> ssl = spec.getServerStartup();
1006-
if (ssl != null) {
1007-
for (ServerStartup ss : ssl) {
1008-
if (serverName.equals(ss.getServerName())) {
1009-
serverStartup = ss;
1010-
break;
1011-
}
1012-
}
1013-
}
1014-
}
1015-
1016-
if (serverStartup != null) {
1017-
nodePort = serverStartup.getNodePort();
1018-
}
1019-
1020-
p.put(ProcessingConstants.SERVER_NAME, serverName);
1021-
if (ssi.clusterConfig != null) {
1022-
p.put(ProcessingConstants.CLUSTER_NAME, ssi.clusterConfig.getClusterName());
1023-
}
1024-
p.put(ProcessingConstants.PORT, serverConfig.getListenPort());
1025-
p.put(ProcessingConstants.NODE_PORT, nodePort);
1026-
1027-
startDetails.add(new StepAndPacket(ServiceHelper.createForServerStep(null), p));
1028-
}
1029-
1030964
// Add cluster services
1031965
WlsDomainConfig scan = info.getScan();
1032966
if (scan != null) {
@@ -1100,6 +1034,11 @@ public NextAction apply(Packet packet) {
11001034
p.put(ProcessingConstants.CLUSTER_SCAN, ssi.clusterConfig);
11011035
p.put(ProcessingConstants.ENVVARS, ssi.envVars);
11021036

1037+
p.put(ProcessingConstants.SERVER_NAME, ssi.serverConfig.getName());
1038+
p.put(ProcessingConstants.PORT, ssi.serverConfig.getListenPort());
1039+
ServerStartup ss = ssi.serverStartup;
1040+
p.put(ProcessingConstants.NODE_PORT, ss != null ? ss.getNodePort() : null);
1041+
11031042
startDetails.add(new StepAndPacket(bringManagedServerUp(ssi, null), p));
11041043
}
11051044

@@ -1202,7 +1141,9 @@ public ServerDownStep(String serverName, ServerKubernetesObjects sko, Step next)
12021141

12031142
@Override
12041143
public NextAction apply(Packet packet) {
1205-
return doNext(PodHelper.deletePodStep(sko, new ServerDownFinalizeStep(serverName, next)), packet);
1144+
return doNext(PodHelper.deletePodStep(sko,
1145+
ServiceHelper.deleteServiceStep(sko,
1146+
new ServerDownFinalizeStep(serverName, next))), packet);
12061147
}
12071148
}
12081149

@@ -1228,7 +1169,8 @@ public NextAction apply(Packet packet) {
12281169
// "clusterScan"
12291170
// "envVars"
12301171
private static Step bringManagedServerUp(ServerStartupInfo ssi, Step next) {
1231-
return PodHelper.createManagedPodStep(next);
1172+
return PodHelper.createManagedPodStep(
1173+
ServiceHelper.createForServerStep(next));
12321174
}
12331175

12341176
private static void deleteDomainPresence(Domain dom) {

src/main/java/oracle/kubernetes/operator/helpers/ServiceHelper.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,56 @@ public NextAction onSuccess(Packet packet, V1Service result, int statusCode,
161161
}
162162
}
163163

164+
/**
165+
* Factory for {@link Step} that deletes per-managed server service
166+
* @param sko Server Kubernetes Objects
167+
* @param next Next processing step
168+
* @return Step for deleting per-managed server service
169+
*/
170+
public static Step deleteServiceStep(ServerKubernetesObjects sko, Step next) {
171+
return new DeleteServiceStep(sko, next);
172+
}
173+
174+
private static class DeleteServiceStep extends Step {
175+
private final ServerKubernetesObjects sko;
176+
177+
public DeleteServiceStep(ServerKubernetesObjects sko, Step next) {
178+
super(next);
179+
this.sko = sko;
180+
}
181+
182+
@Override
183+
public NextAction apply(Packet packet) {
184+
DomainPresenceInfo info = packet.getSPI(DomainPresenceInfo.class);
185+
186+
Domain dom = info.getDomain();
187+
V1ObjectMeta meta = dom.getMetadata();
188+
String namespace = meta.getNamespace();
189+
190+
// Set service to null so that watcher doesn't try to recreate service
191+
V1Service oldService = sko.getService().getAndSet(null);
192+
if (oldService != null) {
193+
return doNext(CallBuilder.create().deleteServiceAsync(oldService.getMetadata().getName(), namespace, new ResponseStep<V1Status>(next) {
194+
@Override
195+
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
196+
Map<String, List<String>> responseHeaders) {
197+
if (statusCode == CallBuilder.NOT_FOUND) {
198+
return onSuccess(packet, null, statusCode, responseHeaders);
199+
}
200+
return super.onFailure(packet, e, statusCode, responseHeaders);
201+
}
202+
203+
@Override
204+
public NextAction onSuccess(Packet packet, V1Status result, int statusCode,
205+
Map<String, List<String>> responseHeaders) {
206+
return doNext(next, packet);
207+
}
208+
}), packet);
209+
}
210+
return doNext(packet);
211+
}
212+
}
213+
164214
/**
165215
* Create asynchronous step for internal cluster service
166216
* @param next Next processing step

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
}

0 commit comments

Comments
 (0)