This repository has been archived by the owner on Jan 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
forklift-opdev.sh
executable file
·156 lines (137 loc) · 4.08 KB
/
forklift-opdev.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# Quay.io repo names must match what is provisioned by user
# PROJECT_ROOT assumes running script from tools repo subdir
# CSV_PATH is relative to PROJECT_ROOT
# All objects are created inside the konveyor-forklift namespace for OCP and k8s clusters
PROJECT_ROOT="../"
CSV_PATH="bundle/manifests/forklift-operator.clusterserviceversion.yaml"
REQ_BINS="opm oc docker podman operator-sdk"
OPERATOR_REPO="forklift-operator"
BUNDLE_REPO="forklift-operator-bundle"
INDEX_REPO="forklift-operator-index"
CATALOG_NS="openshift-marketplace"
FORKLIFT_NS="konveyor-forklift"
TAG="latest"
NAME="Forklift"
function usage () {
echo
echo "Valid arguments for $(basename $0):"
echo
echo -e "\t-n : Quay ORG used for ${NAME} development repos (required)"
echo -e "\t-o : Build and push operator image"
echo -e "\t-b : Build and push bundle image"
echo -e "\t-i : Build and push index image"
echo -e "\t-c : Create custom ${NAME} catalogsource"
echo -e "\t-d : Deploy development ${NAME} for testing"
echo
echo "$(basename $0) helps a developer test a ${NAME} operator in a Kubernetes or OpenShift environment. The script uses operator-sdk to build and publish operator, bundle and index images to Quay. Once this is done, developers can deploy and test and validate using a custom catalog source."
echo
exit 1
}
if [ $# -eq 0 ]; then
usage
fi
# Parse options and set run conditions
while getopts 'n:obicdh' opt
do
case $opt in
n)
QUAY_NS="${OPTARG}"
;;
b)
RUN_BUNDLE=true
;;
i)
RUN_INDEX=true
;;
o)
RUN_OPERATOR=true
;;
c)
RUN_CATALOG=true
;;
d)
RUN_DEPLOYMENT=true
;;
h)
usage
;;
*) usage
;;
esac
done
#
# Sanity checks
#
echo
echo "##### Sanity Checks #####"
echo
for bin in $REQ_BINS; do
which $bin &>/dev/null
if [ $? -ne 0 ]; then
echo "Required $bin missing in path, exiting..."
echo
exit 1
fi
done
# Safety check if QUAY_NS set to konveyor, NEVER build/push to upstream production repos
if [ "${QUAY_NS}" == "konveyor" ]; then
echo "${NAME} Quay production repos (quay.io/${QUAY_NS}) should NEVER be used for development/testing, exiting..."
echo
exit 1
fi
echo "All requirements Ok"
# Check if we are running on k8s or OCP clusters
oc get apiservices v1.route.openshift.io 1>/dev/null
if [ $? -ne 0 ]; then
CLI_BIN=kubectl
else
CLI_BIN=oc
fi
# CWD is project root
pushd ${PROJECT_ROOT} 1>/dev/null
# Must process options passed in correct sequence regardless of positional getopts args
if [ ! -z ${RUN_OPERATOR} ]; then
echo
echo "##### Building and pushing Operator #####"
echo
make docker-build docker-push IMG=quay.io/${QUAY_NS}/${OPERATOR_REPO}:${TAG}
fi
if [ ! -z ${RUN_BUNDLE} ]; then
echo
echo "##### Building and pushing Bundle #####"
echo
# Must patch bundle CSV with target custom operator image first, assumes main branch latest tag
sed -i "s/quay.io\/konveyor\/forklift-operator:latest/quay.io\/${QUAY_NS}\/forklift-operator:${TAG}/" ${CSV_PATH}
operator-sdk bundle validate ./bundle && make bundle-build bundle-push BUNDLE_IMG=quay.io/${QUAY_NS}/${BUNDLE_REPO}:${TAG}
fi
if [ ! -z ${RUN_INDEX} ]; then
echo
echo "##### Building and pushing Index #####"
echo
opm index add --bundles quay.io/${QUAY_NS}/${BUNDLE_REPO}:${TAG} --tag quay.io/${QUAY_NS}/${INDEX_REPO}:${TAG} && podman push quay.io/${QUAY_NS}/${INDEX_REPO}:${TAG}
fi
if [ ! -z ${RUN_CATALOG} ]; then
echo
echo "##### Creating custom Catalog #####"
echo
${CLI_BIN} create namespace ${FORKLIFT_NS}
cat << EOF | ${CLI_BIN} apply -f -
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: konveyor-forklift
namespace: ${FORKLIFT_NS}
spec:
displayName: Forklift Development
publisher: Konveyor
sourceType: grpc
image: quay.io/${QUAY_NS}/${INDEX_REPO}:${TAG}
EOF
fi
if [ ! -z ${RUN_DEPLOYMENT} ]; then
echo
echo "##### Deploying Forklift #####"
echo
${CLI_BIN} apply -f forklift-k8s-dev.yaml
fi