Skip to content

Commit db2b0a7

Browse files
authored
Merge pull request #625 from butler54/argocd-cli
feat: add script to login to argocd using the cli
2 parents 71c640d + cbdaac5 commit db2b0a7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

scripts/argocd-login.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
## Login to validated patterns argocd instances
4+
5+
# Detect Argo CD namespaces
6+
ARGOCD_NAMESPACES=$(oc get argoCD -A -o jsonpath='{.items[*].metadata.namespace}')
7+
if [ -z "$ARGOCD_NAMESPACES" ]; then
8+
echo "Error: No Argo CD instances found in the cluster."
9+
exit 1
10+
fi
11+
12+
# Split the namespaces into an array
13+
NAMESPACES=($ARGOCD_NAMESPACES)
14+
15+
# Check if there are at least two Argo CD instances
16+
if [ ${#NAMESPACES[@]} -lt 2 ]; then
17+
echo "Error: Less than two Argo CD instances found. Found instances in namespaces: $ARGOCD_NAMESPACES"
18+
exit 1
19+
fi
20+
21+
22+
for NAMESPACE in ${NAMESPACES[@]}; do
23+
# get the instance name
24+
ARGOCD_INSTANCE=$(oc get argocd -n "$NAMESPACE" -o jsonpath='{.items[0].metadata.name}') # assume only one per NS
25+
SERVER_URL=$(oc get route "$ARGOCD_INSTANCE"-server -n "$NAMESPACE" -o jsonpath='{.status.ingress[0].host}')
26+
PASSWORD=$(oc get secret "$ARGOCD_INSTANCE"-cluster -n "$NAMESPACE" -o jsonpath='{.data.admin\.password}' | base64 -d)
27+
echo $PASSWORD
28+
argocd login --skip-test-tls --insecure --grpc-web "$SERVER_URL" --username "admin" --password "$PASSWORD"
29+
if [ "$?" -ne 0 ]; then
30+
echo "Login to Argo CD ${SERVER_URL} failed. Exiting."
31+
exit 1
32+
fi
33+
34+
done

0 commit comments

Comments
 (0)