forked from opendatahub-io/opendatahub-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_all_manifests.sh
executable file
·90 lines (76 loc) · 3.74 KB
/
get_all_manifests.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
#!/usr/bin/env bash
set -e
GITHUB_URL="https://github.com"
# component: notebook, dsp, kserve, dashbaord, cf/ray/kueue/trainingoperator, trustyai, modelmesh, modelregistry.
# in the format of "repo-org:repo-name:ref-name:source-folder:target-folder".
declare -A COMPONENT_MANIFESTS=(
["codeflare"]="opendatahub-io:codeflare-operator:main:config:codeflare"
["ray"]="opendatahub-io:kuberay:dev:ray-operator/config:ray"
["kueue"]="opendatahub-io:kueue:dev:config:kueue"
["data-science-pipelines-operator"]="opendatahub-io:data-science-pipelines-operator:main:config:data-science-pipelines-operator"
["odh-dashboard"]="opendatahub-io:odh-dashboard:main:manifests:dashboard"
["kf-notebook-controller"]="opendatahub-io:kubeflow:v1.7-branch:components/notebook-controller/config:odh-notebook-controller/kf-notebook-controller"
["odh-notebook-controller"]="opendatahub-io:kubeflow:v1.7-branch:components/odh-notebook-controller/config:odh-notebook-controller/odh-notebook-controller"
["notebooks"]="opendatahub-io:notebooks:main:manifests:notebooks"
["trustyai"]="trustyai-explainability:trustyai-service-operator:main:config:trustyai-service-operator"
["model-mesh"]="opendatahub-io:modelmesh-serving:release-0.12.0-rc0:config:model-mesh"
["odh-model-controller"]="opendatahub-io:odh-model-controller:incubating:config:odh-model-controller"
["kserve"]="opendatahub-io:kserve:release-v0.14:config:kserve"
["modelregistry"]="opendatahub-io:model-registry-operator:main:config:model-registry-operator"
["trainingoperator"]="opendatahub-io:training-operator:dev:manifests:trainingoperator"
)
# Allow overwriting repo using flags component=repo
pattern="^[a-zA-Z0-9_.-]+:[a-zA-Z0-9_.-]+:[a-zA-Z0-9_.-]+:[a-zA-Z0-9_./-]+:[a-zA-Z0-9_./-]+$"
if [ "$#" -ge 1 ]; then
for arg in "$@"; do
if [[ $arg == --* ]]; then
arg="${arg:2}" # Remove the '--' prefix
IFS="=" read -r key value <<< "$arg"
if [[ -n "${COMPONENT_MANIFESTS[$key]}" ]]; then
if [[ ! $value =~ $pattern ]]; then
echo "ERROR: The value '$value' does not match the expected format 'repo-org:repo-name:branch-name:source-folder:target-folder'."
continue
fi
COMPONENT_MANIFESTS["$key"]=$value
else
echo "ERROR: '$key' does not exist in COMPONENT_MANIFESTS, it will be skipped."
echo "Available components are: [${!COMPONENT_MANIFESTS[@]}]"
exit 1
fi
else
echo "Warning: Argument '$arg' does not follow the '--key=value' format."
fi
done
fi
TMP_DIR=$(mktemp -d -t "odh-manifests.XXXXXXXXXX")
trap '{ rm -rf -- "$TMP_DIR"; }' EXIT
function git_fetch_ref()
{
local repo=$1
local ref=$2
local dir=$3
local git_fetch="git fetch -q --depth 1 $repo"
mkdir -p $dir
pushd $dir &>/dev/null
git init -q
# try tag first, avoid printing fatal: couldn't find remote ref
if ! $git_fetch refs/tags/$ref 2>/dev/null ; then
$git_fetch refs/heads/$ref
fi
git reset -q --hard FETCH_HEAD
popd &>/dev/null
}
for key in "${!COMPONENT_MANIFESTS[@]}"; do
echo -e "\033[32mCloning repo \033[33m${key}\033[32m:\033[0m ${COMPONENT_MANIFESTS[$key]}"
IFS=':' read -r -a repo_info <<< "${COMPONENT_MANIFESTS[$key]}"
repo_org="${repo_info[0]}"
repo_name="${repo_info[1]}"
repo_ref="${repo_info[2]}"
source_path="${repo_info[3]}"
target_path="${repo_info[4]}"
repo_url="${GITHUB_URL}/${repo_org}/${repo_name}"
repo_dir=${TMP_DIR}/${key}
git_fetch_ref ${repo_url} ${repo_ref} ${repo_dir}
mkdir -p ./opt/manifests/${target_path}
cp -rf ${repo_dir}/${source_path}/* ./opt/manifests/${target_path}
done