-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuttlectl
executable file
·98 lines (85 loc) · 2.34 KB
/
cuttlectl
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
#!/bin/bash
set -e
set -o pipefail
PKGS=https://github.com/cuttlefacts/packages.git
function usage {
echo "Usage:" >&2
echo "cuttlectl bootstrap" >&2
echo " bootstrap a cluster by installing a sync to the" >&2
echo " git origin of the working directory." >&2
echo >&2
echo "cuttlectl install <pkg> <dir>" >&2
echo " install the package <pkg> into the directory <dir>," >&2
echo " and add to the git index, ready to commit". >&2
echo >&2
echo "cuttlectl expand <dir>" >&2
echo " run the function specified in <dir> to generate YAMLs" >&2
echo >&2
echo "cuttlectl sync"
echo " ask the sync to pull from origin and apply" >&2
}
function bootstrap {
local origin=$(git remote get-url origin)
if [ -z "$origin" ]; then
echo "error: no git remote 'origin' found" >&2
exit 1
fi
echo "==> Getting flux-readonly package as bootstrap/" >&2
kpt pkg get $PKGS/flux-readonly@17eb975 bootstrap
echo "==> Setting bootstrap sync URL to $origin" >&2
kpt cfg set bootstrap git-url "$origin"
kpt cfg set bootstrap namespace bootstrap-system
echo "==> Commit changes and pushing to origin" >&2
git add bootstrap
git commit -m "Add bootstrap sync"
git push origin
echo "==> Applying bootstrap sync to cluster" >&2
# NB a little cheat: make sure the namespace is applied first,
# otherwise this will fail the first time.
kubectl apply -f bootstrap/*-ns.yaml
kubectl apply -f bootstrap/
}
function install {
# cuttlectl install <package> <dir>
local pkg="$1"
local dir="$2"
echo "=> Fetching package into $dir" >&2
kpt pkg get "$PKGS/$pkg" "$dir"
echo >&2
echo "Done. Next you may want to:" >&2
echo >&2
echo " git add $dir && git commit" >&2
}
function expand {
# cuttlectl expand <dir>
local dir="$1"
echo "==> Expanding package in $dir" >&2
kpt fn run "$dir"
echo >&2
echo "Done. Next you may want to:" >&2
echo >&2
echo " git add $dir && git commit" >&2
}
function sync {
# cuttlectl sync
fluxctl --k8s-fwd-ns bootstrap-system sync
}
CMD=$1
shift 1
case "$CMD" in
bootstrap)
bootstrap
;;
install)
install "$1" "$2"
;;
expand)
expand "$1"
;;
sync)
sync
;;
*)
usage
;;
esac