24 lines
1.1 KiB
Python
24 lines
1.1 KiB
Python
"""Preserve reconciler-owned placement; roll when mounted configuration changes."""
|
|||
|
|
import hashlib
|
||
|
|
import json
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
import yaml
|
||
|
|
|
||
|
|
docs = list(yaml.safe_load_all(Path(sys.argv[1]).read_text()))
|
||
|
|
live_text = Path(sys.argv[2]).read_text().strip()
|
||
|
|
live = json.loads(live_text) if live_text else None
|
||
|
|
config = {d['metadata']['name']: d.get('data', {}) for d in docs if d['kind'] == 'ConfigMap' and d['metadata']['namespace'] == 'factorio'}
|
||
|
|
checksum = hashlib.sha256(json.dumps(config, sort_keys=True).encode()).hexdigest()
|
||
|
|
for doc in docs:
|
||
|
|
if doc['kind'] == 'Deployment' and doc['metadata']['name'] == 'factorio':
|
||
|
|
template = doc['spec']['template']
|
||
|
|
template['metadata'].setdefault('annotations', {})['factorio.brunner.ninja/config-revision'] = checksum
|
||
|
|
if live:
|
||
|
|
template['spec']['affinity'] = live['spec']['template']['spec']['affinity']
|
||
|
|
# The fresh PVC is an administrator bootstrap resource. CI never owns storage.
|
||
|
|
if doc['kind'] == 'PersistentVolumeClaim':
|
||
|
|
continue
|
||
|
|
print('---')
|
||
|
|
print(yaml.safe_dump(doc, sort_keys=False), end='')
|