Skip to content

Commit 2de78c6

Browse files
tdieslersquakez
authored andcommitted
(#5545) Add a canonical script that installs Knative
1 parent 842f56e commit 2de78c6

File tree

3 files changed

+241
-145
lines changed

3 files changed

+241
-145
lines changed

.github/actions/kamel-install-knative/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ runs:
2323
- name: Install Knative
2424
shell: bash
2525
run: |
26-
./.github/actions/kamel-install-knative/install-knative.sh
26+
./e2e/knative/files/setup.sh

.github/actions/kamel-install-knative/install-knative.sh

-144
This file was deleted.

e2e/knative/files/setup.sh

+240
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
#!/bin/bash
2+
3+
# ---------------------------------------------------------------------------
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership.
7+
# The ASF licenses this file to You under the Apache License, Version 2.0
8+
# (the "License"); you may not use this file except in compliance with
9+
# the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
# ---------------------------------------------------------------------------
19+
20+
####
21+
#
22+
# This script takes care of Knative setup
23+
#
24+
####
25+
26+
KNATIVE_VERSION=1.14.0
27+
28+
TIMEOUT="150s"
29+
30+
set -e
31+
32+
# Get the os/arch
33+
ARCH=$(uname -m)
34+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
35+
36+
# Prerequisites
37+
#
38+
39+
echo -n "Checking yq ... "
40+
if which yq > /dev/null 2>&1; then
41+
echo "ok"
42+
else
43+
echo "not installed. (see https://mikefarah.gitbook.io/yq)"
44+
exit 1
45+
fi
46+
47+
set +e
48+
49+
apply() {
50+
local file="${1:-}"
51+
if [ -z "${file}" ]; then
52+
echo "Error: Cannot apply. No file."
53+
exit 1
54+
fi
55+
echo "Applying ${file} ..."
56+
kubectl apply --filename ${file}
57+
if [ $? != 0 ]; then
58+
sleep 5
59+
echo "Re-applying ${file} ..."
60+
kubectl apply --filename ${file}
61+
if [ $? != 0 ]; then
62+
echo "Error: Application of resource failed."
63+
exit 1
64+
fi
65+
fi
66+
}
67+
68+
SERVING_VERSION="knative-v${KNATIVE_VERSION}"
69+
EVENTING_VERSION="knative-v${KNATIVE_VERSION}"
70+
KOURIER_VERSION="knative-v${KNATIVE_VERSION}"
71+
72+
SERVING_CRDS="https://github.com/knative/serving/releases/download/${SERVING_VERSION}/serving-crds.yaml"
73+
SERVING_CORE="https://github.com/knative/serving/releases/download/${SERVING_VERSION}/serving-core.yaml"
74+
KOURIER="https://github.com/knative-sandbox/net-kourier/releases/download/${KOURIER_VERSION}/kourier.yaml"
75+
EVENTING_CRDS="https://github.com/knative/eventing/releases/download/${EVENTING_VERSION}/eventing-crds.yaml"
76+
EVENTING_CORE="https://github.com/knative/eventing/releases/download/${EVENTING_VERSION}/eventing-core.yaml"
77+
IN_MEMORY_CHANNEL="https://github.com/knative/eventing/releases/download/${EVENTING_VERSION}/in-memory-channel.yaml"
78+
CHANNEL_BROKER="https://github.com/knative/eventing/releases/download/${EVENTING_VERSION}/mt-channel-broker.yaml"
79+
80+
KNATIVE_TEMP=$(mktemp -d knative-XXXX)
81+
82+
# Serving CRDs
83+
#
84+
85+
if kubectl get ns knative-serving >/dev/null 2>&1; then
86+
echo "Knative Serving already installed"
87+
else
88+
echo "Installing Knative Serving ..."
89+
90+
orig_yaml="${KNATIVE_TEMP}/serving-crds.yaml"
91+
92+
curl -L -s ${SERVING_CRDS} > ${orig_yaml}
93+
if [ -s ${orig_yaml} ]; then
94+
apply ${orig_yaml}
95+
else
96+
echo "Error: Failed to install ${SERVING_CRDS}"
97+
exit 1
98+
fi
99+
100+
# Serving Core
101+
#
102+
103+
orig_yaml="${KNATIVE_TEMP}/serving-core.yaml"
104+
apply_yaml="${KNATIVE_TEMP}/serving-core-apply.yaml"
105+
106+
curl -L -s ${SERVING_CORE} > ${orig_yaml}
107+
cat ${orig_yaml} | yq e 'del(.spec.template.spec.containers[].resources)' > ${apply_yaml}
108+
if [ -s ${apply_yaml} ]; then
109+
apply ${apply_yaml}
110+
echo "Waiting for pods to be ready in knative-serving"
111+
kubectl wait --for=condition=Ready pod --all -n knative-serving --timeout=${TIMEOUT}
112+
else
113+
echo "Error: Failed to install ${SERVING_CORE}"
114+
exit 1
115+
fi
116+
fi
117+
118+
# Kourier
119+
#
120+
121+
if kubectl get ns kourier-system >/dev/null 2>&1; then
122+
echo "Kourier already installed"
123+
else
124+
echo "Installing Kourier ..."
125+
126+
orig_yaml="${KNATIVE_TEMP}/kourier.yaml"
127+
128+
curl -L -s ${KOURIER} > ${orig_yaml}
129+
if [ -s ${orig_yaml} ]; then
130+
apply ${orig_yaml}
131+
else
132+
echo "Error: Failed to install ${KOURIER}"
133+
exit 1
134+
fi
135+
136+
sleep 5
137+
138+
kubectl patch configmap/config-network \
139+
--namespace knative-serving \
140+
--type merge \
141+
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'
142+
if [ $? != 0 ]; then
143+
echo "Error: Failed to patch configmap"
144+
exit 1
145+
fi
146+
fi
147+
148+
# Eventing CRDs
149+
#
150+
151+
if kubectl get ns knative-eventing >/dev/null 2>&1; then
152+
echo "Knative Eventing already installed"
153+
else
154+
echo "Installing Knative Eventing ..."
155+
156+
orig_yaml="${KNATIVE_TEMP}/eventing-crds.yaml"
157+
158+
curl -L -s ${EVENTING_CRDS} > ${orig_yaml}
159+
if [ -s ${orig_yaml} ]; then
160+
apply ${orig_yaml}
161+
else
162+
echo "Error: Failed to install ${EVENTING_CRDS}"
163+
exit 1
164+
fi
165+
166+
# Eventing Core
167+
#
168+
169+
orig_yaml="${KNATIVE_TEMP}/eventing-core.yaml"
170+
apply_yaml="${KNATIVE_TEMP}/eventing-core-apply.yaml"
171+
172+
curl -L -s ${EVENTING_CORE} > ${orig_yaml}
173+
cat ${orig_yaml} | yq e 'del(.spec.template.spec.containers[].resources)' > ${apply_yaml}
174+
if [ -s ${apply_yaml} ]; then
175+
apply ${apply_yaml}
176+
echo "Waiting for pods to be ready in knative-eventing"
177+
kubectl wait --for=condition=Ready pod --all -n knative-eventing --timeout=${TIMEOUT}
178+
else
179+
echo "Error: Failed to install ${EVENTING_CORE}"
180+
exit 1
181+
fi
182+
183+
# Eventing Channels
184+
185+
orig_yaml="${KNATIVE_TEMP}/in-memory-channel.yaml"
186+
apply_yaml="${KNATIVE_TEMP}/in-memory-channel-apply.yaml"
187+
188+
curl -L -s ${IN_MEMORY_CHANNEL} > ${orig_yaml}
189+
cat ${orig_yaml} | yq e 'del(.spec.template.spec.containers[].resources)' > ${apply_yaml}
190+
if [ -s ${apply_yaml} ]; then
191+
apply ${apply_yaml}
192+
else
193+
echo "Error: Failed to install ${IN_MEMORY_CHANNEL}"
194+
exit 1
195+
fi
196+
197+
# Eventing Broker
198+
#
199+
200+
orig_yaml="${KNATIVE_TEMP}/channel-broker.yaml"
201+
apply_yaml="${KNATIVE_TEMP}/channel-broker-apply.yaml"
202+
203+
curl -L -s ${CHANNEL_BROKER} > ${orig_yaml}
204+
cat ${orig_yaml} | yq e 'del(.spec.template.spec.containers[].resources)' > ${apply_yaml}
205+
if [ -s ${apply_yaml} ]; then
206+
apply ${apply_yaml}
207+
else
208+
echo "Error: Failed to install ${CHANNEL_BROKER}"
209+
exit 1
210+
fi
211+
212+
# Eventing sugar controller configuration
213+
echo "Patching Knative eventing configuration"
214+
kubectl patch configmap/config-sugar \
215+
-n knative-eventing \
216+
--type merge \
217+
-p '{"data":{"namespace-selector":"{\"matchExpressions\":[{\"key\":\"eventing.knative.dev/injection\",\"operator\":\"In\",\"values\":[\"enabled\"]}]}"}}'
218+
219+
kubectl patch configmap/config-sugar \
220+
-n knative-eventing \
221+
--type merge \
222+
-p '{"data":{"trigger-selector":"{\"matchExpressions\":[{\"key\":\"eventing.knative.dev/injection\",\"operator\":\"In\",\"values\":[\"enabled\"]}]}"}}'
223+
fi
224+
225+
# Wait for installation completed
226+
echo && echo "Waiting for all pods to be ready in knative-serving"
227+
kubectl wait --for=condition=Ready pod --all -n knative-serving --timeout=${TIMEOUT}
228+
echo && echo "Waiting for all pods to be ready in kourier-system"
229+
kubectl wait --for=condition=Ready pod --all -n kourier-system --timeout=${TIMEOUT}
230+
echo && echo "Waiting for all pods to be ready in knative-eventing"
231+
kubectl wait --for=condition=Ready pod --all -n knative-eventing --timeout=${TIMEOUT}
232+
233+
# Expose Kourier Service
234+
#
235+
if [[ "${OS}" = "darwin" ]]; then
236+
echo
237+
kubectl get svc -n kourier-system
238+
echo
239+
echo "On ${OS} you may want to run 'minikube tunnel' to expose the Kourier Service"
240+
fi

0 commit comments

Comments
 (0)