Skip to content
This repository was archived by the owner on Aug 2, 2019. It is now read-only.

Commit f6e453f

Browse files
authored
Merge pull request #20 from openshift-cloud-functions/minikube
Install our knative operators on minikube
2 parents 93d6366 + 7207f8e commit f6e453f

File tree

4 files changed

+142
-62
lines changed

4 files changed

+142
-62
lines changed

etc/scripts/install-on-minikube.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
# WARNING: this totally destroys and recreates your `knative` profile,
4+
# thereby guaranteeing (hopefully) a clean environment upon successful
5+
# completion.
6+
7+
if minikube status 2>&1 | grep -E "^E[0-9]{4}"; then
8+
echo "minikube is confused, check for conflicting vm's, e.g. minishift"
9+
exit -1
10+
fi
11+
if minikube status | head -1 | grep "Running" >/dev/null; then
12+
echo "Please stop your running minikube to acknowledge this script will destroy it."
13+
exit 1
14+
fi
15+
16+
set -x
17+
18+
KUBERNETES_VERSION=${KUBERNETES_VERSION:-v1.11.5}
19+
MEMORY=${MEMORY:-8192}
20+
CPUS=${CPUS:-4}
21+
DISK_SIZE=${DISK_SIZE:-50g}
22+
23+
# blow away everything in the knative profile
24+
minikube delete --profile knative
25+
26+
# configure knative profile
27+
minikube profile knative
28+
minikube config set kubernetes-version ${KUBERNETES_VERSION}
29+
minikube config set memory ${MEMORY}
30+
minikube config set cpus ${CPUS}
31+
minikube config set disk-size ${DISK_SIZE}
32+
33+
# Start minikube
34+
minikube start -p knative --extra-config=apiserver.enable-admission-plugins="LimitRanger,NamespaceExists,NamespaceLifecycle,ResourceQuota,ServiceAccount,DefaultStorageClass,MutatingAdmissionWebhook"
35+
36+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
37+
"$DIR/install.sh" -q

etc/scripts/install-on-minishift.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44
# thereby guaranteeing (hopefully) a clean environment upon successful
55
# completion.
66

7-
if minishift status | grep "Minishift: Running" >/dev/null; then
7+
if minishift status | head -1 | grep "Running" >/dev/null; then
88
echo "Please stop your running minishift to acknowledge this script will destroy it."
99
exit 1
1010
fi
1111

1212
set -x
1313

14+
OPENSHIFT_VERSION=${OPENSHIFT_VERSION:-v3.11.0}
15+
MEMORY=${MEMORY:-10GB}
16+
CPUS=${CPUS:-4}
17+
DISK_SIZE=${DISK_SIZE:-50g}
18+
1419
# blow away everything in the knative profile
1520
minishift profile delete knative --force
1621

1722
# configure knative profile
1823
minishift profile set knative
19-
minishift config set openshift-version v3.11.0
20-
minishift config set memory 10GB
21-
minishift config set cpus 4
22-
minishift config set disk-size 50g
24+
minishift config set openshift-version ${OPENSHIFT_VERSION}
25+
minishift config set memory ${MEMORY}
26+
minishift config set cpus ${CPUS}
27+
minishift config set disk-size ${DISK_SIZE}
2328
minishift config set image-caching true
2429
minishift addons enable admin-user
2530

etc/scripts/install.sh

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/usr/bin/env bash
22

3-
# Installs OLM first, and then istio and knative using OLM operators
3+
# Attempts to install istio, knative, and OLM, ideally not in that order.
44

