Skip to content

Commit 5bb7307

Browse files
committed
setup-operator.sh pretty solid now
Signed-off-by: Scott J Dickerson <[email protected]>
1 parent b96e18a commit 5bb7307

File tree

1 file changed

+56
-32
lines changed

1 file changed

+56
-32
lines changed

hack/setup-operator.sh

+56-32
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/bin/bash
22
#
33
# Based on:
4-
# - https://github.com/konveyor/operator/blob/main/hack/install-konveyor.sh
4+
# - https://github.com/konveyor/operator/blob/main/hack/install-konveyor.sh **latest
55
# - https://github.com/konveyor/operator/blob/main/hack/install-tackle.sh
66
# - https://konveyor.github.io/konveyor/installation/#installing-konveyor-operator
7+
# - https://github.com/konveyor/operator/blob/main/tackle-k8s.yaml
78
#
89
# By default, no authentication, and only use pre-built images
910
#
10-
set -euxo pipefail
11+
set -eo pipefail
12+
# set -euxo pipefail
1113

1214
# use kubectl if available, else fall back to `minikube kubectl --`, else error
1315
KUBECTL=kubectl
@@ -38,6 +40,19 @@ debug() {
3840
}
3941
trap 'debug' ERR
4042

43+
function retry_command() {
44+
local retries=$1
45+
local sleeptime=$2
46+
local cmd=${@:3}
47+
48+
until [[ $retries -eq 0 ]] || ${cmd} &>/dev/null; do
49+
echo "command failed, try again in ${sleeptime}s [retries: $retries]"
50+
sleep $sleeptime
51+
((retries--))
52+
done
53+
[[ $retries == 0 ]] && return 1 || return 0
54+
}
55+
4156
# Inputs for setting up the operator
4257
NAMESPACE="${NAMESPACE:-konveyor-tackle}"
4358
OPERATOR_INDEX_IMAGE="${OPERATOR_INDEX_IMAGE:-quay.io/konveyor/tackle2-operator-index:latest}"
@@ -46,22 +61,23 @@ OPERATOR_INDEX_IMAGE="${OPERATOR_INDEX_IMAGE:-quay.io/konveyor/tackle2-operator-
4661
TACKLE_CR="${TACKLE_CR:-}"
4762

4863
FEATURE_AUTH_REQUIRED="${FEATURE_AUTH_REQUIRED:-false}"
49-
HUB_IMAGE="${HUB_IMAGE:-quay.io/konveyor/tackle2-hub:latest}"
50-
UI_IMAGE="${UI_IMAGE:-quay.io/konveyor/tackle2-ui:latest}"
64+
IMAGE_PULL_POLICY="${IMAGE_PULL_POLICY:-Always}"
5165
UI_INGRESS_CLASS_NAME="${UI_INGRESS_CLASS_NAME:-nginx}"
66+
UI_IMAGE="${UI_IMAGE:-quay.io/konveyor/tackle2-ui:latest}"
67+
HUB_IMAGE="${HUB_IMAGE:-quay.io/konveyor/tackle2-hub:latest}"
5268
ADDON_ANALYZER_IMAGE="${ADDON_ANALYZER_IMAGE:-quay.io/konveyor/tackle2-addon-analyzer:latest}"
53-
IMAGE_PULL_POLICY="${IMAGE_PULL_POLICY:-Always}"
5469
ANALYZER_CONTAINER_REQUESTS_MEMORY="${ANALYZER_CONTAINER_REQUESTS_MEMORY:-0}"
5570
ANALYZER_CONTAINER_REQUESTS_CPU="${ANALYZER_CONTAINER_REQUESTS_CPU:-0}"
5671

