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

Commit 7304d5a

Browse files
committed
Use either kubectl or oc, whichever is available
But if targeting OpenShift, oc needs to be available for things like `oc adm ...` and `oc login ...`. Fortunately, minikube doesn't require those things in order to install knative via OLM.
1 parent 5480cf8 commit 7304d5a

File tree

2 files changed

+50
-37
lines changed

2 files changed

+50
-37
lines changed

etc/scripts/install.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ if [ "$1" != "-q" ]; then
77
echo " This script will attempt to install istio, knative, and OLM in your "
88
echo " Kubernetes/OpenShift cluster."
99
echo
10-
echo " A recent version of the `oc` CLI should be in your PATH"
10+
echo " If targeting OpenShift, a recent version of `oc` should be available"
11+
echo " in your PATH. Otherwise, `kubectl` will be used."
1112
echo
1213
echo " If using OpenShift 3.11 and your cluster isn't minishift, ensure"
1314
echo " \$KUBE_SSH_KEY and \$KUBE_SSH_USER are set"
@@ -37,9 +38,9 @@ wait_for_all_pods knative-serving
3738
# skip tag resolving for internal registry
3839
# OpenShift 3 and 4 place the registry in different locations, hence
3940
# the two hostnames here
40-
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 -
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 -
4142

42-
if oc get ns openshift 2>/dev/null; then
43+
if $CMD get ns openshift 2>/dev/null; then
4344
# Add Golang imagestreams to be able to build go based images
4445
oc import-image -n openshift golang --from=centos/go-toolset-7-centos7 --confirm
4546
oc import-image -n openshift golang:1.11 --from=centos/go-toolset-7-centos7 --confirm
@@ -51,9 +52,8 @@ if oc get ns openshift 2>/dev/null; then
5152
oc adm policy add-scc-to-user privileged -z default
5253
oc adm policy add-scc-to-user anyuid -z default
5354
else
54-
oc create namespace myproject
55-
oc project myproject
55+
$CMD create namespace myproject
5656
fi
5757

5858
# show all the running pods
59-
oc get pods --all-namespaces
59+
$CMD get pods --all-namespaces

etc/scripts/installation-functions.sh

Lines changed: 44 additions & 31 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,29 +27,37 @@ 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 {
2942
(hash minishift &&
3043
minishift ip | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" &&
31-
oc whoami --show-server | grep "$(minishift ip)"
44+
show_server | grep "$(minishift ip)"
3245
) >/dev/null 2>&1
3346
}
3447

3548
function check_minikube {
3649
(hash minikube &&
3750
minikube ip | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" &&
38-
oc whoami --show-server | grep "$(minikube ip)"
51+
show_server | grep "$(minikube ip)"
3952
) >/dev/null 2>&1
4053
}
4154

4255
function check_openshift_4 {
43-
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
4457
}
4558

4659
function check_operatorgroups {
47-
oc get crd operatorgroups.operators.coreos.com >/dev/null 2>&1
60+
$CMD get crd operatorgroups.operators.coreos.com >/dev/null 2>&1
4861
}
4962