55
if [ "$1" != "-q" ]; then
66
echo
7-
echo " WARNING: This script will blindly attempt to install OLM, istio, and knative"
8-
echo " on your OpenShift cluster, so if any are already there, hijinks may ensue."
7+
echo " This script will attempt to install istio, knative, and OLM in your "
8+
echo " Kubernetes/OpenShift cluster."
9+
echo
10+
echo " If targeting OpenShift, a recent version of 'oc' should be available"
11+
echo " in your PATH. Otherwise, 'kubectl' will be used."
912
echo
1013
echo " If using OpenShift 3.11 and your cluster isn't minishift, ensure"
1114
echo " \$KUBE_SSH_KEY and \$KUBE_SSH_USER are set"
1215
echo
13-
echo " Pass -q to disable this warning"
16+
echo " Pass -q to disable this prompt"
1417
echo
1518
read -p "Enter to continue or Ctrl-C to exit: "
1619
fi
@@ -35,18 +38,22 @@ wait_for_all_pods knative-serving
3538
# skip tag resolving for internal registry
3639
# OpenShift 3 and 4 place the registry in different locations, hence
3740
# the two hostnames here
38-
oc -n knative-serving get cm config-controller -oyaml | sed "s/\(^ *registriesSkippingTagResolving.*$\)/\1,docker-registry.default.svc:5000,image-registry.openshift-image-registry.svc:5000/" | oc apply -f -
39-
40-
# Add Golang imagestreams to be able to build go based images
41-
oc import-image -n openshift golang --from=centos/go-toolset-7-centos7 --confirm
42-
oc import-image -n openshift golang:1.11 --from=centos/go-toolset-7-centos7 --confirm
43-
44-
# these perms are required by istio
45-
if ! oc project myproject 2>/dev/null; then
46-
oc new-project myproject
41+
$CMD -n knative-serving get cm config-controller -oyaml | sed "s/\(^ *registriesSkippingTagResolving.*$\)/\1,docker-registry.default.svc:5000,image-registry.openshift-image-registry.svc:5000/" | oc apply -f -
42+
43+
if $CMD get ns openshift 2>/dev/null; then
44+
# Add Golang imagestreams to be able to build go based images
45+
oc import-image -n openshift golang --from=centos/go-toolset-7-centos7 --confirm
46+
oc import-image -n openshift golang:1.11 --from=centos/go-toolset-7-centos7 --confirm
47+
48+
if ! oc project myproject 2>/dev/null; then
49+
oc new-project myproject
50+
fi
51+
# these perms are required by istio
52+
oc adm policy add-scc-to-user privileged -z default
53+
oc adm policy add-scc-to-user anyuid -z default
54+
else
55+
$CMD create namespace myproject
4756
fi
48-
oc adm policy add-scc-to-user privileged -z default
49-
oc adm policy add-scc-to-user anyuid -z default
5057

51-
# show all the pods
52-
oc get pods --all-namespaces
58+
# show all the running pods
59+
$CMD get pods --all-namespaces

etc/scripts/installation-functions.sh

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ KNATIVE_EVENTING_VERSION=v0.3.0
1111

1212
INSTALL_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
1313

