Skip to content

Commit 3de13a3

Browse files
committed
feat: add install Zone Argo CD script
1 parent 9830f18 commit 3de13a3

File tree

11 files changed

+304
-112
lines changed

11 files changed

+304
-112
lines changed

INSTALL.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,51 @@ watch "kubectl get ns | grep '\-mynamespace'"
376376
- Pour Kyverno : `-t kyverno`
377377
- La fonctionnalité actuellement remplie par le role Kyverno était auparavant gérée par un role kubed. C'est la raison pour laquelle la désinstallation de kubed est toujours disponible. Si kubed est encore présent dans votre cluster hébergeant le socle DSO, nous vous recommandons sa désinstallation via l'utilisation du tag `-t kubed` (ou `-t confSyncer`).
378378

379+
### Installation d'un Argo CD dans une nouvelle zone
380+
381+
Cette section décrit comment installer Argo CD dans une nouvelle zone.
382+
383+
Pour cela, connectez vous à votre console DSO et allez dans la page `Zones` dans la section `Administration` et suivez les instructions de la [documentation](https://cloud-pi-native.fr/administration/zones) pour créer une zone.
384+
385+
La création d'une zone déclenchera la création d'un repository GitLab DSO de la zone dans le groupe `infra`.
386+
387+
**NB: Une fois la zone créée, vous aurez besoin du nom court de la zone ainsi que du repository GitLab de la zone pour pouvoir l'utiliser dans l'installation.**
388+
389+
#### Installation
390+
391+
Veuillez suivre les étapes suivantes dans l'ordre pour installer l'instance Argo CD dans la nouvelle zone.
392+
393+
L'installation de l'instance Argo CD se fait de manière automatisée via un script bash.
394+
395+
Assurez-vous d'avoir le CLI [`argocd-vault-plugin`](https://argocd-vault-plugin.readthedocs.io/en/stable/installation/) installé et les variables d'environnement suivantes définies :
396+
397+
```bash
398+
export GITOPS_REPO_PATH=/chemin/absolu/vers/votre/gitops
399+
export VAULT_INFRA_DOMAIN=infra-vault.example.com
400+
export VAULT_INFRA_TOKEN=vault-infra-token
401+
```
402+
403+
Dans votre repository GitOps, créez un fichier `gitops/envs/conf-dso/apps/argocd/zone-<zoneName>-values.yaml` avec les valeurs suivantes :
404+
405+
```yaml
406+
# Repository GitLab DSO de la zone (n'oubliez pas le .git à la fin)
407+
dsoZoneRepo: <repository-git-lab-dso-de-la-zone>
408+
# Nom court de la zone
409+
zoneName: <zone-name>
410+
411+
# Les valeurs suivantes correspondent à la configuration de l'instance Argo CD dans la nouvelle zone.
412+
# Veuillez consulter la documentation Argo CD pour les valeurs possibles (https://github.com/argoproj/argo-helm/blob/main/charts/argo-cd/README.md)
413+
argocd:
414+
```
415+
416+
Positionnez votre kube context sur la zone cible et exécutez la commande suivante :
417+
418+
```bash
419+
./admin-tools/install-zone-argocd.sh
420+
```
421+
422+
Ce script va installer l'instance Argo CD dans la zone dans le namespace `dso-argocd`.
423+
379424
### Désinstaller un ou plusieurs outils
380425

381426
Le playbook de désinstallation peut aussi être utilisé pour supprimer un ou plusieurs outils **de manière ciblée**, via les tags associés.

admin-tools/install-zone-argocd.sh

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
5+
6+
echo "Starting deployment pre-flight checks..."
7+
echo "----------------------------------------"
8+
9+
# 1. Environment Variable Checks
10+
MISSING_VARS=0
11+
12+
if [[ -z "$GITOPS_REPO_PATH" ]]; then
13+
echo "❌ Error: Environment variable GITOPS_REPO_PATH is not defined or is empty."
14+
MISSING_VARS=1
15+
fi
16+
17+
if [[ -z "$VAULT_INFRA_TOKEN" ]]; then
18+
echo "❌ Error: Environment variable VAULT_INFRA_TOKEN is not defined or is empty."
19+
MISSING_VARS=1
20+
fi
21+
22+
if [[ -z "$VAULT_INFRA_DOMAIN" ]]; then
23+
echo "❌ Error: Environment variable VAULT_INFRA_DOMAIN is not defined or is empty."
24+
MISSING_VARS=1
25+
fi
26+
27+
if [[ $MISSING_VARS -ne 0 ]]; then
28+
echo ""
29+
echo "⚠️ Please set the missing environment variables and relaunch the script."
30+
exit 1
31+
fi
32+
33+
echo "✅ Environment variables are set."
34+
35+
# 2. Dependency Check: argocd-vault-plugin
36+
if ! command -v argocd-vault-plugin &> /dev/null; then
37+
echo "❌ Error: 'argocd-vault-plugin' CLI is not installed."
38+
echo ""
39+
echo "To install it via Homebrew, run:"
40+
echo " brew install argocd-vault-plugin"
41+
echo ""
42+
echo "For Linux or other methods via curl, refer to:"
43+
echo " https://argocd-vault-plugin.readthedocs.io/en/stable/installation/#on-linux-or-macos-via-curl"
44+
echo ""
45+
echo "⚠️ Please install the CLI, then relaunch this script."
46+
exit 1
47+
fi
48+
49+
echo "✅ argocd-vault-plugin is installed."
50+
51+
# 3. Directory and File Checks
52+
TARGET_DIR="$GITOPS_REPO_PATH/gitops/envs/conf-dso/apps/argocd"
53+
54+
if [[ ! -d "$TARGET_DIR" ]]; then
55+
echo "❌ Error: Directory $TARGET_DIR does not exist."
56+
exit 1
57+
fi
58+
59+
if [[ ! -f "$TARGET_DIR/values.yaml" ]]; then
60+
echo "❌ Error: The base 'values.yaml' was not found in $TARGET_DIR."
61+
exit 1
62+
fi
63+
64+
# Find all zone files matching the naming convention
65+
shopt -s nullglob
66+
ZONE_FILES=("$TARGET_DIR"/zone-*-values.yaml)
67+
shopt -u nullglob
68+
69+
if [[ ${#ZONE_FILES[@]} -eq 0 ]]; then
70+
echo "❌ Error: No files matching 'zone-<zoneName>-values.yaml' found in $TARGET_DIR."
71+
exit 1
72+
fi
73+
74+
# 4. Zone Selection
75+
ZONES=()
76+
for file in "${ZONE_FILES[@]}"; do
77+
filename=$(basename "$file")
78+
# Extract zoneName by stripping 'zone-' prefix and '-values.yaml' suffix
79+
zone=${filename#zone-}
80+
zone=${zone%-values.yaml}
81+
ZONES+=("$zone")
82+
done
83+
84+
SELECTED_ZONE=""
85+
if [[ ${#ZONES[@]} -eq 1 ]]; then
86+
SELECTED_ZONE="${ZONES[0]}"
87+
echo "✅ Found a single zone configuration: $SELECTED_ZONE"
88+
else
89+
echo ""
90+
echo "Multiple zone configurations found. Please select which zone you want to install:"
91+
PS3="Enter the number of the zone: "
92+
select zone_choice in "${ZONES[@]}"; do
93+
if [[ -n "$zone_choice" ]]; then
94+
SELECTED_ZONE="$zone_choice"
95+
break
96+
else
97+
echo "Invalid selection. Please try again."
98+
fi
99+
done
100+
fi
101+
102+
# 5. Confirmation prompt
103+
echo ""
104+
read -p "Do you want to install the '$SELECTED_ZONE' Zone ArgoCD? (y/n): " confirm
105+
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
106+
echo "Installation aborted by administrator."
107+
exit 0
108+
fi
109+
110+
echo "Proceeding with installation for zone: $SELECTED_ZONE..."
111+
echo "----------------------------------------"
112+
113+
# 6. Render Secrets with argocd-vault-plugin
114+
# Map the provided environment variables to standard AVP expected variables
115+
export AVP_TYPE=vault
116+
export AVP_AUTH_TYPE=token
117+
export VAULT_ADDR="https://$VAULT_INFRA_DOMAIN"
118+
export VAULT_TOKEN="$VAULT_INFRA_TOKEN"
119+
120+
# 7. Use AVP as a Helm Wrapper
121+
# This method renders the chart, injects the values, AND replaces placeholders in templates.
122+
123+
CHART_PATH="$GITOPS_REPO_PATH/gitops/envs/conf-dso/apps/argocd"
124+
RELEASE_NAME="argocd-$SELECTED_ZONE"
125+
NAMESPACE="dso-argocd"
126+
127+
echo "Step 1: Generating fully rendered manifest (Helm + AVP)..."
128+
129+
# We use 'helm template' to build the manifest, then pipe it to AVP to swap placeholders.
130+
# We save this to a temporary file to pipe into 'kubectl apply' or 'helm install'.
131+
FINAL_MANIFEST=$(mktemp)
132+
# Ensure the temporary manifest is deleted when the script exits
133+
trap 'rm -f "$FINAL_MANIFEST"' EXIT
134+
135+
echo "Ensuring namespace '$NAMESPACE' exists..."
136+
if ! kubectl get namespace "$NAMESPACE" &> /dev/null; then
137+
echo "Creating namespace '$NAMESPACE'..."
138+
kubectl create namespace "$NAMESPACE"
139+
else
140+
echo "✅ Namespace '$NAMESPACE' already exists."
141+
fi
142+
143+
helm dependency build "$CHART_PATH"
144+
helm template "$RELEASE_NAME" "$CHART_PATH" \
145+
--namespace "$NAMESPACE" \
146+
--values "$CHART_PATH/values.yaml" \
147+
--values "$CHART_PATH/zone-$SELECTED_ZONE-values.yaml" \
148+
| argocd-vault-plugin generate - > "$FINAL_MANIFEST"
149+
150+
if [[ $? -ne 0 ]]; then
151+
echo "❌ Error: argocd-vault-plugin failed to generate the manifest."
152+
exit 1
153+
fi
154+
155+
echo "✅ Manifest generated and secrets injected."
156+
157+
# 8. Deploy to Cluster
158+
echo "Step 2: Deploying to cluster..."
159+
160+
# 8a. Extract and Apply CRDs first
161+
echo "Installing CRDs first..."
162+
# This grep/sed logic finds the blocks that are Kind: CustomResourceDefinition
163+
# and applies only those to ensure the API server knows about them.
164+
awk '/^---/{if (p ~ /[kK]ind: CustomResourceDefinition/) print p; p=""} {p=p $0 "\n"} END{if (p ~ /[kK]ind: CustomResourceDefinition/) print p}' "$FINAL_MANIFEST" | kubectl apply -f -
165+
166+
# 8b. Wait for CRDs to be established
167+
# This gives the Kubernetes API server a few seconds to register the new types
168+
echo "Waiting for CRDs to be ready..."
169+
kubectl wait --for condition=established --timeout=60s crd -l "app.kubernetes.io/part-of=argocd" 2>/dev/null || sleep 5
170+
171+
# 8c. Apply the full manifest (including Namespace, Deployments, RBAC, etc.)
172+
echo "Applying full manifest..."
173+
echo ""
174+
if kubectl apply -f "$FINAL_MANIFEST" -n "$NAMESPACE" --server-side; then
175+
echo "🎉 Deployment of $SELECTED_ZONE zone completed successfully!"
176+
else
177+
echo "❌ Error: kubectl apply failed."
178+
exit 1
179+
fi
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
{% set dsoZoneRepo = 'https://' + gitlab_domain + '/' + dsc.global.projectsRootDir | join('/') + '/infra/' + dsc.argocd.zoneName + '.git' %}
21
apiVersion: argoproj.io/v1alpha1
32
kind: AppProject
43
metadata:
5-
name: zone-{{ dsc.argocd.zoneName }}-project
6-
namespace: {{ dsc.argocd.namespace }}
4+
name: "zone-{{ '{{ .Values.zoneName }}' }}-project"
75
spec:
86
description: "Projet contenant l'Application responsable de tous les déploiements par zone"
97
clusterResourceWhitelist:
108
- group: '*'
119
kind: '*'
1210
sourceRepos:
1311
- https://cloud-pi-native.github.io/helm-charts
14-
- {{ dsoZoneRepo }}
12+
- {{ '{{ .Values.dsoZoneRepo }}' }}
1513
destinations:
16-
- namespace: {{ dsc.argocd.namespace }}
14+
- namespace: {{ '{{ .Release.Namespace }}' }}
1715
server: "https://kubernetes.default.svc"
1816

1917
---
2018
apiVersion: argoproj.io/v1alpha1
2119
kind: Application
2220
metadata:
23-
name: zone-{{ dsc.argocd.zoneName }}-app
24-
namespace: {{ dsc.argocd.namespace }}
21+
name: "zone-{{ '{{ .Values.zoneName }}' }}-app"
2522
spec:
2623
destination:
27-
namespace: {{ dsc.argocd.namespace }}
24+
namespace: {{ '{{ .Release.Namespace }}' }}
2825
server: https://kubernetes.default.svc
29-
project: zone-{{ dsc.argocd.zoneName }}-project
26+
project: "zone-{{ '{{ .Values.zoneName }}' }}-project"
3027
sources:
3128
- chart: dso-argocd-zone
3229
targetRevision: {{ dsc.argocd.zoneChartVersion | quote }}
@@ -36,8 +33,8 @@ spec:
3633
- ./values.yaml
3734
- $argocdValues/argocd-values.yaml
3835
values: |
39-
dsoZoneRepo: {{ dsoZoneRepo }}
36+
dsoZoneRepo: {{ '{{ .Values.dsoZoneRepo }}' }}
4037
autosync: true
41-
- repoURL: {{ dsoZoneRepo }}
38+
- repoURL: {{ '{{ .Values.dsoZoneRepo }}' }}
4239
targetRevision: HEAD
4340
ref: argocdValues

roles/gitops/rendering-apps-files/templates/argocd/templates/clusterrolebinding-openshift.yml.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ roleRef:
1010
subjects:
1111
- kind: ServiceAccount
1212
name: "{{ dsc_name }}-argocd-repo-server"
13-
namespace: "{{ dsc.argocd.namespace }}"
13+
namespace: "{{ '{{ .Release.Namespace }}' }}"
1414
- kind: ServiceAccount
1515
name: argocd-server
16-
namespace: "{{ dsc.argocd.namespace }}"
16+
namespace: "{{ '{{ .Release.Namespace }}' }}"
1717
- kind: ServiceAccount
1818
name: "{{ dsc_name }}-redis"
19-
namespace: "{{ dsc.argocd.namespace }}"
19+
namespace: "{{ '{{ .Release.Namespace }}' }}"
2020
- kind: ServiceAccount
2121
name: "{{ dsc_name }}-redis-ha"
22-
namespace: "{{ dsc.argocd.namespace }}"
22+
namespace: "{{ '{{ .Release.Namespace }}' }}"
2323
- kind: ServiceAccount
2424
name: "{{ dsc_name }}-redis-ha-haproxy"
25-
namespace: "{{ dsc.argocd.namespace }}"
25+
namespace: "{{ '{{ .Release.Namespace }}' }}"
2626
{% endif %}

roles/gitops/rendering-apps-files/templates/argocd/templates/helm-docker-registry-secret.yml.j2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ apiVersion: v1
44
kind: Secret
55
metadata:
66
name: helm-docker-registry-secret
7-
namespace: {{ dsc.argocd.namespace }}
87
type: Opaque
98
stringData:
109
username: <path:{{ vaultinfra_kv_name }}/data/env/{{ dsc_name }}/apps/global/values#dockerAccount | jsonPath {.username}>

roles/gitops/rendering-apps-files/templates/argocd/templates/ingress.yml.j2

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)