Skip to content

OWLS 85938 - Server lifecycle script changes to use domain.status.minimumReplicas when stopping/starting server #2042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions kubernetes/samples/scripts/domain-lifecycle/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ function createServerStartPolicyPatch {
local serverName=$2
local policy=$3
local __result=$4
local currentServerStartPolicy=""
local currentStartPolicy=""

# Get server start policy for this server
getServerPolicy "${domainJson}" "${serverName}" currentServerStartPolicy
if [ -z "${currentServerStartPolicy}" ]; then
getServerPolicy "${domainJson}" "${serverName}" currentStartPolicy
if [ -z "${currentStartPolicy}" ]; then
# Server start policy doesn't exist, add a new policy
addPolicyCmd=".[.| length] |= . + {\"serverName\":\"${serverName}\", \
\"serverStartPolicy\":\"${policy}\"}"
Expand Down Expand Up @@ -319,6 +319,12 @@ function getReplicaCount {
if [[ -z "${replicaCount}" || "${replicaCount}" == "null" ]]; then
replicaCount=0
fi
# check if replica count is less than minimum replicas
getMinReplicas "${domainJson}" "${clusterName}" minReplicas
if [ "${replicaCount}" -lt "${minReplicas}" ]; then
# Reset current replica count to minimum replicas
replicaCount=${minReplicas}
fi
eval $__replicaCount="'${replicaCount}'"

}
Expand Down Expand Up @@ -407,6 +413,44 @@ function shouldStart {
fi
}

#
# Function to check if cluster's replica count is same as min replicas
# $1 - Domain resource in json format
# $2 - Name of the cluster
# $3 - Returns "true" or "false" indicating if replica count is equal to
# or greater than min replicas.
#
function isReplicaCountEqualToMinReplicas {
local domainJson=$1
local clusterName=$2
local __result=$3

eval $__result=false
getMinReplicas "${domainJson}" "${clusterName}" minReplicas
getReplicaCount "${domainJson}" "${clusterName}" replica
if [ ${replica} -eq ${minReplicas} ]; then
eval $__result=true
fi
}

#
# Function to get minimum replica count for cluster
# $1 - Domain resource in json format
# $2 - Name of the cluster
# $3 - Return value containing minimum replica count
#
function getMinReplicas {
local domainJson=$1
local clusterName=$2
local __result=$3

eval $__result=0
minReplicaCmd="(.status.clusters[] | select (.clusterName == \"${clusterName}\")) \
| .minimumReplicas"
minReplicas=$(echo ${domainJson} | jq "${minReplicaCmd}")
eval $__result=${minReplicas}
}

#
# Function to create patch string for updating replica count
# $1 - Domain resource in json format
Expand All @@ -431,9 +475,6 @@ Not increasing replica count value."
getReplicaCount "${domainJson}" "${clusterName}" replica
if [ "${operation}" == "DECREMENT" ]; then
replica=$((replica-1))
if [ ${replica} -lt 0 ]; then
replica=0
fi
elif [ "${operation}" == "INCREMENT" ]; then
maxReplicas=$(echo ${domainJson} | jq "${maxReplicaCmd}")
if [ ${replica} -ge ${maxReplicas} ]; then
Expand Down
12 changes: 12 additions & 0 deletions kubernetes/samples/scripts/domain-lifecycle/stopServer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ serverStarted=""
effectivePolicy=""
managedServerPolicy=""
stoppedWhenAlwaysPolicyReset=""
replicasEqualsMinReplicas=""
withReplicas="CONSTANT"
withPolicy="CONSTANT"

Expand Down Expand Up @@ -153,6 +154,17 @@ else
fi
fi

if [[ -n "${clusterName}" && "${keepReplicaConstant}" == 'false' ]]; then
# check if replica count can decrease below current value
isReplicaCountEqualToMinReplicas "${domainJson}" "${clusterName}" replicasEqualsMinReplicas
if [ "${replicasEqualsMinReplicas}" == 'true' ]; then
printInfo "Not decreasing the replica count value: it is at its minimum. \
(See 'domain.spec.allowReplicasBelowMinDynClusterSize' and \
'domain.status.clusters[].minimumReplicas' for details)."
keepReplicaConstant=true
fi
fi

# Create server start policy patch with NEVER value
createServerStartPolicyPatch "${domainJson}" "${serverName}" "${serverStartPolicy}" neverStartPolicyPatch
getServerPolicy "${domainJson}" "${serverName}" managedServerPolicy
Expand Down