-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathstorage-version-migration.sh
executable file
·83 lines (73 loc) · 2.51 KB
/
storage-version-migration.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
#!/bin/bash
# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
if ! hash jq >/dev/null 2>&1 ; then
echo "[ERROR] jq is not installed"
exit 1
fi
# Delete old job for storage version migration
kubectl -n shipwright-build delete job --selector app=storage-version-migration-shipwright --wait=true
# create new job for storage version migration
cat <<EOF | kubectl create -f -
apiVersion: batch/v1
kind: Job
metadata:
generateName: storage-version-migration-shipwright-
labels:
app: storage-version-migration-shipwright
app.kubernetes.io/component: storage-version-migration-job
app.kubernetes.io/name: shipwright-build
namespace: shipwright-build
spec:
backoffLimit: 10
template:
metadata:
annotations:
sidecar.istio.io/inject: "false"
labels:
app: storage-version-migration-shipwright
app.kubernetes.io/component: storage-version-migration-job
app.kubernetes.io/name: shipwright-build
spec:
serviceAccountName: shipwright-build-controller
containers:
- args:
- buildruns.shipwright.io
- builds.shipwright.io
- buildstrategies.shipwright.io
- clusterbuildstrategies.shipwright.io
image: gcr.io/knative-releases/knative.dev/pkg/apiextensions/storageversion/cmd/migrate
name: migrate
resources:
limits:
cpu: 1000m
memory: 1000Mi
requests:
cpu: 100m
memory: 100Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
restartPolicy: OnFailure
ttlSecondsAfterFinished: 600
EOF
JOB_NAME=$(kubectl -n shipwright-build get job --selector app=storage-version-migration-shipwright -o jsonpath='{.items[0].metadata.name}')
while [ "$(kubectl -n shipwright-build get job "${JOB_NAME}" -o json | jq -r '.status.completionTime // ""')" == "" ]; do
echo "[INFO] Storage version migraton job is still running"
sleep 10
done
isFailed="$(kubectl -n shipwright-build get job "${JOB_NAME}" -o json | jq -r '.status.conditions[] | select(.type == "Failed") | .status')"
if [ "${isFailed}" == "True" ]; then
echo "[ERROR] Storage version migration failed"
kubectl -n shipwright-build logs "job/${JOB_NAME}"
exit 1
fi
echo "[DONE]"