Skip to content

Commit 1c3a149

Browse files
committed
Merge branch 'master' into feature/dynamic-cluster
2 parents 14f57e1 + 8d0db3f commit 1c3a149

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
@@ -49,6 +49,10 @@ weblogicDomainStorageType: HOST_PATH
4949
# The following line must be uncomment and customized:
5050
#weblogicDomainStoragePath: /scratch/k8s_dir/domain1
5151

52+
# Reclaim policy of the domain's persistent storage
53+
# The valid values are: 'Retain', 'Delete', and 'Recycle'
54+
weblogicDomainStorageReclaimPolicy: Retain
55+
5256
# Total storage allocated to the domain's persistent storage.
5357
weblogicDomainStorageSize: 10Gi
5458

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
@@ -771,6 +771,11 @@ function run_create_domain_job {
771771
sed -i -e "s/^configuredManagedServerCount:.*/configuredManagedServerCount: 3/" $inputs
772772
fi
773773

774+
# we will test pv reclaim policy in domain6. We choose to do this way to void adding too many parameters in dom_define
775+
if [ "$DOMAIN_UID" == "domain6" ] ; then
776+
sed -i -e "s/^weblogicDomainStorageReclaimPolicy:.*/weblogicDomainStorageReclaimPolicy: Recycle/" $inputs
777+
fi
778+
774779
local outfile="${tmp_dir}/mkdir_physical_nfs.out"
775780
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."
776781

@@ -2253,6 +2258,32 @@ function test_create_domain_startup_control_admin {
22532258
declare_test_pass
22542259
}
22552260

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

24582489
/usr/local/packages/aime/ias/run_as_root "mkdir -p $RESULT_ROOT/acceptance_test_tmp"
2459-
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_tmp"
2490+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULT_ROOT/acceptance_test_tmp"
24602491

24612492
/usr/local/packages/aime/ias/run_as_root "mkdir -p $RESULT_ROOT/acceptance_test_tmp_archive"
2462-
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_tmp_archive"
2493+
/usr/local/packages/aime/ias/run_as_root "chmod 777 $RESULT_ROOT/acceptance_test_tmp_archive"
24632494

24642495
/usr/local/packages/aime/ias/run_as_root "mkdir -p $PV_ROOT/acceptance_test_pv"
24652496
/usr/local/packages/aime/ias/run_as_root "chmod 777 $PV_ROOT/acceptance_test_pv"
@@ -2527,6 +2558,7 @@ function test_suite {
25272558
dom_define domain3 oper1 test1 domain3 AUTO cluster-1 dynamic managed-server 7021 30041 30703 8031 30307 30317
25282559
dom_define domain4 oper2 test2 domain4 AUTO cluster-1 configured managed-server 7041 30051 30704 8041 30308 30318
25292560
dom_define domain5 oper1 default domain5 ADMIN cluster-1 dynamic managed-server 7051 30061 30705 8051 30309 30319
2561+
dom_define domain6 oper1 default domain6 AUTO cluster-1 dynamic managed-server 7061 30071 30706 8061 30310 30320
25302562

25312563
# create namespaces for domains (the operator job creates a namespace if needed)
25322564
# 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
@@ -2591,9 +2623,12 @@ function test_suite {
25912623
# cycle domain1 down and back up, plus verify no impact on domain4
25922624
test_domain_lifecycle domain1 domain4
25932625

2594-
# create another domain in the default namespace with startupControl="ADMIN", and verify that only admin server is created
2626+
# create domain5 in the default namespace with startupControl="ADMIN", and verify that only admin server is created
25952627
test_create_domain_startup_control_admin domain5
25962628

2629+
# create domain6 in the default namespace with pvReclaimPolicy="Recycle", and verify that the PV is deleted once the domain and PVC are deleted
2630+
test_create_domain_pv_reclaim_policy_recycle domain6
2631+
25972632
# test managed server 1 pod auto-restart
25982633
test_wls_liveness_probe domain1
25992634

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
@@ -168,6 +168,56 @@ public NextAction onSuccess(Packet packet, V1Service result, int statusCode,
168168
}
169169
}
170170

171+
/**
172+
* Factory for {@link Step} that deletes per-managed server service
173+
* @param sko Server Kubernetes Objects
174+
* @param next Next processing step
175+
* @return Step for deleting per-managed server service
176+
*/
177+
public static Step deleteServiceStep(ServerKubernetesObjects sko, Step next) {
178+
return new DeleteServiceStep(sko, next);
179+
}
180+
181+
private static class DeleteServiceStep extends Step {
182+
private final ServerKubernetesObjects sko;
183+
184+
public DeleteServiceStep(ServerKubernetesObjects sko, Step next) {
185+
super(next);
186+
this.sko = sko;
187+
}
188+
189+
@Override
190+
public NextAction apply(Packet packet) {
191+
DomainPresenceInfo info = packet.getSPI(DomainPresenceInfo.class);
192+
193+
Domain dom = info.getDomain();
194+
V1ObjectMeta meta = dom.getMetadata();
195+
String namespace = meta.getNamespace();
196+
197+
// Set service to null so that watcher doesn't try to recreate service
198+
V1Service oldService = sko.getService().getAndSet(null);
199+
if (oldService != null) {
200+
return doNext(CallBuilder.create().deleteServiceAsync(oldService.getMetadata().getName(), namespace, new ResponseStep<V1Status>(next) {
201+
@Override
202+
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
203+
Map<String, List<String>> responseHeaders) {
204+
if (statusCode == CallBuilder.NOT_FOUND) {
205+
return onSuccess(packet, null, statusCode, responseHeaders);
206+
}
207+
return super.onFailure(packet, e, statusCode, responseHeaders);
208+
}
209+
210+
@Override
211+
public NextAction onSuccess(Packet packet, V1Status result, int statusCode,
212+
Map<String, List<String>> responseHeaders) {
213+
return doNext(next, packet);
214+
}
215+
}), packet);
216+
}
217+
return doNext(packet);
218+
}
219+
}
220+
171221
/**
172222
* Create asynchronous step for internal cluster service
173223
* @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";
@@ -48,6 +51,7 @@ public class CreateDomainInputs {
4851
private String initialManagedServerReplicas = "";
4952
private String managedServerNameBase = "";
5053
private String managedServerPort = "";
54+
private String weblogicDomainStorageReclaimPolicy = "";
5155
private String weblogicDomainStorageNFSServer = "";
5256
private String weblogicDomainStoragePath = "";
5357
private String weblogicDomainStorageSize = "";
@@ -300,6 +304,19 @@ public CreateDomainInputs weblogicDomainStorageSize(String weblogicDomainStorage
300304
return this;
301305
}
302306

307+
public String getWeblogicDomainStorageReclaimPolicy() {
308+
return weblogicDomainStorageReclaimPolicy;
309+
}
310+
311+
public void setWeblogicDomainStorageReclaimPolicy(String weblogicDomainStorageReclaimPolicy) {
312+
this.weblogicDomainStorageReclaimPolicy = convertNullToEmptyString(weblogicDomainStorageReclaimPolicy);
313+
}
314+
315+
public CreateDomainInputs weblogicDomainStorageReclaimPolicy(String weblogicDomainStorageReclaimPolicy) {
316+
setWeblogicDomainStorageReclaimPolicy(weblogicDomainStorageReclaimPolicy);
317+
return this;
318+
}
319+
303320
public String getWeblogicDomainStorageType() {
304321
return weblogicDomainStorageType;
305322
}

0 commit comments

Comments
 (0)