6
6
7
7
set -o errexit
8
8
9
-
10
- export KUBECONFIG=/home/$USER /.kube/config
11
-
12
- # Add /usr/local/bin to the PATH as some utilities, like kubectl, could be installed there
13
- export PATH=$PATH :/usr/local/bin
14
- IMAGE_REGISTRY=" ${IMAGE_REGISTRY:- docker.io} "
15
-
16
- upgrade_argocd () {
17
-
18
9
cat << "EOF "
19
10
20
11
_ ____ ____ _ _ _
@@ -26,6 +17,10 @@ cat << "EOF"
26
17
27
18
EOF
28
19
20
+ export KUBECONFIG=/home/$USER /.kube/config
21
+
22
+ # Add /usr/local/bin to the PATH as some utilities, like kubectl, could be installed there
23
+ export PATH=$PATH :/usr/local/bin
29
24
30
25
cp /tmp/argo-cd/values.tmpl /tmp/argo-cd/argo-cd/templates/values.tmpl
31
26
# helm treats comma as separator in '--set' command, so multiple no_proxy values are treated as different env values, so we have to write them to file first
@@ -96,127 +91,3 @@ applicationSet:
96
91
echo " ArgoCD Helm Chart is being upgraded, please wait, timeout is set to 10m..."
97
92
helm upgrade argocd /tmp/argo-cd/argo-cd --values /tmp/argo-cd/values.yaml -f /tmp/argo-cd/mounts.yaml -n argocd \
98
93
--wait --timeout 15m0s
99
- }
100
-
101
-
102
- processSAN () {
103
- local result=" subjectAltName=DNS:localhost"
104
- for domain in " $@ " ; do
105
- result=" ${result} ,DNS:${domain} "
106
- done
107
- echo " ${result} "
108
- }
109
-
110
- processCerts () {
111
- echo " Generating key..."
112
-
113
- if ! openssl version; then
114
- echo " OpenSSL not found!"
115
- exit 1
116
- fi
117
-
118
- openssl=" openssl"
119
-
120
- tmpDir=$( mktemp -d)
121
- $openssl genrsa -out " $tmpDir /infra-tls.key" 4096
122
-
123
- echo " Generating certificate..."
124
- san=$( processSAN " $@ " )
125
- # Generate the certificate with the name infra-tls.crt
126
- $openssl req -key " $tmpDir /infra-tls.key" -new -x509 -days 365 -out " $tmpDir /infra-tls.crt" -subj " /C=US/O=Orch Deploy/OU=Open Edge Platform" -addext " $san "
127
- cp " ${tmpDir} " /infra-tls.crt /usr/local/share/ca-certificates/gitea_cert.crt
128
- update-ca-certificates
129
-
130
- # Create a tls secret with custom key names
131
- kubectl create secret tls gitea-tls-certs -n gitea \
132
- --cert=" $tmpDir /infra-tls.crt" \
133
- --key=" $tmpDir /infra-tls.key"
134
-
135
- # Clean up the temporary directory
136
- rm -rf " $tmpDir "
137
- }
138
-
139
- randomPassword () {
140
- tr -dc A-Za-z0-9 < /dev/urandom | head -c 16
141
- }
142
-
143
- createGiteaSecret () {
144
- local secretName=$1
145
- local accountName=$2
146
- local password=$3
147
- local namespace=$4
148
-
149
- kubectl create secret generic " $secretName " -n " $namespace " \
150
- --from-literal=username=" $accountName " \
151
- --from-literal=password=" $password " \
152
- --dry-run=client -o yaml | kubectl apply -f -
153
- }
154
-
155
- createGiteaAccount () {
156
- local secretName=$1
157
- local accountName=$2
158
- local password=$3
159
- local email=$4
160
- local giteaPods=" "
161
- local giteaPod=" "
162
-
163
- giteaPods=$( kubectl get pods -n gitea -l app=gitea -o jsonpath=" {.items[*].metadata.name}" )
164
- if [ -z " $giteaPods " ]; then
165
- echo " No Gitea pods found. Exiting."
166
- exit 1
167
- fi
168
-
169
- giteaPod=$( echo " $giteaPods " | cut -d ' ' -f1)
170
- if ! kubectl exec -n gitea " $giteaPod " -c gitea -- gitea admin user list | grep -q " $accountName " ; then
171
- echo " Creating Gitea account for $accountName "
172
- kubectl exec -n gitea " $giteaPod " -c gitea -- gitea admin user create --username " $accountName " --password " $password " --email " $email " --must-change-password=false
173
- else
174
- echo " Gitea account for $accountName already exists, updating password"
175
- kubectl exec -n gitea " $giteaPod " -c gitea -- gitea admin user change-password --username " $accountName " --password " $password " --must-change-password=false
176
- fi
177
-
178
- userToken=$( kubectl exec -n gitea " $giteaPod " -c gitea -- gitea admin user generate-access-token --scopes write:repository,write:user --username " $accountName " --token-name " ${accountName} -$( date +%s) " )
179
- token=$( echo " $userToken " | awk ' {print $NF}' )
180
- kubectl create secret generic gitea-" $accountName " -token -n gitea --from-literal=token=" $token "
181
- }
182
-
183
- upgrade_gitea () {
184
- cat << "EOF "
185
-
186
- ____ _ _ _ _ _
187
- / ___(_) |_ ___ __ _ | | | |_ __ __ _ _ __ __ _ __| | ___
188
- | | _| | __/ _ \/ _` | | | | | '_ \ / _` | '__/ _` |/ _` |/ _ \
189
- | |_| | | || __/ (_| | | |_| | |_) | (_| | | | (_| | (_| | __/
190
- \____|_|\__\___|\__,_| \___/| .__/ \__, |_| \__,_|\__,_|\___|
191
- |_| |___/
192
-
193
- EOF
194
-
195
- kubectl create ns gitea > /dev/null 2>&1 || true
196
- kubectl create ns orch-platform > /dev/null 2>&1 || true
197
- kubectl -n gitea get secret gitea-tls-certs > /dev/null 2>&1 || processCerts gitea-http.gitea.svc.cluster.local
198
-
199
- adminGiteaPassword=$( randomPassword)
200
- argocdGiteaPassword=$( randomPassword)
201
- appGiteaPassword=$( randomPassword)
202
- clusterGiteaPassword=$( randomPassword)
203
-
204
- # Create secret for Gitea admin user but should not be used for normal operations
205
- createGiteaSecret " gitea-cred" " gitea_admin" " $adminGiteaPassword " " gitea"
206
-
207
- # Create user credential secrets for ArgoCD, AppOrch and ClusterOrch
208
- createGiteaSecret " argocd-gitea-credential" " argocd" " $argocdGiteaPassword " " gitea"
209
- createGiteaSecret " app-gitea-credential" " apporch" " $appGiteaPassword " " orch-platform"
210
- createGiteaSecret " cluster-gitea-credential" " clusterorch" " $clusterGiteaPassword " " orch-platform"
211
-
212
- # More helm values are set in ../assets/gitea/values.yaml
213
- helm upgrade --install gitea /tmp/gitea/gitea --values /tmp/gitea/values.yaml --set gitea.admin.existingSecret=gitea-cred --set image.registry=" ${IMAGE_REGISTRY} " -n gitea --timeout 15m0s --wait
214
-
215
- # Create Gitea accounts for ArgoCD, AppOrch and ClusterOrch
216
- createGiteaAccount
" argocd-gitea-credential" " argocd" " $argocdGiteaPassword " " [email protected] "
217
- createGiteaAccount
" app-gitea-credential" " apporch" " $appGiteaPassword " " [email protected] "
218
- createGiteaAccount
" cluster-gitea-credential" " clusterorch" " $clusterGiteaPassword " " [email protected] "
219
- }
220
-
221
- upgrade_gitea
222
- upgrade_argocd
0 commit comments