-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup_arlon.sh
executable file
·164 lines (132 loc) · 5.46 KB
/
setup_arlon.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
set -e
set -o pipefail
# $1 = expression
# $2 = sleep period
# $3 = iterations
function wait_until()
{
for i in `seq 1 $3`
do
eval $1 && return 0
echo "Waiting for \"$1\" to evaluate to true ..."
sleep $2
done
echo Timed out waiting for \"$1\"
return 1
}
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
os="linux"
arlon_os="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os="darwin"
arlon_os="Darwin"
fi
cpu=$(uname -m)
if [[ "$cpu" == "x86_64" ]]; then
arlon_arch="x86_64"
arch="amd64"
elif [[ "$cpu" == "arm64"* ]]; then
arlon_arch="arm64"
arch="arm64"
fi
if [ ! -d "$HOME/.local/bin" ] ; then
mkdir -p "$HOME/.local/bin"
fi
PATH=$PATH:$HOME/.local/bin
if ! which kubectl &> /dev/null ; then
curl -sLO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${os}/${arch}/kubectl"
chmod +x kubectl
mv kubectl ${HOME}/.local/bin/
fi
if [ -z "${KUBECONFIG}" ]; then
echo "Set the KUBECONFIG variable to your management cluster's config"
exit
fi
if [ -z "${AWS_REGION}" ]; then
echo "Set the AWS_REGION env variable"
exit
fi
if [ -z "${AWS_ACCESS_KEY_ID}" ]; then
echo "Set the AWS_ACCESS_KEY_ID env variable"
exit
fi
if [ -z "${AWS_SECRET_ACCESS_KEY}" ]; then
echo "Set the AWS_SECRET_ACCESS_KEY env variable"
exit
fi
if ! kubectl get ns argocd &> /dev/null ; then
echo creating argocd namespace
kubectl create ns argocd
fi
argocd_git_tag=${ARGOCD_GIT_TAG}
if [ -z "${argocd_git_tag}" ]; then
argocd_git_tag="release-2.4"
fi
echo applying argocd manifest from git tag: ${argocd_git_tag}
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/${argocd_git_tag}/manifests/install.yaml > /dev/null
if ! argocd &> /dev/null; then
echo downloading argocd CLI
curl -sSL -o ${HOME}/.local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-${os}-${arch}
chmod +x ${HOME}/.local/bin/argocd
fi
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
if pkill -f "kubectl port-forward svc/argocd-server" ; then
echo terminated previous port forwarding session
fi
wait_until 'set -o pipefail; pwd=$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)' 6 20
forwarding_port=8189
kubectl port-forward svc/argocd-server -n argocd ${forwarding_port}:443 &>/dev/null &
wait_until "argocd login localhost:${forwarding_port} --username admin --password ${pwd} --insecure" 10 20
if ! kubectl get ns arlon &> /dev/null ; then
echo creating arlon namespace
kubectl create ns arlon
fi
kubectl apply -f testing/manifests/
if ! kubectl get secret argocd-creds -n arlon &> /dev/null ; then
wait_until "auth_token=$(argocd account generate-token --account arlon)" 2 10
echo auth_token: ${auth_token}
# The file name 'config' is important as that's how it'll appear when mounted in arlon container
tmp_config=/tmp/config
wget -qc https://raw.githubusercontent.com/arlonproj/arlon/main/testing/argocd-config-for-controller.template.yaml --output-document=argocd-config-for-controller.template.yaml
mv argocd-config-for-controller.template.yaml ${tmp_config}
echo " auth-token: ${auth_token}" >> ${tmp_config}
echo creating argocd-creds secret
kubectl -n arlon create secret generic argocd-creds --from-file ${tmp_config}
rm -f ${tmp_config}
else
echo argo-creds secret already exists
fi
# Arlon CRDs
kubectl apply -f config/crd/bases
# Deploy arlon controller
kubectl apply -f deploy/manifests/
echo '------- waiting for arlon controller to become ready ---------'
wait_until 'set -o pipefail; kubectl get pods -n arlon | grep Running &> /dev/null' 10 30
echo Arlon controller is up and running
if ! which arlon &> /dev/null; then
echo Downloading arlon CLI
latestRelease=$(curl -L -s -H 'Accept: application/json' https://github.com/arlonproj/arlon/releases/latest)
latestVersion=$(echo $latestRelease | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
wget -qc https://github.com/arlonproj/arlon/releases/download/${latestVersion}/arlon_${arlon_os}_${arlon_arch}_${latestVersion}.tar.gz
tar -xf arlon_${arlon_os}_${arlon_arch}_${latestVersion}.tar.gz
mv arlon_${os}_${arch}_${latestVersion} ${HOME}/.local/bin/arlon
rm arlon_${arlon_os}_${arlon_arch}_${latestVersion}.tar.gz
fi
if ! which clusterctl &> /dev/null; then
echo Downloading clusterctl CLI
curl -L -o ${HOME}/.local/bin/clusterctl https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.1.6/clusterctl-${os}-${arch} -o clusterctl
chmod +x ${HOME}/.local/bin/clusterctl
fi
if ! which clusterawsadm &> /dev/null; then
echo Downloading clusterawsadm CLI
curl -L -o ${HOME}/.local/bin/clusterawsadm https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v1.5.0/clusterawsadm-${os}-${arch} -o clusterawsadm
chmod +x ${HOME}/.local/bin/clusterawsadm
fi
clusterawsadm bootstrap iam create-cloudformation-stack
export AWS_B64ENCODED_CREDENTIALS=$(clusterawsadm bootstrap credentials encode-as-profile)
clusterctl init --infrastructure aws
echo "To access ArgoCD UI, run: kubectl port-forward svc/argocd-server -n argocd ${forwarding_port}:443"
echo "Login as admin: ${pwd} into ArgoCD at http://localhost:${forwarding_port}"
echo "Run the following command to use kubectl, argocd, clusterctl, clusterawsadm, arlon (If not already installed)"
echo 'PATH=$PATH:$HOME/.local/bin'
echo Installation successfull