5772
install_operator() {
58-
# Create the Konveyor Namespace
59-
$KUBECTL auth can-i create namespace --all-namespaces
60-
$KUBECTL create namespace ${NAMESPACE} || true
61-
62-
# Install the Konveyor CatalogSource, OperatorGroup, and Subscription
73+
# Install the Konveyor Namespace, CatalogSource, OperatorGroup, and Subscription
6374
cat <<EOF | $KUBECTL apply -f -
6475
---
76+
apiVersion: v1
77+
kind: Namespace
78+
metadata:
79+
name: ${NAMESPACE}
80+
---
6581
apiVersion: operators.coreos.com/v1alpha1
6682
kind: CatalogSource
6783
metadata:
@@ -95,29 +111,37 @@ spec:
95111
sourceNamespace: ${NAMESPACE}
96112
EOF
97113

98-
# # If on MacOS, need to install `brew install coreutils` to get `timeout`
99-
# timeout 600s bash -c "until $KUBECTL get customresourcedefinitions.apiextensions.k8s.io tackles.tackle.konveyor.io; do sleep 30; done" \
100-
# || $KUBECTL get subscription --namespace ${NAMESPACE} -o yaml konveyor-operator # Print subscription details when timed out
114+
echo "Waiting for the Tackle CRD to exist"
115+
retry_command 10 10 \
116+
$KUBECTL get customresourcedefinitions.apiextensions.k8s.io tackles.tackle.konveyor.io
117+
118+
if [[ $? -ne 0 ]]; then
119+
echo "Tackle CRD doesn't exist yet, cannot continue"
120+
exit 1
121+
fi
101122

123+
echo "Waiting for the Tackle CRD to become established"
102124
$KUBECTL wait \
103125
--namespace ${NAMESPACE} \
104-
--for=condition=established \
105-
customresourcedefinitions.apiextensions.k8s.io/tackles.tackle.konveyor.io
106-
}
126+
--timeout=120s \
127+
--for=condition=Established \
128+
customresourcedefinitions.apiextensions.k8s.io tackles.tackle.konveyor.io
107129

108-
install_tackle() {
109-
echo "Waiting for the Tackle CRD to become available"
110-
$KUBECTL wait \
130+
echo "Waiting for the Tackle Operator to become available"
131+
$KUBECTL rollout status \
111132
--namespace "${NAMESPACE}" \
112-
--for=condition=established \
113-
customresourcedefinitions.apiextensions.k8s.io/tackles.tackle.konveyor.io
114-
115-
echo "Waiting for the Tackle Operator to exist"
116-
timeout 2m bash -c "until $KUBECTL --namespace ${NAMESPACE} get deployment/tackle-operator; do sleep 10; done"
133+
--timeout=600s \
134+
-w deployment/tackle-operator
135+
}
117136

118-
echo "Waiting for the Tackle Operator to become available"
119-
$KUBECTL rollout status --namespace "${NAMESPACE}" -w deployment/tackle-operator --timeout=600s
137+
install_konveyor() {
138+
echo "Make sure the Tackle Operator is available"
139+
$KUBECTL rollout status \
140+
--namespace "${NAMESPACE}" \
141+
--timeout=600s \
142+
-w deployment/tackle-operator
120143

144+
echo "Create a Tackle CR"
121145
if [ -n "${TACKLE_CR}" ]; then
122146
echo "${TACKLE_CR}" | $KUBECTL apply --namespace "${NAMESPACE}" -f -
123147
else
@@ -127,18 +151,18 @@ apiVersion: tackle.konveyor.io/v1alpha1
127151
metadata:
128152
name: tackle
129153
spec:
154+
image_pull_policy: ${IMAGE_PULL_POLICY}
130155
feature_auth_required: ${FEATURE_AUTH_REQUIRED}
131-
hub_image_fqin: ${HUB_IMAGE}
132-
ui_image_fqin: ${UI_IMAGE}
133156
ui_ingress_class_name: ${UI_INGRESS_CLASS_NAME}
157+
ui_image_fqin: ${UI_IMAGE}
158+
hub_image_fqin: ${HUB_IMAGE}
134159
analyzer_fqin: ${ADDON_ANALYZER_IMAGE}
135-
image_pull_policy: ${IMAGE_PULL_POLICY}
136160
analyzer_container_requests_memory: ${ANALYZER_CONTAINER_REQUESTS_MEMORY}
137161
analyzer_container_requests_cpu: ${ANALYZER_CONTAINER_REQUESTS_CPU}
138162
EOF
139163
fi
140164

141-
# Want to see in github logs what we just created
165+
# Log Want to see in github logs what we just created
142166
$KUBECTL get --namespace "${NAMESPACE}" -o yaml tackles.tackle.konveyor.io/tackle
143167

144168
# Wait for reconcile to finish
@@ -157,5 +181,5 @@ EOF
157181
deployments.apps
158182
}
159183

160-
$KUBECTL get customresourcedefinitions.apiextensions.k8s.io tackles.tackle.konveyor.io || install_operator
161-
install_tackle
184+
$KUBECTL get customresourcedefinitions.apiextensions.k8s.io tackles.tackle.konveyor.io &>/dev/null || install_operator
185+
install_konveyor

0 commit comments

Comments
 (0)