-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsetup.sh
executable file
·252 lines (205 loc) · 6.67 KB
/
setup.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
# This script sets up a single node cluster (SNC) which was created by
# the Cloud Installer (https://cloud.redhat.com/openshift/assisted-installer/clusters/~new)
#
# First, you have to install the SNC in your network. Then you are logging into it with kubeadmin
# THEN you can let this script run, which will create PVs in the VM and configures the
# internal registry to use one of the PVs for storing everything.
#
# Please see README.MD for more details.
#
set -e -u -o pipefail
declare HOST=192.168.2.23 # set it to your IP
declare USER=core
declare NUM_PVs=100
declare KUBECONFIG=""
declare OC=oc
declare -r SCRIPT_DIR=$(cd -P $(dirname $0) && pwd)
declare COMMAND="help"
valid_command() {
local fn=$1; shift
[[ $(type -t "$fn") == "function" ]]
}
info() {
printf "\n# INFO: $@\n"
}
err() {
printf "\n# ERROR: $1\n"
exit 1
}
while (( "$#" )); do
case "$1" in
rhdh|mesh|crc|sno|aws|monitoring|console|storage|registry|operators|ci|users|all|oauth)
COMMAND=$1
shift
;;
-h|--host-name)
HOST=$2
shift 2
;;
-u|--user-name)
USER=$2
shift 2
;;
-k|--kubeconfig)
KUBECONFIG=$2
shift 2
;;
--)
shift
break
;;
-*|--*)
err "Error: Unsupported flag $1"
;;
*)
break
esac
done
command.help() {
cat <<-EOF
Provides some functions to make an OpenShift Single Node Cluster usable.
NOTE: First, you need to install an OpenShift Single Node Cluster (CRC or SNO). Then you
have to log into it using the kubeadmin credentials provided.
oc login -u kubeadmin -p <your kubeadmin hash> https://api.crc.testing:6443
And THEN you can issue this script.
Usage:
setup.sh [command] [options]
Examples:
./setup.sh storage
./setup.sh registry
./setup.sh users
./setup.sh all
COMMANDS:
rhdh Installs and configures Red Hat Developer Hub (requires the install of the Operator first)
oauth Adds a SSO provider to OpenShift
console Adds some links to the App menu and some APIs to the left menu
storage Setup CSI kubevirt hostpath provisioner
registry Setup internal image registry to use a PVC and accept requests
operators Install gitops and pipeline operators
monitoring Configure OpenShift monitoring and user monitoring
ci Install Nexus and Gogs in a ci namespace
users Creates two users: admin/admin123 and devel/devel
mesh Installs and configures RH Service Mesh
help Help about this command
ENVIRONMENTS:
all calls all modules
sno Fresh SNO: like all, except ci
aws demo.redhat.com workshop: calls console, operators and ci
crc Fresh CRC: calls console, operators,
OPTIONS:
-k --kubeconfig kubeconfig file to be used
EOF
}
command.oauth() {
info "Setting up OAuth2 provider..."
cat <<-EOF
Configuring SSO OAuth2 authentication provider with OpenShift
First go to https://console.developers.google.com/apis/credentials
and generate a new OAuth2 client. Then take the generated Client ID
and Client Secret and put them into
$SCRIPT_DIR/config/oauth/client-secret.env
EOF
$OC apply -k $SCRIPT_DIR/config/oauth
}
command.rhdh() {
info "Installing and configuring OpenShift Developer Hub"
cat <<-EOF
Please make sure, you've called the 'operators' module first to install
all the necessary operators. Then have a look at the 'config/rhdh' folder
to configure Developer Hub according to your needs.
Copy both config/rhdh/example-*.yaml files to config/rhdh/ without the
'example' prefix and make sure they contain YOUR content.
EOF
$OC apply -k $SCRIPT_DIR/config/rhdh
}
command.mesh() {
info "Configuring Red Hat OpenShift ServiceMesh operator"
$OC apply -k $SCRIPT_DIR/config/mesh
echo
cat <<-EOF
ServiceMesh should have been successfully installed and preconfigured to
include a demo project (grumpycat) into the mesh. If you want to install
the official bookinfo demo project for the mesh, please install it by calling
$> oc apply -k $SCRIPT_DIR/config/mesh/sample
EOF
}
command.console() {
info "Configuring the OpenShift Console"
$OC apply -k $SCRIPT_DIR/config/console
}
command.monitoring() {
info "Configuring the OpenShift Monitoring and User Monitoring"
$OC apply -k $SCRIPT_DIR/config/monitoring
}
# This command sets up the kubevirt hostpath provisioner
command.storage() {
info "Installing kubevirt CSI hostpath provisioner"
$OC apply -k $SCRIPT_DIR/config/storage
}
command.registry() {
info "Binding internal image registry to a persistent volume and make it manageable"
# Apply registry pvc to bound with pv0001
$OC apply -k $SCRIPT_DIR/config/registry
}
command.operators() {
info "Installing a bunch of operators..."
$OC apply -k $SCRIPT_DIR/config/operators/
}
command.ci() {
info "Initialising a CI project in OpenShift with Nexus and Gitea installed"
$OC apply -k $SCRIPT_DIR/config/ci
GITEA_HOST=$($OC get route gitea -o template --template="{{.spec.host}}" -n ci)
sed "s/@HOSTNAME/$GITEA_HOST/g" $SCRIPT_DIR/config/ci/gitea-config.yaml | $OC create -f - -n ci
$OC rollout status deployment/gitea -n ci
$OC create -f $SCRIPT_DIR/config/ci/gitea-init-run.yaml -n ci
}
command.users() {
info "Creating an admin and a developer user."
$OC apply -k $SCRIPT_DIR/config/users
# we want admin be cluster-admin
#$OC adm policy add-cluster-role-to-user cluster-admin admin
info "Please wait a while until OpenShift has updated OAuth management"
}
command.crc() {
command.console
command.operators
command.ci
}
command.sno() {
$OC apply -k $SCRIPT_DIR/config
command.monitoring
command.storage
command.users
}
command.aws() {
command.operators
command.console
command.ci
command.monitoring
}
command.all() {
$OC apply -k $SCRIPT_DIR/config
command.storage
command.users
command.ci
command.monitoring
}
main() {
local fn="command.$COMMAND"
valid_command "$fn" || {
err "invalid command '$COMMAND'"
}
# setup OC command
if [ -n "$KUBECONFIG" ]; then
info "Using kubeconfig $KUBECONFIG"
OC="oc --kubeconfig $KUBECONFIG"
else
info "Using default kubeconfig"
OC="oc"
fi
cd "$SCRIPT_DIR"
$fn
return $?
}
main