#!/usr/bin/env bash # Creates the objects the integration fixtures are recorded from, then (with # --cleanup) removes them again. Everything lives in the namespace the recorder # is allowed to capture, so no real project data can end up in a fixture. # # Usage: # ./scripts/seed-integration-fixtures.sh # create and wait # ./scripts/seed-integration-fixtures.sh --cleanup # remove set -euo pipefail cd "$(dirname "$0")/.." NS="${NS:-cy-test-ns}" NAD="network-attachment-definitions.k8s.cni.cncf.io" UDN="userdefinednetworks.k8s.ovn.org" cleanup() { oc delete -n "$NS" --ignore-not-found \ pod/web-1 pod/web-2 pod/other-1 \ service/web service/cluster-ip service/headless service/node-port \ service/load-balancer service/external-name service/healthy service/degraded service/down \ "${NAD}/network-bridge" "${NAD}/other-nad" \ "${UDN}/udn-layer2" "${UDN}/udn-layer3" \ ingress/shop ingress/no-rules \ route/shop route/draft \ networkpolicy/deny-all networkpolicy/allow-web \ endpointslice/healthy-1 endpointslice/degraded-1 endpointslice/down-1 \ virtualmachine/vm-plain virtualmachine/vm-qualified virtualmachine/vm-other \ virtualmachine/vm-detached oc delete clusteruserdefinednetwork test-cudn-team --ignore-not-found } if [ "${1-}" = "--cleanup" ]; then cleanup exit 0 fi oc get namespace "$NS" >/dev/null # The namespace carries audit/warn PodSecurity labels only, so the pause pods # below are admitted. Health states use manually managed EndpointSlices on # selector-less Services, which keeps the fixture deterministic. oc apply -f - </dev/null | wc -l) [ "$slices" -gt 0 ] && break sleep 4 done # Route and Ingress status is populated asynchronously. The Ingress controller # also creates one Route per host; wait for both derived Routes so the recorded # list has the shape the console sees. for _ in $(seq 1 15); do route_status=$(oc get route shop -n "$NS" -o jsonpath='{.status.ingress}' 2>/dev/null || true) derived=$(oc get routes -n "$NS" -o name 2>/dev/null | grep -c 'route.route.openshift.io/shop-' || true) [ -n "$route_status" ] && [ "$derived" -ge 2 ] && break sleep 2 done echo "seeded:" # Names only: a table row for a Route carries its cluster-generated hostname, # which embeds the cluster's apps domain. The recorder is what needs the data; # the shell output goes to terminals and CI logs. oc get -n "$NS" pods,services,endpointslices,ingresses,routes,networkpolicies,"$NAD","$UDN",virtualmachines -o name 2>/dev/null || true echo "run ./scripts/record-integration-fixtures.sh, then --cleanup"