@@ -1689,6 +1689,12 @@ spec:
16891689 }
16901690 adm_port=$(service_port "$adm" https-webhook)
16911691 ctl_port=$(service_port "$ctl" https)
1692+ adm_cluster_ip=$(kubectl -n "$ns" get svc "$adm" -o jsonpath='{.spec.clusterIP}')
1693+ [ -n "$adm_cluster_ip" ] && [ "$adm_cluster_ip" != None ] || {
1694+ echo "SETUP FAILURE: $adm must have a real ClusterIP, found ${adm_cluster_ip:-<empty>}" >&2
1695+ kubectl -n "$ns" get svc "$adm" -o yaml >&2 2>&1 || true
1696+ exit 1
1697+ }
16921698 [ -n "$adm_port" ] || {
16931699 echo "SETUP FAILURE: $adm must expose exactly one TCP https-webhook port" >&2
16941700 kubectl -n "$ns" get svc "$adm" -o yaml >&2 2>&1 || true
@@ -1711,10 +1717,11 @@ spec:
17111717 echo "$n"
17121718 }
17131719
1714- # Exact ready admission coordinates. The IP and backend port come
1715- # from the same EndpointSlice as the ready condition; selecting them
1716- # independently from .items[0] could probe an unready replica while a
1717- # different replica kept the aggregate Service readiness above zero.
1720+ # Exact ready admission coordinates. The Pod identity, IP and backend
1721+ # port come from the same EndpointSlice as the ready condition;
1722+ # selecting them independently from .items[0] could probe an unready
1723+ # replica while a different replica kept aggregate readiness above
1724+ # zero.
17181725 ready_admission_backends() {
17191726 kubectl -n "$ns" get endpointslice -l "kubernetes.io/service-name=$adm" -o json | jq -r '
17201727 .items[]? as $slice
@@ -1726,21 +1733,32 @@ spec:
17261733 | select(.conditions.ready == true)
17271734 | select(.targetRef.kind == "Pod")
17281735 | select((.targetRef.name // "") != "")
1736+ | select((.targetRef.uid // "") != "")
17291737 | .targetRef.name as $pod
1738+ | .targetRef.uid as $uid
17301739 | .addresses[]?
17311740 | select(type == "string" and length > 0)
1732- | [$pod, ., ($port.port | tostring)]
1741+ | [$pod, $uid, ., ($port.port | tostring)]
17331742 | @tsv
17341743 ' | sort -u
17351744 }
17361745
1737- # Pod identity plus restart count, as one string. Compared for
1738- # equality across the probe window, so a restart AND a replacement
1739- # both show up -- a crash-looping controller can satisfy a readiness
1740- # check at both ends of a window it spent dying in the middle of.
1746+ # Pod identity, IP and every container restart count, as one string.
1747+ # Compared for equality across the probe window, so a restart AND a
1748+ # replacement both show up -- a crash-looping controller can satisfy
1749+ # a readiness check at both ends of a window it spent dying in the
1750+ # middle of.
17411751 controller_generation() {
1742- kubectl -n "$ns" get pod -l "$sel" \
1743- -o jsonpath='{range .items[*]}{.metadata.name}/{.metadata.uid}={range .status.containerStatuses[*]}{.name}:{.restartCount},{end}{"\n"}{end}' | sort
1752+ generation=$(kubectl -n "$ns" get pod -l "$sel" \
1753+ -o jsonpath='{range .items[*]}{.metadata.name}/{.metadata.uid}/{.status.podIP}={range .status.containerStatuses[*]}{.name}:{.restartCount},{end}{"\n"}{end}') || {
1754+ echo "SETUP FAILURE: unable to read ingress-nginx controller generation" >&2
1755+ return 1
1756+ }
1757+ [ -n "$generation" ] || {
1758+ echo "SETUP FAILURE: ingress-nginx controller generation is empty" >&2
1759+ return 1
1760+ }
1761+ printf '%s\n' "$generation" | sort
17441762 }
17451763
17461764 # Precondition. Both Services are backed by the same controller pods,
@@ -1765,29 +1783,30 @@ spec:
17651783 done
17661784
17671785 backend=$(ready_admission_backends | head -1)
1768- [ -n "$backend" ] || { echo "SETUP FAILURE: $adm has no complete ready Pod/IP/port coordinate" >&2; exit 1; }
1786+ [ -n "$backend" ] || { echo "SETUP FAILURE: $adm has no complete ready Pod/UID/ IP/port coordinate" >&2; exit 1; }
17691787 tab=$(printf '\t')
17701788 backend_fields=$(printf '%s\n' "$backend" | awk -F "$tab" '{ print NF }')
1771- [ "$backend_fields" -eq 3 ] || { echo "SETUP FAILURE: malformed ready backend coordinate: $backend" >&2; exit 1; }
1789+ [ "$backend_fields" -eq 4 ] || { echo "SETUP FAILURE: malformed ready backend coordinate: $backend" >&2; exit 1; }
17721790 pod_name=$(printf '%s\n' "$backend" | cut -f1)
1773- pod_ip=$(printf '%s\n' "$backend" | cut -f2)
1774- hook_port=$(printf '%s\n' "$backend" | cut -f3)
1775- [ -n "$pod_name" ] && [ -n "$pod_ip" ] && [ -n "$hook_port" ] || {
1791+ pod_uid=$(printf '%s\n' "$backend" | cut -f2)
1792+ pod_ip=$(printf '%s\n' "$backend" | cut -f3)
1793+ hook_port=$(printf '%s\n' "$backend" | cut -f4)
1794+ [ -n "$pod_name" ] && [ -n "$pod_uid" ] && [ -n "$pod_ip" ] && [ -n "$hook_port" ] || {
17761795 echo "SETUP FAILURE: incomplete ready backend coordinate: $backend" >&2
17771796 exit 1
17781797 }
17791798
17801799 selected_backend_ready() {
17811800 ready_admission_backends | awk -F "$tab" \
1782- -v pod="$pod_name" -v ip="$pod_ip" -v port="$hook_port" '
1783- $1 == pod && $2 == ip && $3 == port { found = 1 }
1801+ -v pod="$pod_name" -v uid="$pod_uid" -v ip="$pod_ip" -v port="$hook_port" '
1802+ $1 == pod && $2 == uid && $3 == ip && $4 == port { found = 1 }
17841803 END { exit !found }
17851804 '
17861805 }
17871806
17881807 require_selected_backend() {
17891808 selected_backend_ready && return 0
1790- echo "SETUP FAILURE: selected admission backend $pod_name ($pod_ip:$hook_port) was not ready $1" >&2
1809+ echo "SETUP FAILURE: selected admission backend $pod_name/$pod_uid ($pod_ip:$hook_port) was not ready $1" >&2
17911810 kubectl -n "$ns" get endpointslice -l "kubernetes.io/service-name=$adm" -o yaml >&2 2>&1 || true
17921811 kubectl -n "$ns" get pod "$pod_name" -o wide >&2 2>&1 || true
17931812 exit 1
@@ -1799,6 +1818,14 @@ spec:
17991818 # instant. Six samples over 30s, all of which must be live and show no
18001819 # restart or replacement.
18011820 gen_before=$(controller_generation)
1821+ printf '%s\n' "$gen_before" | awk \
1822+ -v prefix="${pod_name}/${pod_uid}/${pod_ip}=" '
1823+ index($0, prefix) == 1 { found = 1 }
1824+ END { exit !found }
1825+ ' || {
1826+ echo "SETUP FAILURE: selected admission backend is not a current controller Pod: $backend" >&2
1827+ exit 1
1828+ }
18021829 i=0
18031830 while [ "$i" -lt 6 ]; do
18041831 sleep 5
@@ -1820,7 +1847,7 @@ spec:
18201847 exit 1
18211848 }
18221849
1823- echo "probing from $ns: expect reachable ${ctl}:${ctl_port}, denied ${adm}:${adm_port}, denied ${pod_name}@${pod_ip}:${hook_port}"
1850+ echo "probing from $ns: expect reachable ${ctl}:${ctl_port}, denied ${adm}@${adm_cluster_ip} :${adm_port}, denied ${pod_name}/${pod_uid }@${pod_ip}:${hook_port}"
18241851
18251852 kubectl -n "$ns" delete pod "$probe" --ignore-not-found --wait=true --timeout=60s
18261853 # busybox:musl is staged onto every node by hack/e2e-prepull-images.sh,
@@ -1854,7 +1881,7 @@ spec:
18541881 - name: CTL_PORT
18551882 value: "${ctl_port}"
18561883 - name: ADM_HOST
1857- value: "${adm}.${ns}.svc "
1884+ value: "${adm_cluster_ip} "
18581885 - name: ADM_PORT
18591886 value: "${adm_port}"
18601887 - name: POD_IP
0 commit comments