#!/bin/sh

# Run this with just the Serverless Operator installed (with no KnativeServing created yet)
# A ksvc created in between the services.serving.knative.dev CRD is available and the serving controller starts up will never become Ready

oc create -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
 name: knative-serving
EOF

oc create -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
 name: foobar
EOF

oc create -f - <<EOF
apiVersion: operator.knative.dev/v1alpha1
kind: KnativeServing
metadata:
  name: knative-serving
  namespace: knative-serving
EOF

while ! oc get crd services.serving.knative.dev
do
  echo "Waiting for the services.serving.knative.dev CRD"
  sleep 1
done

oc create -f - <<EOF
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: foobar
spec:
  template:
    spec:
      containers:
      - image: gcr.io/knative-samples/helloworld-go
        env:
        - name: TARGET
          value: "Go Sample v1"
EOF

while oc get services.serving.knative.dev helloworld-go -n foobar -o=jsonpath='{.metadata.name}{"\tReady:"}{.status.conditions[?(@.type=="Ready")].status}{"\tMessage:"}{.status.conditions[?(@.type=="Ready")].message}' | grep -v 'Ready:True'; do sleep 1; done
oc get services.serving.knative.dev helloworld-go -n foobar -o=jsonpath='{.metadata.name}{"\tReady:"}{.status.conditions[?(@.type=="Ready")].status}{"\tMessage:"}{.status.conditions[?(@.type=="Ready")].message}'


