chore(cassandra): run verified artifact copy
This commit is contained in:
parent
7bff060389
commit
6706662737
@ -7,7 +7,7 @@ metadata:
|
||||
labels:
|
||||
app: cassandra-backend
|
||||
spec:
|
||||
replicas: 1
|
||||
replicas: 0
|
||||
revisionHistoryLimit: 2
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: cassandra-artifact-copy-from-veles-1
|
||||
name: cassandra-artifact-copy-from-veles-2
|
||||
namespace: cassandra
|
||||
spec:
|
||||
suspend: true
|
||||
suspend: false
|
||||
backoffLimit: 0
|
||||
activeDeadlineSeconds: 43200
|
||||
ttlSecondsAfterFinished: 86400
|
||||
@ -33,6 +33,8 @@ spec:
|
||||
value: /dest
|
||||
- name: ALLOW_NONEMPTY_DEST
|
||||
value: "0"
|
||||
- name: RESET_DESTINATION
|
||||
value: "1"
|
||||
command: ["python", "-c"]
|
||||
args:
|
||||
- |
|
||||
@ -42,12 +44,15 @@ spec:
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tarfile
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
SOURCE_URL = os.environ["SOURCE_URL"].rstrip("/")
|
||||
DEST = Path(os.environ.get("DEST_ROOT", "/dest")).resolve()
|
||||
ALLOW_NONEMPTY = os.environ.get("ALLOW_NONEMPTY_DEST", "") in {"1", "true", "yes"}
|
||||
RESET_DESTINATION = os.environ.get("RESET_DESTINATION", "") in {"1", "true", "yes"}
|
||||
EXCLUDE_TOP = {"lost+found", ".cassandra-artifact-migration"}
|
||||
REPORT_DIR = DEST / ".cassandra-artifact-migration"
|
||||
|
||||
@ -57,6 +62,13 @@ spec:
|
||||
def assert_safe_destination() -> None:
|
||||
DEST.mkdir(parents=True, exist_ok=True)
|
||||
entries = visible_entries()
|
||||
if entries and RESET_DESTINATION:
|
||||
for entry in entries:
|
||||
if entry.is_dir():
|
||||
shutil.rmtree(entry)
|
||||
else:
|
||||
entry.unlink()
|
||||
entries = visible_entries()
|
||||
if entries and not ALLOW_NONEMPTY:
|
||||
names = ", ".join(entry.name for entry in entries[:10])
|
||||
raise SystemExit(f"destination is not empty; refusing to merge into existing data: {names}")
|
||||
@ -66,6 +78,16 @@ spec:
|
||||
with urllib.request.urlopen(f"{SOURCE_URL}/manifest.json", timeout=120) as response:
|
||||
return json.loads(response.read().decode())
|
||||
|
||||
def wait_for_manifest() -> dict[str, object]:
|
||||
last_error = ""
|
||||
for _attempt in range(90):
|
||||
try:
|
||||
return fetch_manifest()
|
||||
except Exception as exc:
|
||||
last_error = str(exc)
|
||||
time.sleep(5)
|
||||
raise SystemExit(f"source artifact exporter did not become ready: {last_error}")
|
||||
|
||||
def safe_extract() -> None:
|
||||
root_text = str(DEST)
|
||||
with urllib.request.urlopen(f"{SOURCE_URL}/archive.tar", timeout=600) as response:
|
||||
@ -116,7 +138,7 @@ spec:
|
||||
}
|
||||
|
||||
assert_safe_destination()
|
||||
source = fetch_manifest()
|
||||
source = wait_for_manifest()
|
||||
(REPORT_DIR / "source_manifest.json").write_text(json.dumps(source, indent=2, sort_keys=True))
|
||||
safe_extract()
|
||||
dest = destination_manifest()
|
||||
|
||||
@ -20,7 +20,7 @@ metadata:
|
||||
name: veles-artifact-export-for-cassandra
|
||||
namespace: veles
|
||||
spec:
|
||||
replicas: 0
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: veles-artifact-export-for-cassandra
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user