Skip to content

Commit a7ecff0

Browse files
committed
Merge branch 'shutdown-processing' into 'main'
Allow for faster shut down and don't block waiting for a shutting down instance to be ready See merge request weblogic-cloud/weblogic-kubernetes-operator!4725
2 parents c48c616 + 5630c79 commit a7ecff0

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

operator/src/main/java/oracle/kubernetes/operator/steps/ManagedServerUpIteratorStep.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static class ManagedPodReadyStep extends Step {
149149
(WlsDomainConfig) packet.get(ProcessingConstants.DOMAIN_TOPOLOGY);
150150
V1Pod managedPod = info.getServerPod(serverName);
151151

152-
if (managedPod == null || !isPodReady(managedPod)) {
152+
if (managedPod == null || (!isPodReady(managedPod) && !isPodMarkedForShutdown(managedPod))) {
153153
// requeue to wait for managed pod to be ready
154154
return doRequeue(packet);
155155
}
@@ -158,7 +158,11 @@ static class ManagedPodReadyStep extends Step {
158158
}
159159

160160
protected boolean isPodReady(V1Pod result) {
161-
return result != null && !PodHelper.isDeleting(result) && PodHelper.isReady(result);
161+
return PodHelper.isReady(result);
162+
}
163+
164+
protected boolean isPodMarkedForShutdown(V1Pod result) {
165+
return PodHelper.isDeleting(result) || PodHelper.isPodAlreadyLabeledForShutdown(result);
162166
}
163167
}
164168

operator/src/main/resources/scripts/stopServer.sh

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright (c) 2017, 2022, Oracle and/or its affiliates.
3+
# Copyright (c) 2017, 2024, Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55

66
#
@@ -46,17 +46,32 @@ export SHUTDOWN_TIMEOUT_ARG=${SHUTDOWN_TIMEOUT:-30}
4646
# Calculate the wait timeout to issue "kill -9" before the pod is destroyed.
4747
# Allow 3 seconds for the NFS v3 manager to detect the process destruction and release file locks.
4848
export SIGKILL_WAIT_TIMEOUT=$(expr $SHUTDOWN_TIMEOUT_ARG - 3)
49-
wait_and_kill_after_timeout(){
49+
50+
# Block until the given file appears or the given timeout is reached.
51+
wait_file() {
52+
local file="$1"; shift
53+
local wait_seconds="${1:-10}"; shift
54+
test $wait_seconds -lt 1 && echo 'At least 1 second is required' && return 1
55+
56+
until test $((wait_seconds--)) -eq 0 -o -e "$file" ; do sleep 1; done
57+
58+
test $wait_seconds -ge 0
59+
}
60+
61+
wait_and_kill_after_timeout() {
5062
trace "Wait for ${SIGKILL_WAIT_TIMEOUT} seconds for ${SERVER_NAME} to shut down." >> ${STOP_OUT_FILE}
5163
sleep ${SIGKILL_WAIT_TIMEOUT}
52-
trace "The server ${SERVER_NAME} didn't shut down in ${SIGKILL_WAIT_TIMEOUT} seconds, " \
53-
"killing the server processes." >> ${STOP_OUT_FILE}
54-
# Adjust PATH if necessary before calling jps
55-
adjustPath
56-
57-
#Specifically killing the NM first as it can auto-restart a killed WL server.
58-
kill -9 `jps -v | grep " NodeManager " | awk '{ print $1 }'`
59-
kill -9 `jps -v | grep -v Jps | awk '{ print $1 }'`
64+
wait_file "${SHUTDOWN_MARKER_FILE}" ${SIGKILL_WAIT_TIMEOUT} || {
65+
trace "The server ${SERVER_NAME} didn't shut down in ${SIGKILL_WAIT_TIMEOUT} seconds, " \
66+
"killing the server processes." >> ${STOP_OUT_FILE}
67+
# Adjust PATH if necessary before calling jps
68+
adjustPath
69+
70+
#Specifically killing the NM first as it can auto-restart a killed WL server.
71+
kill -9 `jps -v | grep " NodeManager " | awk '{ print $1 }'`
72+
kill -9 `jps -v | grep -v Jps | awk '{ print $1 }'`
73+
}
74+
6075
touch ${SHUTDOWN_MARKER_FILE}
6176
}
6277

@@ -106,8 +121,11 @@ check_for_shutdown() {
106121

107122

108123
# Check if the server is already shutdown
109-
check_for_shutdown
110-
[ $? -eq 0 ] && trace "Server is already shutting down, is shutdown or failed" &>> ${STOP_OUT_FILE} && exit 0
124+
if check_for_shutdown ; then
125+
trace "Server is already shutting down, is shutdown or failed" &>> ${STOP_OUT_FILE}
126+
touch ${SHUTDOWN_MARKER_FILE}
127+
exit 0
128+
fi
111129

112130
# Otherwise, connect to the node manager and stop the server instance
113131
[ ! -f "${SCRIPTPATH}/wlst.sh" ] && trace SEVERE "Missing file '${SCRIPTPATH}/wlst.sh'." && exit 1

0 commit comments

Comments
 (0)