Skip to content

Commit

Permalink
feat: add var ARGOCD_USE_TLS to control tls
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicCoder committed Dec 20, 2024
1 parent b4c67fb commit e9ac2e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
imagePullPolicy: IfNotPresent
env:
- name: ARGOCD_SERVER_URL
value: "argocd-server.argocd.svc.cluster.local:443"
value: "argocd-server.argocd.svc.cluster.local"
envFrom:
- secretRef:
name: deploykf-sync-access
30 changes: 16 additions & 14 deletions sync_argocd_apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ ARGOCD_APP_NAME_PREFIX="${ARGOCD_APP_NAME_PREFIX:-}"
ARGOCD_NAMESPACE="${ARGOCD_NAMESPACE:-argocd}"

# the argocd server URL
# - If empty, port-forwarding will be used to connect to the argocd server.
ARGOCD_SERVER_URL="${ARGOCD_SERVER_URL:-}"
ARGOCD_USE_TLS="${ARGOCD_USE_TLS:-false}"

# credentials for argocd
# - If password is empty, and username is "admin", the 'argocd-initial-admin-secret' will be read from the cluster.
# This will NOT work if you have changed the ArgoCD admin password.
ARGOCD_USERNAME="${ARGOCD_USERNAME:-admin}"
ARGOCD_USERNAME="${ARGOCD_USERNAME:-}"
ARGOCD_PASSWORD="${ARGOCD_PASSWORD:-}"

# how to handle resources that require PRUNING (deletion)
Expand Down Expand Up @@ -118,29 +116,33 @@ function argocd_login() {
local _argocd_namespace="$2"
local _argocd_username="$3"
local _argocd_password="$4"
local _argocd_use_tls="$5"

# if "admin" is the username and no password is provided, get the password from the cluster
if [[ -z "$_argocd_username" || -z "$_argocd_password" ]]; then
# Check for empty username or password
if [[ -z "$_argocd_username" || -z "$_argocd_password" ]]; then
echo ">>> ERROR: empty username or password"
exit 1
fi

# if the server URL is not provided
if [[ -z "$_argocd_server_url" ]]; then
echo ">>> ERROR: Nn ArgoCD server URL provided"
exit 1
fi

# log in to argocd
echo ""
echo_blue "=========================================================================================="
echo_blue "Authenticating with ArgoCD..."
echo_blue "------------------------------------------------------------------------------------------"
echo_blue "Server: ${_argocd_server_url:-<port-forward>}"
echo_blue "Server: '$_argocd_server_url'"
echo_blue "Namespace: '$_argocd_namespace'"
echo_blue "Username: '$_argocd_username'"
echo_blue "Password: '**********'"
echo_blue "=========================================================================================="
if [[ -n "$_argocd_server_url" ]]; then
argocd login "$_argocd_server_url" --username "$_argocd_username" --password "$_argocd_password" --insecure --skip-test-tls
if [[ "$_argocd_use_tls" == "true" ]]; then
argocd login "$_argocd_server_url" --username "$_argocd_username" --password "$_argocd_password" --insecure
else
# NOTE: we must export ARGOCD_OPTS for all the argocd commands to see it
export ARGOCD_OPTS="--port-forward --port-forward-namespace '$_argocd_namespace'"
argocd login --username "$_argocd_username" --password "$_argocd_password"
argocd login "$_argocd_server_url" --username "$_argocd_username" --password "$_argocd_password" --plaintext
fi
echo_green ">>> DONE"
}
Expand Down Expand Up @@ -604,7 +606,7 @@ function ask_prune_mode() {
ARGOCD_APP_SELECTOR="app.kubernetes.io/part-of=${ARGOCD_APP_NAME_PREFIX}deploykf"

# authenticate to argocd
argocd_login "$ARGOCD_SERVER_URL" "$ARGOCD_NAMESPACE" "$ARGOCD_USERNAME" "$ARGOCD_PASSWORD"
argocd_login "$ARGOCD_SERVER_URL" "$ARGOCD_NAMESPACE" "$ARGOCD_USERNAME" "$ARGOCD_PASSWORD" "$ARGOCD_USE_TLS"

# ask the user to set a prune mode
if [[ "$ARGOCD_PRUNE_MODE" == "ask" ]]; then
Expand Down

0 comments on commit e9ac2e7

Please sign in to comment.