-
Notifications
You must be signed in to change notification settings - Fork 55
/
update_devworkspace_crds.sh
executable file
·71 lines (61 loc) · 2.46 KB
/
update_devworkspace_crds.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
#!/bin/bash
#
# Copyright (c) 2019-2024 Red Hat, Inc.
# 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.
#
set -e
INIT_ONLY=0
while [[ "$#" -gt 0 ]]; do
case $1 in
'--api-version') DEVWORKSPACE_API_VERSION=$2; shift 1;;
'--init') INIT_ONLY=1; shift 0;;
*) echo "Unknown argument $1 is specified."; exit 1;;
esac
shift 1
done
if [ -z "$DEVWORKSPACE_API_VERSION" ]; then
echo "Argument --api-version is required"
exit 1
fi
SCRIPT_DIR=$(cd "$(dirname "$0")" || exit; pwd)
if [[ ("$INIT_ONLY" -eq 1) &&
(-f "$SCRIPT_DIR/deploy/templates/crd/bases/workspace.devfile.io_devworkspaces.yaml") &&
(-f "$SCRIPT_DIR/deploy/templates/crd/bases/workspace.devfile.io_devworkspacetemplates.yaml") &&
("${DEVWORKSPACE_API_VERSION}" == $(cat "$SCRIPT_DIR/deploy/templates/crd/bases/devfile_version" 2>/dev/null))]]; then
echo "CRDs from devfile/api are already initialized"
exit 0
fi
TMP_DIR=$(mktemp -d)
echo "Downloading devfile/api CRDs to $TMP_DIR"
cd "$TMP_DIR"
git init
git remote add origin https://github.com/devfile/api.git
git config core.sparsecheckout true
mkdir -p .git/info
echo "crds/*" > .git/info/sparse-checkout
git fetch --quiet -p origin
if git show-ref --verify refs/tags/"${DEVWORKSPACE_API_VERSION}" --quiet; then
echo "DevWorkspace API is specified from tag ${DEVWORKSPACE_API_VERSION}"
git checkout --quiet tags/"${DEVWORKSPACE_API_VERSION}"
elif [[ -z $(git ls-remote --heads origin "${DEVWORKSPACE_API_VERSION}") ]]; then
echo "DevWorkspace API is specified from revision ${DEVWORKSPACE_API_VERSION}"
git checkout --quiet "${DEVWORKSPACE_API_VERSION}"
else
echo "DevWorkspace API is specified from branch ${DEVWORKSPACE_API_VERSION}"
git checkout --quiet "${DEVWORKSPACE_API_VERSION}"
fi
cp crds/workspace.devfile.io_devworkspaces.yaml \
crds/workspace.devfile.io_devworkspacetemplates.yaml \
"$SCRIPT_DIR/deploy/templates/crd/bases/"
echo "${DEVWORKSPACE_API_VERSION}" > "$SCRIPT_DIR/deploy/templates/crd/bases/devfile_version"
cd "$SCRIPT_DIR"