-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkubespray-repo-setup.sh
executable file
·86 lines (69 loc) · 1.64 KB
/
kubespray-repo-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
#!/bin/bash
if [ -z "$KUBESPRAY_REPO_DIR" ]; then
echo Missing var KUBESPRAY_REPO_DIR
exit 1
fi
if which pip3.9 2>/dev/null; then
PIP=pip3.9
elif which pip3.8 2>/dev/null; then
PIP=pip3.8
else
PIP=pip3
fi
export GIT_DIR=$KUBESPRAY_REPO_DIR/.git
set -eu
function validate_parameters()
{
if [[ "${KUBESPRAY_GIT_REF}" =~ ^refs/(heads|tags)/.* ]]; then
return 0
elif [[ "${KUBESPRAY_GIT_REF}" =~ ^remotes/origin/.* ]]; then
return 0
fi
echo "Invalid git ref: $KUBESPRAY_GIT_REF. Accepted format: refs/{heads|tags}/{name}"
exit 1
}
function command_create()
{
validate_parameters
if [ -e "$KUBESPRAY_DIR" ]; then
rm -rf "$KUBESPRAY_DIR"
fi
ln -fs $KUBESPRAY_REPO_DIR $KUBESPRAY_DIR
git reset --hard
git checkout "$KUBESPRAY_GIT_REF" >&2
$PIP install -r $KUBESPRAY_REPO_DIR/requirements.txt >&2
command_read
}
function command_update()
{
validate_parameters
command_create
}
function command_read()
{
{
git_hash=$(git log -1 --pretty=format:%h)
git_ref="$(git rev-parse --symbolic-full-name $KUBESPRAY_GIT_REF)"
requirements_txt_id=$(md5sum $KUBESPRAY_REPO_DIR/requirements.txt | awk '{print $1}')
} >&2
kubespray_link=""
if [ -e "$KUBESPRAY_DIR" ]; then
kubespray_link="$KUBESPRAY_DIR"
fi
jq -Mcn \
--arg git_hash $git_hash \
--arg git_ref $git_ref \
--arg requirements_txt_id $requirements_txt_id \
--arg kubespray_link $kubespray_link \
'{
"git_hash": $git_hash,
"git_ref": $git_ref,
"requirements_txt_id": $requirements_txt_id,
"kubespray_repo": $kubespray_link
}'
}
function command_delete()
{
echo {}
}
eval command_$1