forked from tektoncd/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller
executable file
·569 lines (511 loc) · 14.1 KB
/
installer
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
#!/usr/bin/env bash
# Copyright 2021-2023 The Tekton Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# dashboard flavour
READONLY="true"
# configuration default values
DEBUG="false"
INSTALL_NAMESPACE="tekton-pipelines"
PIPELINES_NAMESPACE="tekton-pipelines"
TRIGGERS_NAMESPACE="tekton-pipelines"
EXTENSIONS_RBAC="false"
LOGOUT_URL=""
LOG_LEVEL="info"
LOG_FORMAT="json"
TENANT_NAMESPACES=""
STREAM_LOGS="true"
EXTERNAL_LOGS=""
BASE_RELEASE_URL="https://storage.googleapis.com/tekton-releases/dashboard"
# additional options passed to ko resolve
KO_RESOLVE_OPTIONS=""
PLATFORM=""
# Display a box banner.
# Parameters: $1 - character to use for the box.
# $2 - banner message.
make_banner() {
local msg="$1$1$1$1 WARNING: $2 $1$1$1$1"
local border="${msg//[-0-9A-Za-z _.,:\/()]/$1}"
echo -e "\n${border}\n${msg}\n${border}\n"
}
# Simple warning banner for logging purposes.
warning() {
make_banner "!" "$1"
}
initOS() {
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
case "$OS" in
# Minimalist GNU for Windows
mingw*)
OS='windows'
;;
darwin*)
ARCH=$(uname -m)
if [ "$ARCH" == "arm64" ] && [ -z "$PLATFORM" ]; then
debug "Detected Apple M1 and no custom platform specified"
PLATFORM="--platform linux/arm64"
fi
;;
esac
debug "Detected OS: $OS"
}
verifySupported() {
if ( [ "$ACTION" == "install" ] || [ "$ACTION" == "uninstall" ] ) && ! type "kubectl" > /dev/null 2>&1; then
echo "kubectl is required"
exit 1
fi
if [ -z "$DASHBOARD_VERSION" ] && ! type "kustomize" > /dev/null 2>&1; then
echo "kustomize is required"
exit 1
fi
if [ -z "$DASHBOARD_VERSION" ] && ! type "ko" > /dev/null 2>&1; then
echo "ko is required"
exit 1
fi
if ! type "sed" > /dev/null 2>&1; then
echo "sed is required"
exit 1
fi
if ! type "curl" > /dev/null 2>&1 && ! type "wget" > /dev/null 2>&1; then
echo "Either curl or wget is required"
exit 1
fi
}
debug() {
local message=$1
if [ "$DEBUG" == "true" ]; then
echo $message
fi
}
compile() {
local overlay="overlays/installer"
if [ "$READONLY" == "true" ]; then
overlay="$overlay/read-only"
else
overlay="$overlay/read-write"
fi
debug "Building overlay $overlay …"
kustomize build --load-restrictor LoadRestrictionsNone "$overlay" | ko resolve $KO_RESOLVE_OPTIONS $PLATFORM -f - > "$TMP_FILE"
}
download() {
if [ $DASHBOARD_VERSION == "latest" ]; then
local url="$BASE_RELEASE_URL/latest/installer-"
else
local url="$BASE_RELEASE_URL/previous/$DASHBOARD_VERSION/installer-"
fi
url="${url}release"
if [ "$READONLY" == "false" ]; then
url="${url}-full"
fi
url="${url}.yaml"
debug "Downloading $url -> $TMP_FILE …"
if type "curl" > /dev/null 2>&1; then
curl -s "$url" -o "$TMP_FILE"
elif type "wget" > /dev/null 2>&1; then
wget -q -O "$TMP_FILE" "$url"
fi
}
setup() {
if [ ! -z "$OVERRIDE_NAMESPACE" ]; then
INSTALL_NAMESPACE="$OVERRIDE_NAMESPACE"
fi
if [ ! -z "$OVERRIDE_PIPELINES_NAMESPACE" ]; then
PIPELINES_NAMESPACE="$OVERRIDE_PIPELINES_NAMESPACE"
fi
if [ ! -z "$OVERRIDE_TRIGGERS_NAMESPACE" ]; then
TRIGGERS_NAMESPACE="$OVERRIDE_TRIGGERS_NAMESPACE"
fi
}
replace() {
local src=$1
local dest=$2
debug "REPLACE $src -> $dest"
if [ "$OS" == "darwin" ]; then
sed -i "" "s~$src~$dest~g" $TMP_FILE
else
sed -i "s~$src~$dest~g" $TMP_FILE
fi
}
patch() {
replace "--pipelines-namespace=--pipelines-namespace" "--pipelines-namespace=$PIPELINES_NAMESPACE"
replace "--triggers-namespace=--triggers-namespace" "--triggers-namespace=$TRIGGERS_NAMESPACE"
replace "--log-level=--log-level" "--log-level=$LOG_LEVEL"
replace "--log-format=--log-format" "--log-format=$LOG_FORMAT"
replace "--logout-url=--logout-url" "--logout-url=$LOGOUT_URL"
replace "--read-only=--read-only" "--read-only=$READONLY"
replace "--namespace=--tenant-namespace" "--namespace="
replace "--namespaces=--tenant-namespaces" "--namespaces=$TENANT_NAMESPACES"
replace "--stream-logs=--stream-logs" "--stream-logs=$STREAM_LOGS"
replace "--external-logs=--external-logs" "--external-logs=$EXTERNAL_LOGS"
replace "namespace: tekton-dashboard" "namespace: $INSTALL_NAMESPACE"
}
role_binding() {
local name=$1
local namespace=$2
cat <<EOF >> $TMP_FILE
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app.kubernetes.io/component: dashboard
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-dashboard
rbac.dashboard.tekton.dev/subject: tekton-dashboard
name: $name
namespace: $namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: $name
subjects:
- kind: ServiceAccount
name: tekton-dashboard
namespace: $INSTALL_NAMESPACE
EOF
}
cluster_role_binding() {
local name=$1
cat <<EOF >> $TMP_FILE
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/component: dashboard
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-dashboard
rbac.dashboard.tekton.dev/subject: tekton-dashboard
name: $name
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: $name
subjects:
- kind: ServiceAccount
name: tekton-dashboard
namespace: $INSTALL_NAMESPACE
EOF
}
rbac() {
if [ "$EXTENSIONS_RBAC" == "true" ]; then
cat <<EOF >> $TMP_FILE
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tekton-dashboard-extensions
labels:
app.kubernetes.io/component: dashboard
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-dashboard
aggregationRule:
clusterRoleSelectors:
- matchLabels:
rbac.dashboard.tekton.dev/aggregate-to-dashboard: 'true'
EOF
fi
if [ ! -z "$TENANT_NAMESPACES" ]; then
IFS=','
for namespace in ${TENANT_NAMESPACES}; do
role_binding tekton-dashboard-tenant $namespace
if [ "$EXTENSIONS_RBAC" == "true" ]; then
role_binding tekton-dashboard-extensions $namespace
fi
done
unset IFS
else
cluster_role_binding tekton-dashboard-tenant
if [ "$EXTENSIONS_RBAC" == "true" ]; then
cluster_role_binding tekton-dashboard-extensions
fi
fi
}
ingress() {
INGRESS_DEFAULT_CLASS_NAME_CONFIG=""
if [ "$INGRESS_DEFAULT_CLASS" == "true" ]; then
INGRESS_DEFAULT_CLASS_NAME_CONFIG="ingressClassName: nginx"
cat <<EOF >> $TMP_FILE
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
labels:
app.kubernetes.io/component: controller
name: nginx
annotations:
ingressclass.kubernetes.io/is-default-class: "true"
spec:
controller: k8s.io/ingress-nginx
EOF
fi
if [ ! -z "$INGRESS_URL" ] && [ ! -z "$INGRESS_SECRET" ]; then
cat <<EOF >> $TMP_FILE
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tekton-dashboard
namespace: $INSTALL_NAMESPACE
spec:
$INGRESS_DEFAULT_CLASS_NAME_CONFIG
tls:
- hosts:
- $INGRESS_URL
secretName: $INGRESS_SECRET
rules:
- host: $INGRESS_URL
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: tekton-dashboard
port:
number: 9097
EOF
elif [ ! -z "$INGRESS_URL" ]; then
cat <<EOF >> $TMP_FILE
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tekton-dashboard
namespace: $INSTALL_NAMESPACE
spec:
$INGRESS_DEFAULT_CLASS_NAME_CONFIG
rules:
- host: $INGRESS_URL
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: tekton-dashboard
port:
number: 9097
EOF
fi
}
# install invokes kubectl apply with the built manifest.
install() {
echo "Installing …"
kubectl create ns $INSTALL_NAMESPACE > /dev/null 2>&1 || true
kubectl apply -f $TMP_FILE
}
uninstall() {
echo "Uninstalling …"
resourceKinds=(
"deployments.apps"
"serviceaccounts"
"services"
"customresourcedefinitions.apiextensions.k8s.io"
"clusterrolebindings.rbac.authorization.k8s.io"
"clusterroles.rbac.authorization.k8s.io"
"rolebindings.rbac.authorization.k8s.io"
"roles.rbac.authorization.k8s.io"
)
for resourceKind in "${resourceKinds[@]}";do
echo "Deleting ${resourceKind}"
kubectl delete ${resourceKind} --ignore-not-found -l=app.kubernetes.io/instance=default,app.kubernetes.io/part-of=tekton-dashboard --all-namespaces
done
}
build() {
if [ -z "$OUTPUT_FILE" ]; then
cat $TMP_FILE
else
cat $TMP_FILE > $OUTPUT_FILE
fi
}
# fail_trap is executed if an error occurs.
fail_trap() {
result=$?
cleanup
exit $result
}
# help provides possible cli installation arguments
help () {
echo -e "Global command syntax:"
echo -e "\tinstaller COMMAND [OPTIONS]"
echo -e ""
echo -e "Accepted commands:"
echo -e "\thelp|h\t\t\t\t\tPrints this help"
echo -e "\tinstall|i\t\t\t\tInstalls the dashboard"
echo -e "\tuninstall|u\t\t\t\tUninstalls the dashboard"
echo -e "\tbuild|b\t\t\t\t\tBuilds the manifests and dashboard docker image"
echo -e "\trelease|r\t\t\t\tBuilds the manifests and dashboard docker image for release"
echo -e ""
echo -e "Accepted options:"
echo -e "\t[--debug]\t\t\t\tPrints additional messages in the console"
echo -e "\t[--extensions-rbac]\t\t\tEnable ClusterRole aggregation for easier management of extensions RBAC"
echo -e "\t[--external-logs <logs-provider-url>]\tExternal URL from which to fetch logs when logs are not available in the cluster"
echo -e "\t[--ingress-secret <secret>]\t\tWill add SSL support to the ingress"
echo -e "\t[--ingress-url <url>]\t\t\tWill create an additional ingress with the specified URL"
echo -e "\t[--log-format <log-format>]\t\tSpecifies the log format (json or console), default is json"
echo -e "\t[--log-level <log-level>]\t\tSpecifies the log level (debug, info, warn, error, dpanic, panic, fatal), default is info"
echo -e "\t[--logout-url <logout-url>]\t\tWill set up the logout URL"
echo -e "\t[--namespace <namespace>]\t\tWill override install namespace"
echo -e "\t[--nightly]\t\t\t\tWill download manifests from the nightly releases channel"
echo -e "\t[--output <file>]\t\t\tWill output built manifests in the file instead of in the console"
echo -e "\t[--pipelines-namespace <namespace>]\tOverride the namespace where Tekton Pipelines is installed (defaults to Dashboard install namespace)"
echo -e "\t[--platform <platform>]\t\t\tOverride the platform to build for"
echo -e "\t[--read-write]\t\t\t\tWill build manifests for a read/write deployment"
echo -e "\t[--stream-logs false]\t\t\tWill disable log streaming and use polling instead"
echo -e "\t[--tag <tag>]\t\t\t\tTag used for the image produced by ko"
echo -e "\t[--tenant-namespace <namespace>]\t[DEPRECATED: use tenant-namespaces instead] Will limit the visibility to the specified namespace only"
echo -e "\t[--tenant-namespaces <namespaces>]\tWill limit the visibility to the specified comma-separated namespaces only"
echo -e "\t[--triggers-namespace <namespace>]\tOverride the namespace where Tekton Triggers is installed (defaults to Dashboard install namespace)"
echo -e "\t[--version <version>]\t\t\tWill download manifests for specified version or build everything using kustomize/ko"
}
# cleanup temporary files
cleanup() {
if [[ -d "${TMP_ROOT:-}" ]]; then
rm -rf "$TMP_ROOT"
fi
}
# Execution
#Stop execution on any error
trap "fail_trap" EXIT
set -e
# Parsing command
case $1 in
'help'|h)
help
exit 0
;;
'install'|i)
ACTION="install"
shift
;;
'uninstall'|u)
uninstall
exit 0
;;
'build'|b)
ACTION="build"
shift
;;
'release'|r)
KO_RESOLVE_OPTIONS="--preserve-import-paths"
ACTION="build"
shift
;;
*)
ACTION="build"
;;
esac
set -u
# Parsing options (if any)
while [[ $# -gt 0 ]]; do
case $1 in
'--version')
shift
DASHBOARD_VERSION="${1}"
;;
'--nightly')
BASE_RELEASE_URL="https://storage.googleapis.com/tekton-releases-nightly/dashboard"
;;
'--read-write')
READONLY="false"
;;
'--stream-logs')
shift
STREAM_LOGS="${1}"
;;
'--external-logs')
shift
EXTERNAL_LOGS="${1}"
;;
'--namespace')
shift
OVERRIDE_NAMESPACE="${1}"
;;
'--extensions-rbac')
EXTENSIONS_RBAC="true"
;;
'--log-format')
shift
LOG_FORMAT="${1}"
;;
'--log-level')
shift
LOG_LEVEL="${1}"
;;
'--logout-url')
shift
LOGOUT_URL="${1}"
;;
'--pipelines-namespace')
shift
OVERRIDE_PIPELINES_NAMESPACE="${1}"
;;
'--triggers-namespace')
shift
OVERRIDE_TRIGGERS_NAMESPACE="${1}"
;;
'--tenant-namespace')
warning "--tenant-namespace is deprecated, use --tenant-namespaces instead"
shift
TENANT_NAMESPACES="${1}"
;;
'--tenant-namespaces')
shift
TENANT_NAMESPACES="${1}"
;;
'--ingress-default-class')
INGRESS_DEFAULT_CLASS="true"
;;
'--ingress-url')
shift
INGRESS_URL="${1}"
;;
'--ingress-secret')
shift
INGRESS_SECRET="${1}"
;;
'--debug')
DEBUG="true"
;;
'--output')
shift
OUTPUT_FILE="${1}"
;;
'--platform')
shift
PLATFORM="--platform ${1}"
;;
'--tag')
shift
KO_RESOLVE_OPTIONS="$KO_RESOLVE_OPTIONS -t ${1}"
;;
*)
echo "ERROR: Unknown option $1"
help
exit 1
;;
esac
shift
done
set +u
TMP_ROOT="$(mktemp -dt tekton-dashboard-installer.XXXXXX)"
TMP_FILE="$TMP_ROOT/manifest.yaml"
initOS
verifySupported
setup
if [ -z "$DASHBOARD_VERSION" ]; then
compile
else
download
fi
patch
rbac
ingress
eval $ACTION
cleanup