14+
CMD=kubectl
15+
if hash oc 2>/dev/null; then
16+
CMD=$_
17+
fi
18+
1419
# Loops until duration (car) is exceeded or command (cdr) returns non-zero
1520
function timeout() {
1621
SECONDS=0; TIMEOUT=$1; shift
@@ -22,24 +27,44 @@ function timeout() {
2227

2328
# Waits for all pods in the given namespace to complete successfully.
2429
function wait_for_all_pods {
25-
timeout 300 "oc get pods -n $1 2>&1 | grep -v -E '(Running|Completed|STATUS)'"
30+
timeout 300 "$CMD get pods -n $1 2>&1 | grep -v -E '(Running|Completed|STATUS)'"
31+
}
32+
33+
function show_server {
34+
if [ "$CMD" = "oc" ]; then
35+
$CMD whoami --show-server
36+
else
37+
$CMD cluster-info | head -1
38+
fi
2639
}
2740

2841
function check_minishift {
29-
(hash minishift && oc whoami --show-server | grep "$(minishift ip)") >/dev/null 2>&1
42+
(hash minishift &&
43+
minishift ip | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" &&
44+
show_server | grep "$(minishift ip)"
45+
) >/dev/null 2>&1
46+
}
47+
48+
function check_minikube {
49+
(hash minikube &&
50+
minikube ip | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" &&
51+
show_server | grep "$(minikube ip)"
52+
) >/dev/null 2>&1
3053
}
3154

3255
function check_openshift_4 {
33-
oc api-resources | grep machineconfigs | grep machineconfiguration.openshift.io > /dev/null 2>&1
56+
$CMD api-resources | grep machineconfigs | grep machineconfiguration.openshift.io > /dev/null 2>&1
3457
}
3558

3659
function check_operatorgroups {
37-
oc get crd operatorgroups.operators.coreos.com >/dev/null 2>&1
60+
$CMD get crd operatorgroups.operators.coreos.com >/dev/null 2>&1
3861
}
3962

4063
function enable_admission_webhooks {
4164
if check_openshift_4; then
42-
echo "Detected OpenShift 4 - skipping enabling admission webhooks."
65+
echo "Detected OpenShift 4 - skipping enabling admission webhooks"
66+
elif check_minikube; then
67+
echo "Detected minikube - assuming admission webhooks enabled via --extra-config"
4368
elif check_minishift; then
4469
echo "Detected minishift - checking if admission webhooks are enabled."
4570
if ! minishift openshift config view --target=kube | grep ValidatingAdmissionWebhook >/dev/null; then
@@ -72,7 +97,7 @@ function enable_admission_webhooks {
7297
else
7398
echo "Attempting to enable admission webhooks via SSH."
7499
KUBE_SSH_USER=${KUBE_SSH_USER:-cloud-user}
75-
API_SERVER=$(oc config view --minify | grep server | awk -F'//' '{print $2}' | awk -F':' '{print $1}')
100+
API_SERVER=$($CMD config view --minify | grep server | awk -F'//' '{print $2}' | awk -F':' '{print $1}')
76101

77102
ssh $KUBE_SSH_USER@$API_SERVER -i $KUBE_SSH_KEY /bin/bash <<- EOF
78103
sudo -i
@@ -121,7 +146,7 @@ function install_olm {
121146
if check_openshift_4; then
122147
echo "Detected OpenShift 4 - skipping OLM installation."
123148
OLM_NS="openshift-operator-lifecycle-manager"
124-
elif oc get ns "$OLM_NS"; then
149+
elif $CMD get ns "$OLM_NS" 2>/dev/null; then
125150
echo "Detected OpenShift 3 with OLM already installed."
126151
# we'll assume this is v3.11.0, which doesn't support
127152
# OperatorGroups, or ClusterRoles in the CSV, so...
@@ -136,32 +161,37 @@ function install_olm {
136161
rm -rf "$OLM_DIR"
137162
git clone https://github.com/operator-framework/operator-lifecycle-manager "$OLM_DIR"
138163
pushd $OLM_DIR; git checkout eaf605cca864e; popd
139-
for i in "$OLM_DIR"/deploy/okd/manifests/latest/*.crd.yaml; do oc apply -f $i; done
140-
for i in $(find "$OLM_DIR/deploy/okd/manifests/latest/" -type f ! -name "*crd.yaml" | sort); do oc create -f $i; done
164+
for i in "$OLM_DIR"/deploy/okd/manifests/latest/*.crd.yaml; do $CMD apply -f $i; done
165+
for i in $(find "$OLM_DIR/deploy/okd/manifests/latest/" -type f ! -name "*crd.yaml" | sort); do $CMD create -f $i; done
141166
wait_for_all_pods openshift-operator-lifecycle-manager
142167
# perms required by the OLM console: $OLM_DIR/scripts/run_console_local.sh
143-
oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:kube-system:default
168+
# oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:kube-system:default
144169
# check our namespace
145170
OLM_NS=$(grep "catalog_namespace:" "$OLM_DIR/deploy/okd/values.yaml" | awk '{print $2}')
146171
fi
147172
# and finally apply the catalog sources
148-
oc apply -f "$ROOT_DIR/knative-operators.catalogsource.yaml" -n "$OLM_NS"
149-
oc apply -f "$ROOT_DIR/maistra-operators.catalogsource.yaml" -n "$OLM_NS"
173+
$CMD apply -f "$ROOT_DIR/knative-operators.catalogsource.yaml" -n "$OLM_NS"
174+
$CMD apply -f "$ROOT_DIR/maistra-operators.catalogsource.yaml" -n "$OLM_NS"
150175
}
151176

152177
function install_istio {
153-
# istio
154-
oc create ns istio-operator
155-
if check_operatorgroups; then
156-
cat <<-EOF | oc apply -f -
178+
if check_minikube; then
179+
echo "Detected minikube - incompatible with Maistra operator, so installing upstream istio."
180+
$CMD apply -f "https://github.com/knative/serving/releases/download/${KNATIVE_SERVING_VERSION}/istio-crds.yaml" && \
181+
$CMD apply -f "https://github.com/knative/serving/releases/download/${KNATIVE_SERVING_VERSION}/istio.yaml"
182+
wait_for_all_pods istio-system
183+
else
184+
$CMD create ns istio-operator
185+
if check_operatorgroups; then
186+
cat <<-EOF | $CMD apply -f -
157187
apiVersion: operators.coreos.com/v1alpha2
158188
kind: OperatorGroup
159189
metadata:
160190
name: istio-operator
161191
namespace: istio-operator
162192
EOF
163-
fi
164-
cat <<-EOF | oc apply -f -
193+
fi
194+
cat <<-EOF | $CMD apply -f -
165195
apiVersion: operators.coreos.com/v1alpha1
166196
kind: Subscription
167197
metadata:
@@ -172,9 +202,9 @@ function install_istio {
172202
name: maistra
173203
source: maistra-operators
174204
EOF
175-
wait_for_all_pods istio-operator
205+
wait_for_all_pods istio-operator
176206

177-
cat <<-EOF | oc apply -f -
207+
cat <<-EOF | $CMD apply -f -
178208
apiVersion: istio.openshift.com/v1alpha1
179209
kind: Installation
180210
metadata:
@@ -191,32 +221,33 @@ function install_istio {
191221
prefix: kiali/
192222
version: v0.7.1
193223
EOF
194-
timeout 900 'oc get pods -n istio-system && [[ $(oc get pods -n istio-system | grep openshift-ansible-istio-installer | grep -c Completed) -eq 0 ]]'
224+
timeout 900 '$CMD get pods -n istio-system && [[ $($CMD get pods -n istio-system | grep openshift-ansible-istio-installer | grep -c Completed) -eq 0 ]]'
195225

196-
# Scale down unused services deployed by the istio operator. The
197-
# jaeger pods will fail anyway due to the elasticsearch pod failing
198-
# due to "max virtual memory areas vm.max_map_count [65530] is too
199-
# low, increase to at least [262144]" which could be mitigated on
200-
# minishift with:
201-
# minishift ssh "echo 'echo vm.max_map_count = 262144 >/etc/sysctl.d/99-elasticsearch.conf' | sudo sh"
202-
oc scale -n istio-system --replicas=0 deployment/grafana
203-
oc scale -n istio-system --replicas=0 deployment/jaeger-collector
204-
oc scale -n istio-system --replicas=0 deployment/jaeger-query
205-
oc scale -n istio-system --replicas=0 statefulset/elasticsearch
226+
# Scale down unused services deployed by the istio operator. The
227+
# jaeger pods will fail anyway due to the elasticsearch pod failing
228+
# due to "max virtual memory areas vm.max_map_count [65530] is too
229+
# low, increase to at least [262144]" which could be mitigated on
230+
# minishift with:
231+
# minishift ssh "echo 'echo vm.max_map_count = 262144 >/etc/sysctl.d/99-elasticsearch.conf' | sudo sh"
232+
$CMD scale -n istio-system --replicas=0 deployment/grafana
233+
$CMD scale -n istio-system --replicas=0 deployment/jaeger-collector
234+
$CMD scale -n istio-system --replicas=0 deployment/jaeger-query
235+
$CMD scale -n istio-system --replicas=0 statefulset/elasticsearch
236+
fi
206237
}
207238

208239
function install_knative_build {
209-
oc create ns knative-build
240+
$CMD create ns knative-build
210241
if check_operatorgroups; then
211-
cat <<-EOF | oc apply -f -
242+
cat <<-EOF | $CMD apply -f -
212243
apiVersion: operators.coreos.com/v1alpha2
213244
kind: OperatorGroup
214245
metadata:
215246
name: knative-build
216247
namespace: knative-build
217248
EOF
218249
fi
219-
cat <<-EOF | oc apply -f -
250+
cat <<-EOF | $CMD apply -f -
220251
apiVersion: operators.coreos.com/v1alpha1
221252
kind: Subscription
222253
metadata:
@@ -232,17 +263,17 @@ function install_knative_build {
232263
}
233264

234265
function install_knative_serving {
235-
oc create ns knative-serving
266+
$CMD create ns knative-serving
236267
if check_operatorgroups; then
237-
cat <<-EOF | oc apply -f -
268+
cat <<-EOF | $CMD apply -f -
238269
apiVersion: operators.coreos.com/v1alpha2
239270
kind: OperatorGroup
240271
metadata:
241272
name: knative-serving
242273
namespace: knative-serving
243274
EOF
244275
fi
245-
cat <<-EOF | oc apply -f -
276+
cat <<-EOF | $CMD apply -f -
246277
apiVersion: operators.coreos.com/v1alpha1
247278
kind: Subscription
248279
metadata:
@@ -258,17 +289,17 @@ function install_knative_serving {
258289
}
259290

260291
function install_knative_eventing {
261-
oc create ns knative-eventing
292+
$CMD create ns knative-eventing
262293
if check_operatorgroups; then
263-
cat <<-EOF | oc apply -f -
294+
cat <<-EOF | $CMD apply -f -
264295
apiVersion: operators.coreos.com/v1alpha2
265296
kind: OperatorGroup
266297
metadata:
267298
name: knative-eventing
268299
namespace: knative-eventing
269300
EOF
270301
fi
271-
cat <<-EOF | oc apply -f -
302+
cat <<-EOF | $CMD apply -f -
272303
apiVersion: operators.coreos.com/v1alpha1
273304
kind: Subscription
274305
metadata:

0 commit comments

Comments
 (0)