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

Commit c749043

Browse files
committed
Make script reasonably idempotent [OCF-348]
This amounts to skipping the istio and olm installations if their respective namespaces exist. The knative resources are re-applied, however. We also refactored the knative install functions to remove their redundancy.
1 parent 9adc228 commit c749043

File tree

2 files changed

+26
-68
lines changed

2 files changed

+26
-68
lines changed

etc/scripts/install.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ enable_admission_webhooks
2828
install_olm
2929
install_catalogsources
3030
install_istio
31-
install_knative_build
32-
install_knative_serving
33-
install_knative_eventing
31+
install_knative build
32+
install_knative serving
33+
install_knative eventing
3434

3535
wait_for_all_pods knative-build
3636
wait_for_all_pods knative-eventing
@@ -53,7 +53,7 @@ if $CMD get ns openshift 2>/dev/null; then
5353
oc adm policy add-scc-to-user privileged -z default
5454
oc adm policy add-scc-to-user anyuid -z default
5555
else
56-
$CMD create namespace myproject
56+
$CMD get ns myproject 2>/dev/null || $CMD create namespace myproject
5757
fi
5858

5959
# show all the running pods

etc/scripts/installation-functions.sh

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ function enable_admission_webhooks {
9898
else
9999
echo "Admission webhooks are already enabled."
100100
fi
101-
else
101+
elif [ "$KUBE_SSH_USER" != "" ]; then
102102
echo "Attempting to enable admission webhooks via SSH."
103-
KUBE_SSH_USER=${KUBE_SSH_USER:-cloud-user}
104103
API_SERVER=$($CMD config view --minify | grep server | awk -F'//' '{print $2}' | awk -F':' '{print $1}')
105104

106105
ssh $KUBE_SSH_USER@$API_SERVER -i $KUBE_SSH_KEY /bin/bash <<- EOF
@@ -141,6 +140,8 @@ function enable_admission_webhooks {
141140
echo 'Remote command failed; check $KUBE_SSH_USER and/or $KUBE_SSH_KEY'
142141
return -1
143142
fi
143+
else
144+
echo "Unable to enable admission webhooks - if necessary, set KUBE_SSH_USER and retry"
144145
fi
145146
}
146147

@@ -182,7 +183,9 @@ function install_catalogsources {
182183
}
183184

184185
function install_istio {
185-
if check_minikube; then
186+
if $CMD get ns "istio-system" 2>/dev/null; then
187+
echo "Detected istio - skipping installation"
188+
elif check_minikube; then
186189
echo "Detected minikube - incompatible with Maistra operator, so installing upstream istio."
187190
$CMD apply -f "https://github.com/knative/serving/releases/download/${KNATIVE_SERVING_VERSION}/istio-crds.yaml" && \
188191
$CMD apply -f "https://github.com/knative/serving/releases/download/${KNATIVE_SERVING_VERSION}/istio.yaml"
@@ -244,83 +247,38 @@ function install_istio {
244247
fi
245248
}
246249

247-
function install_knative_build {
248-
$CMD create ns knative-build
249-
if check_operatorgroups; then
250-
cat <<-EOF | $CMD apply -f -
251-
apiVersion: operators.coreos.com/v1alpha2
252-
kind: OperatorGroup
253-
metadata:
254-
name: knative-build
255-
namespace: knative-build
256-
EOF
250+
function install_knative {
251+
if [[ ! "$1" =~ ^(build|serving|eventing)$ ]]; then
252+
echo "Pass one of 'build', 'serving', or 'eventing'"
253+
return -1
257254
fi
258-
cat <<-EOF | $CMD apply -f -
259-
apiVersion: operators.coreos.com/v1alpha1
260-
kind: Subscription
261-
metadata:
262-
name: knative-build-subscription
263-
generateName: knative-build-
264-
namespace: knative-build
265-
spec:
266-
source: knative-operators
267-
sourceNamespace: $(olm_namespace)
268-
name: knative-build
269-
startingCSV: knative-build.${KNATIVE_BUILD_VERSION}
270-
channel: alpha
271-
EOF
272-
}
273-
274-
function install_knative_serving {
275-
$CMD create ns knative-serving
276-
if check_operatorgroups; then
277-
cat <<-EOF | $CMD apply -f -
278-
apiVersion: operators.coreos.com/v1alpha2
279-
kind: OperatorGroup
280-
metadata:
281-
name: knative-serving
282-
namespace: knative-serving
283-
EOF
255+
local COMPONENT="knative-$1"
256+
if $CMD get ns ${COMPONENT} 2>/dev/null 1>&2; then
257+
echo "${COMPONENT} namespace exists - reapplying resources"
258+
else
259+
$CMD create ns ${COMPONENT}
284260
fi
285-
cat <<-EOF | $CMD apply -f -
286-
apiVersion: operators.coreos.com/v1alpha1
287-
kind: Subscription
288-
metadata:
289-
name: knative-serving-subscription
290-
generateName: knative-serving-
291-
namespace: knative-serving
292-
spec:
293-
source: knative-operators
294-
sourceNamespace: $(olm_namespace)
295-
name: knative-serving
296-
startingCSV: knative-serving.${KNATIVE_SERVING_VERSION}
297-
channel: alpha
298-
EOF
299-
}
300-
301-
function install_knative_eventing {
302-
$CMD create ns knative-eventing
303261
if check_operatorgroups; then
304262
cat <<-EOF | $CMD apply -f -
305263
apiVersion: operators.coreos.com/v1alpha2
306264
kind: OperatorGroup
307265
metadata:
308-
name: knative-eventing
309-
namespace: knative-eventing
266+
name: ${COMPONENT}
267+
namespace: ${COMPONENT}
310268
EOF
311269
fi
312270
cat <<-EOF | $CMD apply -f -
313271
apiVersion: operators.coreos.com/v1alpha1
314272
kind: Subscription
315273
metadata:
316-
name: knative-eventing-subscription
317-
generateName: knative-eventing-
318-
namespace: knative-eventing
274+
name: ${COMPONENT}-subscription
275+
generateName: ${COMPONENT}-
276+
namespace: ${COMPONENT}
319277
spec:
320278
source: knative-operators
321279
sourceNamespace: $(olm_namespace)
322-
name: knative-eventing
323-
startingCSV: knative-eventing.${KNATIVE_EVENTING_VERSION}
280+
name: ${COMPONENT}
281+
startingCSV: ${COMPONENT}.${KNATIVE_BUILD_VERSION}
324282
channel: alpha
325283
EOF
326284
}

0 commit comments

Comments
 (0)