Skip to content

Commit 5794f45

Browse files
kizuna-lekapecloud-bot
authored andcommitted
chore: use kb-tools as pg config-manager image (#2277)
(cherry picked from commit 820d61a)
1 parent c43cf39 commit 5794f45

File tree

2 files changed

+23
-44
lines changed

2 files changed

+23
-44
lines changed

addons/postgresql/reloader/update-parameter.sh

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,49 @@
1-
#!/bin/bash
2-
set -euo pipefail
1+
#!/bin/sh
2+
set -eu
33

44
parse_yaml_array() {
5-
local file="$1"
6-
[[ -f "$file" ]] && grep "^- " "$file" | sed 's/^- //' | sed 's/^["'\'']//' | sed 's/["'\'']$//'
5+
file="$1"
6+
[ -f "$file" ] && grep "^- " "$file" | sed 's/^- //' | sed 's/^["'\'']//' | sed 's/["'\'']$//'
77
}
88

99
in_array() {
10-
local target="$1"
10+
target="$1"
1111
shift
12-
for item in "$@"; do
13-
[[ "$item" == "$target" ]] && return 0
14-
done
15-
return 1
16-
}
17-
18-
build_json_with_jq() {
19-
local json="{}"
12+
items="$*"
2013

21-
for key in "${!patroni_dict[@]}"; do
22-
json=$(echo "$json" | jq --arg k "$key" --arg v "${patroni_dict[$key]}" '. + {($k): $v}')
14+
for item in $items; do
15+
[ "$item" = "$target" ] && return 0
2316
done
24-
25-
if [[ ${#postgresql_dict[@]} -gt 0 ]]; then
26-
local pg_params="{}"
27-
for key in "${!postgresql_dict[@]}"; do
28-
pg_params=$(echo "$pg_params" | jq --arg k "$key" --arg v "${postgresql_dict[$key]}" '. + {($k): $v}')
29-
done
30-
json=$(echo "$json" | jq --argjson params "$pg_params" '. + {postgresql: {parameters: $params}}')
31-
fi
32-
33-
echo "$json"
17+
return 1
3418
}
3519

36-
BOOTSTRAP_FILE="./restart-parameter.yaml"
37-
PATRONI_PARAMS_FILE="./patroni-parameter.yaml"
20+
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
21+
BOOTSTRAP_FILE="${SCRIPT_DIR}/restart-parameter.yaml"
22+
PATRONI_PARAMS_FILE="${SCRIPT_DIR}/patroni-parameter.yaml"
3823

39-
mapfile -t restart_params < <(parse_yaml_array "$BOOTSTRAP_FILE")
40-
mapfile -t patroni_params < <(parse_yaml_array "$PATRONI_PARAMS_FILE")
24+
restart_params=$(parse_yaml_array "$BOOTSTRAP_FILE")
25+
patroni_params=$(parse_yaml_array "$PATRONI_PARAMS_FILE")
4126

4227
command="reload"
4328
paramName="${1:?missing param name}"
4429
paramValue="${2:?missing value}"
45-
paramValue="${paramValue//\'/}"
30+
paramValue=$(echo "$paramValue" | sed "s/'//g")
4631

47-
declare -A patroni_dict
48-
declare -A postgresql_dict
49-
if in_array "$paramName" "${patroni_params[@]}"; then
50-
patroni_dict["$paramName"]="$paramValue"
32+
json_params="{}"
33+
if in_array "$paramName" "$patroni_params"; then
34+
json_params=$(echo "$json_params" | jq --arg k "$paramName" --arg v "$paramValue" '. + {($k): $v}')
5135
else
52-
postgresql_dict["$paramName"]="$paramValue"
36+
pg_params=$(echo "{}" | jq --arg k "$paramName" --arg v "$paramValue" '. + {($k): $v}')
37+
json_params=$(echo "$json_params" | jq --argjson params "$pg_params" '. + {postgresql: {parameters: $params}}')
5338
fi
5439

55-
in_array "$paramName" "${restart_params[@]}" && command="restart"
40+
in_array "$paramName" "$restart_params" && command="restart"
5641

57-
json_params=$(build_json_with_jq)
5842
curl -s -X PATCH -H "Content-Type: application/json" \
5943
--data "$json_params" \
6044
"http://localhost:8008/config"
6145

62-
if [[ "$command" == "restart" ]]; then
46+
if [ "$command" = "restart" ]; then
6347
curl -s -X POST "http://localhost:8008/restart"
6448
else
6549
curl -s -X POST "http://localhost:8008/reload"

addons/postgresql/templates/paramsdef.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ spec:
2020
scriptConfig:
2121
scriptConfigMapRef: {{ include "postgresql.patroniReloadScriptsTemplate" $ }}
2222
namespace: {{ $.Release.Namespace }}
23-
toolsSetup:
24-
mountPoint: /kb_tools
25-
toolConfigs:
26-
- name: kb-tools
27-
image: {{ $.Values.image.registry | default "docker.io" }}/{{ $.Values.image.repository }}:{{ (index .minors 0).tag }}
28-
asContainerImage: true
23+
2924
## update patroni master
3025
targetPodSelector:
3126
matchLabels:

0 commit comments

Comments
 (0)