#!/usr/bin/env bash

NS=test-ksvcs-recreating
DELAY=0

oc new-project "$NS"

function ksvc {
  i=$1
  cat <<EOF
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: $i
  namespace: $NS
spec:
  template:
    spec:
      containers:
      - image: gcr.io/knative-samples/helloworld-go
        env:
        - name: TARGET
          value: Go Sample v0
        resources:
          requests:
            cpu: 10m
            memory: 10M
EOF
}

function create {
  oc create -f -
}

function delete {
  oc delete -f -
}

function wait_for_readiness {
  oc wait -n "$NS" --for=condition=Ready "ksvc/$1"
}

i=0
while true; do
  i=$((i+1))
  name="newksvc$i"
  ksvc "$name" | create
  wait_for_readiness "$name"
  ksvc "$name" | delete
  sleep "$DELAY"
done 
