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