Skip to content

Commit ccf5839

Browse files
pooknullhors
andauthored
K8SPSMDB-1531: add hookScript (#2155)
* K8SPSMDB-1531: add `hookScript` https://perconadev.atlassian.net/browse/K8SPSMDB-1531 * fix cr.yaml * add hookscript to pbm agent * add `hookScript` to `.spec.backup` * `make manifests` * fix syntax highlighting * add e2e test * address comments * update hookScript structure * goimports-reviser * fix unit-test --------- Co-authored-by: Viacheslav Sarzhan <slava.sarzhan@percona.com>
1 parent 0443a5f commit ccf5839

34 files changed

+1258
-305
lines changed

build/pbm-entry.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ if [[ -z ${PBM_AGENT_TLS_ENABLED} ]] || [[ ${PBM_AGENT_TLS_ENABLED} == "true" ]]
77
fi
88
fi
99

10+
# shellcheck disable=SC1091
11+
test -e /opt/percona/pbm-hookscript/hook.sh && source /opt/percona/pbm-hookscript/hook.sh
12+
1013
exec "$@"

build/ps-entry.sh

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ _mongod_hack_have_arg() {
6868
local arg
6969
for arg; do
7070
case "$arg" in
71-
"$checkArg" | "$checkArg"=*)
72-
return 0
73-
;;
71+
"$checkArg" | "$checkArg"=*)
72+
return 0
73+
;;
7474
esac
7575
done
7676
return 1
@@ -83,14 +83,14 @@ _mongod_hack_get_arg_val() {
8383
local arg="$1"
8484
shift
8585
case "$arg" in
86-
"$checkArg")
87-
echo "$1"
88-
return 0
89-
;;
90-
"$checkArg"=*)
91-
echo "${arg#"$checkArg"=}"
92-
return 0
93-
;;
86+
"$checkArg")
87+
echo "$1"
88+
return 0
89+
;;
90+
"$checkArg"=*)
91+
echo "${arg#"$checkArg"=}"
92+
return 0
93+
;;
9494
esac
9595
done
9696
return 1
@@ -131,14 +131,14 @@ _mongod_hack_ensure_no_arg_val() {
131131
local arg="$1"
132132
shift
133133
case "$arg" in
134-
"$ensureNoArg")
135-
shift # also skip the value
136-
continue
137-
;;
138-
"$ensureNoArg"=*)
139-
# value is already included
140-
continue
141-
;;
134+
"$ensureNoArg")
135+
shift # also skip the value
136+
continue
137+
;;
138+
"$ensureNoArg"=*)
139+
# value is already included
140+
continue
141+
;;
142142
esac
143143
mongodHackedArgs+=("$arg")
144144
done
@@ -174,7 +174,7 @@ _mongod_hack_rename_arg_save_val() {
174174
val="$1"
175175
shift
176176
continue
177-
elif [[ $arg =~ "$oldArg"=(.*) ]]; then
177+
elif [[ $arg =~ ^${oldArg}=(.*)$ ]]; then
178178
val=${BASH_REMATCH[1]}
179179
continue
180180
fi
@@ -282,10 +282,10 @@ if [ "$originalArgOne" = 'mongod' ]; then
282282
# if we've got any /docker-entrypoint-initdb.d/* files to parse later, we should initdb
283283
for f in /docker-entrypoint-initdb.d/*; do
284284
case "$f" in
285-
*.sh | *.js) # this should match the set of files we check for below
286-
shouldPerformInitdb="$f"
287-
break
288-
;;
285+
*.sh | *.js) # this should match the set of files we check for below
286+
shouldPerformInitdb="$f"
287+
break
288+
;;
289289
esac
290290
done
291291
fi
@@ -387,17 +387,17 @@ if [ "$originalArgOne" = 'mongod' ]; then
387387
echo
388388
for f in /docker-entrypoint-initdb.d/*; do
389389
case "$f" in
390-
*.sh)
391-
echo "$0: running $f"
392-
# shellcheck source=/dev/null
393-
. "$f"
394-
;;
395-
*.js)
396-
echo "$0: running $f"
397-
"${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"
398-
echo
399-
;;
400-
*) echo "$0: ignoring $f" ;;
390+
*.sh)
391+
echo "$0: running $f"
392+
# shellcheck source=/dev/null
393+
. "$f"
394+
;;
395+
*.js)
396+
echo "$0: running $f"
397+
"${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"
398+
echo
399+
;;
400+
*) echo "$0: ignoring $f" ;;
401401
esac
402402
echo
403403
done
@@ -509,5 +509,8 @@ fi
509509

510510
rm -f "$jsonConfigFile" "$tempConfigFile"
511511

512+
# shellcheck disable=SC1091
513+
test -e /opt/percona/hookscript/hook.sh && source /opt/percona/hookscript/hook.sh
514+
512515
set -o xtrace
513516
exec "$@"

config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ spec:
163163
type: object
164164
enabled:
165165
type: boolean
166+
hookScript:
167+
properties:
168+
configMapRef:
169+
properties:
170+
name:
171+
type: string
172+
type: object
173+
script:
174+
type: string
175+
type: object
166176
image:
167177
type: string
168178
labels:
@@ -1895,6 +1905,16 @@ spec:
18951905
type: object
18961906
enabled:
18971907
type: boolean
1908+
hookScript:
1909+
properties:
1910+
configMapRef:
1911+
properties:
1912+
name:
1913+
type: string
1914+
type: object
1915+
script:
1916+
type: string
1917+
type: object
18981918
labels:
18991919
additionalProperties:
19001920
type: string
@@ -4499,6 +4519,16 @@ spec:
44994519
type: object
45004520
enabled:
45014521
type: boolean
4522+
hookScript:
4523+
properties:
4524+
configMapRef:
4525+
properties:
4526+
name:
4527+
type: string
4528+
type: object
4529+
script:
4530+
type: string
4531+
type: object
45024532
labels:
45034533
additionalProperties:
45044534
type: string
@@ -6693,6 +6723,16 @@ spec:
66936723
- enabled
66946724
- size
66956725
type: object
6726+
hookScript:
6727+
properties:
6728+
configMapRef:
6729+
properties:
6730+
name:
6731+
type: string
6732+
type: object
6733+
script:
6734+
type: string
6735+
type: object
66966736
hostAliases:
66976737
items:
66986738
properties:
@@ -7326,6 +7366,16 @@ spec:
73267366
type: object
73277367
enabled:
73287368
type: boolean
7369+
hookScript:
7370+
properties:
7371+
configMapRef:
7372+
properties:
7373+
name:
7374+
type: string
7375+
type: object
7376+
script:
7377+
type: string
7378+
type: object
73297379
labels:
73307380
additionalProperties:
73317381
type: string
@@ -12684,6 +12734,16 @@ spec:
1268412734
type: object
1268512735
enabled:
1268612736
type: boolean
12737+
hookScript:
12738+
properties:
12739+
configMapRef:
12740+
properties:
12741+
name:
12742+
type: string
12743+
type: object
12744+
script:
12745+
type: string
12746+
type: object
1268712747
labels:
1268812748
additionalProperties:
1268912749
type: string
@@ -15288,6 +15348,16 @@ spec:
1528815348
type: object
1528915349
enabled:
1529015350
type: boolean
15351+
hookScript:
15352+
properties:
15353+
configMapRef:
15354+
properties:
15355+
name:
15356+
type: string
15357+
type: object
15358+
script:
15359+
type: string
15360+
type: object
1529115361
labels:
1529215362
additionalProperties:
1529315363
type: string
@@ -17482,6 +17552,16 @@ spec:
1748217552
- enabled
1748317553
- size
1748417554
type: object
17555+
hookScript:
17556+
properties:
17557+
configMapRef:
17558+
properties:
17559+
name:
17560+
type: string
17561+
type: object
17562+
script:
17563+
type: string
17564+
type: object
1748517565
hostAliases:
1748617566
items:
1748717567
properties:
@@ -18115,6 +18195,16 @@ spec:
1811518195
type: object
1811618196
enabled:
1811718197
type: boolean
18198+
hookScript:
18199+
properties:
18200+
configMapRef:
18201+
properties:
18202+
name:
18203+
type: string
18204+
type: object
18205+
script:
18206+
type: string
18207+
type: object
1811818208
labels:
1811918209
additionalProperties:
1812018210
type: string
@@ -23156,6 +23246,16 @@ spec:
2315623246
type:
2315723247
type: string
2315823248
type: object
23249+
hookScript:
23250+
properties:
23251+
configMapRef:
23252+
properties:
23253+
name:
23254+
type: string
23255+
type: object
23256+
script:
23257+
type: string
23258+
type: object
2315923259
hostAliases:
2316023260
items:
2316123261
properties:

0 commit comments

Comments
 (0)