Skip to content

Commit ac73a7e

Browse files
committed
Merge branch 'dev' into main
2 parents ef3e24f + d0bcf70 commit ac73a7e

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode
2-
src/__pycache__
2+
src/__pycache__
3+
.scannerwork

entrypoint.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
INITPATH=$PWD/init.py
33

44
if [[ DEBUG -eq 1 ]]; then
5-
kopf run "$INITPATH" --verbose
5+
kopf run -A "$INITPATH" --verbose
66
# echo "debug"
77
elif [[ QUIET -eq 1 ]]; then
8-
kopf run "$INITPATH" --quiet
8+
kopf run -A "$INITPATH" --quiet
99
# echo "quiet"
1010
else
1111
# echo "normal"
12-
kopf run "$INITPATH"
12+
kopf run -A "$INITPATH"
1313
fi

sidecar-tool/src/init.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,6 @@ def restore_snapshot(snapshot_id):
219219
log.error(f"Failed to restore {snapshot_id}: {r.text}")
220220

221221

222-
# Fetch all snapshots and restore all of them
223-
def restore():
224-
log.info("Starting to restore snapshots...")
225-
226-
snapshot_ids = fetch_snapshots()
227-
228-
# For each snapshot, restore it
229-
for snapshot in snapshot_ids:
230-
restore_snapshot(snapshot)
231-
time.sleep(3)
232-
233-
# Delete restored snapshots
234-
delete_snapshots(snapshot_ids)
235-
236-
237222
# Check if the cluster is ready to receive requests
238223
# Return a boolean based on Monitoring API status code
239224
def check_cluster_ready():
@@ -257,6 +242,40 @@ def wait_ready_cluster():
257242
time.sleep(10)
258243

259244

245+
# Fetch all snapshots and restore all of them
246+
def restore():
247+
log.info("Starting to restore snapshots...")
248+
249+
snapshot_ids = fetch_snapshots()
250+
251+
# Move enonic cms snapshot to the end
252+
for i, snapshot in enumerate(snapshot_ids):
253+
if "com.enonic.cms" in snapshot:
254+
snapshot_ids.append(snapshot_ids.pop(i))
255+
break
256+
257+
# Move auditlog snapshot to the end
258+
for i, snapshot in enumerate(snapshot_ids):
259+
if "system.auditlog" in snapshot:
260+
snapshot_ids.append(snapshot_ids.pop(i))
261+
break
262+
263+
# Move repo snapshot to the beggining
264+
for i, snapshot in enumerate(snapshot_ids):
265+
if "system-repo" in snapshot:
266+
snapshot_ids.insert(0, snapshot_ids.pop(i))
267+
break
268+
269+
# For each snapshot, restore it
270+
for snapshot in snapshot_ids:
271+
restore_snapshot(snapshot)
272+
time.sleep(5)
273+
wait_ready_cluster()
274+
275+
# Delete restored snapshots
276+
delete_snapshots(snapshot_ids)
277+
278+
260279
# Define all tasks to be performed just on the application startup
261280
def post_start():
262281
log.debug("post_start function starting")
@@ -278,6 +297,8 @@ def post_start():
278297
# If is master then restore the snapshots
279298
if is_master:
280299
restore()
300+
time.sleep(5)
301+
wait_ready_cluster()
281302
take_snapshot()
282303
else:
283304
log.info("No need to restore snapshots.")

src/init.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import time
34

45
import kopf
56
import pykube as pk
@@ -53,6 +54,7 @@ def installed_xp_app_handler(name, namespace, logger, new, **kwargs):
5354
)
5455
parent.patch({"status": {"xp_app_handler/spec": "Failure"}})
5556
logger.error(f"{namespace}/{name} job is failing. Check the logs!")
57+
api.session.close()
5658

5759

5860
@kopf.on.create("kopf.enonic", "v1", "enonicxpapps")
@@ -77,11 +79,12 @@ def xp_app_handler(body, spec, name, namespace, logger, **kwargs):
7779
job = pk.Job.objects(api, namespace=namespace).get_by_name(name)
7880
job.delete(propagation_policy="Foreground")
7981
while job.exists():
80-
pass
82+
time.sleep(1)
8183
except pk.exceptions.ObjectDoesNotExist:
8284
pass
8385
logger.info(f"Creating installer job: {namespace}/{name}.")
8486
pk.Job(api, data).create()
87+
api.session.close()
8588

8689
return "Pending"
8790

0 commit comments

Comments
 (0)