Skip to content

Owls 87209 - Domain lifecycle scripts fix in cases where domain/cluster specs are overridden at the individual managed server level #2222

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 4 commits into from
Feb 24, 2021
Merged
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
44 changes: 37 additions & 7 deletions kubernetes/samples/scripts/domain-lifecycle/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,24 @@ function createServerStartPolicyPatch {
local policy=$3
local __result=$4
local currentStartPolicy=""
local serverStartPolicyPatch=""

# Get server start policy for this server
getServerPolicy "${domainJson}" "${serverName}" currentStartPolicy
if [ -z "${currentStartPolicy}" ]; then
managedServers=$(echo ${domainJson} | jq -cr '(.spec.managedServers)')
if [[ -z "${currentStartPolicy}" && "${managedServers}" == "null" ]]; then
# Server start policy doesn't exist, add a new policy
addPolicyCmd=".[.| length] |= . + {\"serverName\":\"${serverName}\", \
\"serverStartPolicy\":\"${policy}\"}"
serverStartPolicyPatch=$(echo ${domainJson} | jq .spec.managedServers | jq -c "${addPolicyCmd}")
elif [ "${managedServers}" != "null" ]; then
extractSpecCmd="(.spec.managedServers)"
mapCmd="\
. |= (map(.serverName) | index (\"${serverName}\")) as \$idx | \
if \$idx then \
.[\$idx][\"serverStartPolicy\"] = \"${policy}\" \
else .+ [{serverName: \"${serverName}\" , serverStartPolicy: \"${policy}\"}] end"
serverStartPolicyPatch=$(echo ${domainJson} | jq "${extractSpecCmd}" | jq "${mapCmd}")
else
# Server start policy exists, replace policy value
replacePolicyCmd="(.spec.managedServers[] \
Expand All @@ -142,9 +152,7 @@ function createPatchJsonToUnsetPolicyAndUpdateReplica {
local replicaPatch=$3
local __result=$4

replacePolicyCmd="[(.spec.managedServers[] \
| select (.serverName != \"${serverName}\"))]"
serverStartPolicyPatch=$(echo ${domainJson} | jq "${replacePolicyCmd}")
unsetServerStartPolicy "${domainJson}" "${serverName}" serverStartPolicyPatch
patchJson="{\"spec\": {\"clusters\": "${replicaPatch}",\"managedServers\": "${serverStartPolicyPatch}"}}"
eval $__result="'${patchJson}'"
}
Expand Down Expand Up @@ -199,13 +207,35 @@ function createPatchJsonToUnsetPolicy {
local serverName=$2
local __result=$3

replacePolicyCmd="[(.spec.managedServers[] \
| select (.serverName != \"${serverName}\"))]"
serverStartPolicyPatch=$(echo ${domainJson} | jq "${replacePolicyCmd}")
unsetServerStartPolicy "${domainJson}" "${serverName}" serverStartPolicyPatch
patchJson="{\"spec\": {\"managedServers\": "${serverStartPolicyPatch}"}}"
eval $__result="'${patchJson}'"
}

#
# Function to create patch string with server start policy unset
# $1 - Domain resource in json format
# $2 - Name of server whose policy will be unset
# $3 - Return value containing patch string with server start policy unset
#
function unsetServerStartPolicy {
local domainJson=$1
local serverName=$2
local __result=$3
local unsetStartPolicyPatch=""

unsetCmd="(.spec.managedServers[] | select (.serverName == \"${serverName}\") | del (.serverStartPolicy))"
replacePolicyCmd=$(echo ${domainJson} | jq -cr "${unsetCmd}")
replacePolicyCmdLen=$(echo "${replacePolicyCmd}" | jq -e keys_unsorted | jq length)
if [ ${replacePolicyCmdLen} == 1 ]; then
mapCmd=". |= map(if .serverName == \"${serverName}\" then del(.) else . end)"
else
mapCmd=". |= map(if .serverName == \"${serverName}\" then . = ${replacePolicyCmd} else . end)"
fi
unsetStartPolicyPatch=$(echo ${domainJson} | jq "(.spec.managedServers)" | jq "${mapCmd}")
eval $__result="'${unsetStartPolicyPatch}'"
}

#
# Function to create patch json to update cluster server start policy
# $1 - Domain resource in json format
Expand Down