the-custodian/docs/changes/netkingdom-target-2026-10-16/native-preflight-r1/supplement.py
codex cf59a5f9ab
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Reject generated-only commits / generated-commit-guard (push) Successful in 7s
Retain native preflight and independent signer rollout reviews
2026-10-16 21:28:42 +02:00

26 lines
2.4 KiB
Python

"""Coordinator-executed public scheduling fields only, no full Pod/env/config reads."""
import hashlib,json,subprocess
from pathlib import Path
P=Path(__file__).parent
source=(P/'preflight.py').read_text().split("if __name__=='__main__':")[0]
assert hashlib.sha256((P/'preflight.py').read_bytes()).hexdigest()=='1011e5872ebee718e969b7012b17c0737e10eaaed804e0c4ae254024d8ad5248'
source+='''
try:
nodes=query('nodes',['metadata.name','metadata.uid','status.addresses','spec.unschedulable','spec.taints','status.allocatable','status.nodeInfo.kubeletVersion'])
cluster=query('namespace',['metadata.name','metadata.uid'],name='kube-system')
rows=nodes.get('rows',[]);clusters=cluster.get('rows',[])
valid=nodes.get('ok') and cluster.get('ok') and len(clusters)==1 and clusters[0].get('metadata.uid')=='a553c742-0115-43d4-99a4-a5ca56fe0786' and any(a.get('address')=='92.205.62.239' and a.get('type') in {'InternalIP','ExternalIP'} for row in rows for a in (row.get('status.addresses') if type(row.get('status.addresses')) is list else []) if type(a) is dict)
result={'observed_at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'nodes':nodes,'cluster':cluster,'held_fence':False,'persistent_mutations':False}
if not valid:result={'refused':'target-identity','persistent_mutations':False}
else:result['pods']=query('pods',['metadata.namespace','metadata.name','metadata.uid','spec.nodeName','status.phase','spec.resources','spec.initContainers[*].restartPolicy','spec.containers[*].resources','spec.initContainers[*].resources','spec.overhead'],allns=True)
except Exception:result={'refused':'sanitized-supplement-failure'}
print(json.dumps(result))
'''
try:
r=subprocess.run(['ssh','-o','BatchMode=yes','-o','ConnectTimeout=12','railiance01','python3','-'],input=source,capture_output=True,text=True,timeout=140)
try:result=json.loads(r.stdout) if r.returncode==0 else {'refused':'sanitized-ssh-failure'}
except ValueError:result={'refused':'sanitized-output-shape'}
result['transport']={'exit_code':r.returncode,'stderr_present':bool(r.stderr)}
except (OSError,subprocess.TimeoutExpired):result={'refused':'sanitized-supplement-unconfirmed'}
result['supplement_sha256']=hashlib.sha256(Path(__file__).read_bytes()).hexdigest()
(P/'scheduling-supplement.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps({'receipt':str(P/'scheduling-supplement.json'),'refused':result.get('refused'),'node_ok':result.get('nodes',{}).get('ok'),'pod_ok':result.get('pods',{}).get('ok')}))