5063
function enable_admission_webhooks {
@@ -84,7 +97,7 @@ function enable_admission_webhooks {
8497
else
8598
echo "Attempting to enable admission webhooks via SSH."
8699
KUBE_SSH_USER=${KUBE_SSH_USER:-cloud-user}
87-
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}')
88101

89102
ssh $KUBE_SSH_USER@$API_SERVER -i $KUBE_SSH_KEY /bin/bash <<- EOF
90103
sudo -i
@@ -133,7 +146,7 @@ function install_olm {
133146
if check_openshift_4; then
134147
echo "Detected OpenShift 4 - skipping OLM installation."
135148
OLM_NS="openshift-operator-lifecycle-manager"
136-
elif oc get ns "$OLM_NS" 2>/dev/null; then
149+
elif $CMD get ns "$OLM_NS" 2>/dev/null; then
137150
echo "Detected OpenShift 3 with OLM already installed."
138151
# we'll assume this is v3.11.0, which doesn't support
139152
# OperatorGroups, or ClusterRoles in the CSV, so...
@@ -148,36 +161,36 @@ function install_olm {
148161
rm -rf "$OLM_DIR"
149162
git clone https://github.com/operator-framework/operator-lifecycle-manager "$OLM_DIR"
150163
pushd $OLM_DIR; git checkout eaf605cca864e; popd
151-
for i in "$OLM_DIR"/deploy/okd/manifests/latest/*.crd.yaml; do oc apply -f $i; done
152-
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
153166
wait_for_all_pods openshift-operator-lifecycle-manager
154167
# perms required by the OLM console: $OLM_DIR/scripts/run_console_local.sh
155-
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
156169
# check our namespace
157170
OLM_NS=$(grep "catalog_namespace:" "$OLM_DIR/deploy/okd/values.yaml" | awk '{print $2}')
158171
fi
159172
# and finally apply the catalog sources
160-
oc apply -f "$ROOT_DIR/knative-operators.catalogsource.yaml" -n "$OLM_NS"
161-
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"
162175
}
163176

164177
function install_istio {
165178
if check_minikube; then
166179
echo "Detected minikube - incompatible with Maistra operator, so installing upstream istio."
167-
oc apply -f "https://github.com/knative/serving/releases/download/${KNATIVE_SERVING_VERSION}/istio.yaml"
180+
$CMD apply -f "https://github.com/knative/serving/releases/download/${KNATIVE_SERVING_VERSION}/istio.yaml"
168181
wait_for_all_pods istio-system
169182
else
170-
oc create ns istio-operator
183+
$CMD create ns istio-operator
171184
if check_operatorgroups; then
172-
cat <<-EOF | oc apply -f -
185+
cat <<-EOF | $CMD apply -f -
173186
apiVersion: operators.coreos.com/v1alpha2
174187
kind: OperatorGroup
175188
metadata:
176189
name: istio-operator
177190
namespace: istio-operator
178191
EOF
179192
fi
180-
cat <<-EOF | oc apply -f -
193+
cat <<-EOF | $CMD apply -f -
181194
apiVersion: operators.coreos.com/v1alpha1
182195
kind: Subscription
183196
metadata:
@@ -190,7 +203,7 @@ function install_istio {
190203
EOF
191204
wait_for_all_pods istio-operator
192205

193-
cat <<-EOF | oc apply -f -
206+
cat <<-EOF | $CMD apply -f -
194207
apiVersion: istio.openshift.com/v1alpha1
195208
kind: Installation
196209
metadata:
@@ -207,33 +220,33 @@ function install_istio {
207220
prefix: kiali/
208221
version: v0.7.1
209222
EOF
210-
timeout 900 'oc get pods -n istio-system && [[ $(oc get pods -n istio-system | grep openshift-ansible-istio-installer | grep -c Completed) -eq 0 ]]'
223+
timeout 900 '$CMD get pods -n istio-system && [[ $($CMD get pods -n istio-system | grep openshift-ansible-istio-installer | grep -c Completed) -eq 0 ]]'
211224

212225
# Scale down unused services deployed by the istio operator. The
213226
# jaeger pods will fail anyway due to the elasticsearch pod failing
214227
# due to "max virtual memory areas vm.max_map_count [65530] is too
215228
# low, increase to at least [262144]" which could be mitigated on
216229
# minishift with:
217230
# minishift ssh "echo 'echo vm.max_map_count = 262144 >/etc/sysctl.d/99-elasticsearch.conf' | sudo sh"
218-
oc scale -n istio-system --replicas=0 deployment/grafana
219-
oc scale -n istio-system --replicas=0 deployment/jaeger-collector
220-
oc scale -n istio-system --replicas=0 deployment/jaeger-query
221-
oc scale -n istio-system --replicas=0 statefulset/elasticsearch
231+
$CMD scale -n istio-system --replicas=0 deployment/grafana
232+
$CMD scale -n istio-system --replicas=0 deployment/jaeger-collector
233+
$CMD scale -n istio-system --replicas=0 deployment/jaeger-query
234+
$CMD scale -n istio-system --replicas=0 statefulset/elasticsearch
222235
fi
223236
}
224237

225238
function install_knative_build {
226-
oc create ns knative-build
239+
$CMD create ns knative-build
227240
if check_operatorgroups; then
228-
cat <<-EOF | oc apply -f -
241+
cat <<-EOF | $CMD apply -f -
229242
apiVersion: operators.coreos.com/v1alpha2
230243
kind: OperatorGroup
231244
metadata:
232245
name: knative-build
233246
namespace: knative-build
234247
EOF
235248
fi
236-
cat <<-EOF | oc apply -f -
249+
cat <<-EOF | $CMD apply -f -
237250
apiVersion: operators.coreos.com/v1alpha1
238251
kind: Subscription
239252
metadata:
@@ -249,17 +262,17 @@ function install_knative_build {
249262
}
250263

251264
function install_knative_serving {
252-
oc create ns knative-serving
265+
$CMD create ns knative-serving
253266
if check_operatorgroups; then
254-
cat <<-EOF | oc apply -f -
267+
cat <<-EOF | $CMD apply -f -
255268
apiVersion: operators.coreos.com/v1alpha2
256269
kind: OperatorGroup
257270
metadata:
258271
name: knative-serving
259272
namespace: knative-serving
260273
EOF
261274
fi
262-
cat <<-EOF | oc apply -f -
275+
cat <<-EOF | $CMD apply -f -
263276
apiVersion: operators.coreos.com/v1alpha1
264277
kind: Subscription
265278
metadata:
@@ -275,17 +288,17 @@ function install_knative_serving {
275288
}
276289

277290
function install_knative_eventing {
278-
oc create ns knative-eventing
291+
$CMD create ns knative-eventing
279292
if check_operatorgroups; then
280-
cat <<-EOF | oc apply -f -
293+
cat <<-EOF | $CMD apply -f -
281294
apiVersion: operators.coreos.com/v1alpha2
282295
kind: OperatorGroup
283296
metadata:
284297
name: knative-eventing
285298
namespace: knative-eventing
286299
EOF
287300
fi
288-
cat <<-EOF | oc apply -f -
301+
cat <<-EOF | $CMD apply -f -
289302
apiVersion: operators.coreos.com/v1alpha1
290303
kind: Subscription
291304
metadata:

0 commit comments

Comments
 (0)