-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-demo-resources.sh
executable file
·80 lines (60 loc) · 2.93 KB
/
install-demo-resources.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
export DEMO=${DEMO-""}
set -euo pipefail
current_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
readonly cluster_domain="$(oc get ingresses.config/cluster -o jsonpath='{.spec.domain}')"
readonly APICURIO_REGISTRY_API="http://apicurio-registry.apicurio-registry.router-default.${cluster_domain}"
function upload_schema() {
local schema="$1"
local type="$2"
local id="$3"
curl -k -X POST "${APICURIO_REGISTRY_API}/apis/registry/v2/groups/event-discovery/artifacts" \
-H "Content-Type: application/json" \
-H "X-Registry-ArtifactId: ${id}" \
-H "X-Registry-ArtifactType: ${type}" \
-d "@${schema}"
curl -k -X PUT "${APICURIO_REGISTRY_API}/apis/registry/v2/groups/event-discovery/artifacts/${id}" \
-H "Content-Type: application/json" \
-H "X-Registry-ArtifactType: ${type}" \
-d "@${schema}"
echo ''
}
function wait_ready_resource() {
resource="$1"
if [[ $(kubectl get "${resource}" -A -o go-template='{{printf "%d\n" (len .items)}}') != 0 ]]; then
kubectl wait "${resource}" --for=condition=Ready=true --timeout=20m -A --all || return $?
fi
}
function wait_ready() {
wait_ready_resource "brokers.eventing.knative.dev" || return $?
wait_ready_resource "triggers.eventing.knative.dev" || return $?
wait_ready_resource "kafkasinks.eventing.knative.dev" || return $?
wait_ready_resource "kafkasources.sources.knative.dev" || return $?
wait_ready_resource "pingsources.sources.knative.dev" || return $?
wait_ready_resource "kameletbindings.camel.apache.org" || return $?
}
function apply() {
dir="$1"
while ! kustomize build "${dir}" | kubectl apply -f -;
do
wait_ready || sleep 10
echo "waiting for resource apply to succeed"
sleep 10
done
wait_ready
}
echo "=============================="
echo "== Deploying demo resources =="
echo "=============================="
upload_schema "${current_dir}/demo-applications/event-discovery/schemas/order.json" "JSON" "online-order-schema"
echo EVENT_SCHEMA_ORDER="${APICURIO_REGISTRY_API}/ui/artifacts/event-discovery/online-order-schema" > "${current_dir}/demo-applications/event-discovery/.env"
upload_schema "${current_dir}/demo-applications/event-discovery/schemas/cart-changed.json" "JSON" "cart-changed"
echo EVENT_SCHEMA_CART_CHANGED="${APICURIO_REGISTRY_API}/ui/artifacts/event-discovery/cart-changed" >> "${current_dir}/demo-applications/event-discovery/.env"
apply "${current_dir}/demo-kafka-resources/${DEMO}"
apply "${current_dir}/demo-applications/${DEMO}"
if [[ "${DEMO}" == "event-discovery" ]]; then
# This is a temporary solution to use the OCP console version 4.18 on OCP 4.17 or less.
kubectl patch consoles.operator.openshift.io cluster --type merge -p '{"spec":{"managementState": "Unmanaged"}}'
kubectl patch deployment.apps -n openshift-console console \
-p '{"spec":{"template":{"spec":{"containers":[{"name":"console","image":"quay.io/pierdipi/openshift-console:4.18"}]}}}}'
fi