#!/usr/bin/env bash
# time-admission.sh <label> <image> <count> - time <count> server-side dry runs of a pod
# with <image>, one line each: label, run number, seconds, first line of the answer.
label="$1"; image="$2"; n="${3:-5}"
here="$(cd "$(dirname "$0")" && pwd)"
for i in $(seq 1 "$n"); do
  s=$(python3 -c 'import time;print(time.time())')
  out="$("$here/pod.sh" "t-$RANDOM" "$image" | kubectl apply --dry-run=server -f - 2>&1 | head -1 | cut -c1-110)"
  e=$(python3 -c 'import time;print(time.time())')
  printf '%s\t%d\t%.2fs\t%s\n' "$label" "$i" "$(echo "$e - $s" | bc)" "$out"
done
