Using Orchestrator Configurator Tool error Connection refused

Configurator tool failing with connection refused error?

Issue Description:

In the v2023 Automation Suite, when running the configurator tool, the ArgoCD server attempts to connect to localhost:8080, resulting in a “connection refused” error.

Solution Steps: To mitigate this issue, connect the ArgoCD server to the server’s IP address at port 443. Perform the below steps.

  1. Create a Script File:
    • Create a file named updated-orchestrator-configurator.sh
  2. Edit the Script File:
    1. Open the file using a text editor (e.g., vi updated-orchestrator-configurator.sh)
    2. Copy and paste the following content into the file
#!/bin/bash

# Copyright UiPath 2021
#
# =================
# LICENSE AGREEMENT
# -----------------
#   Use of paid UiPath products and services is subject to the licensing agreement
#   executed between you and UiPath. Unless otherwise indicated by UiPath, use of free
#   UiPath products is subject to the associated licensing agreement available here:
#   https://www.uipath.com/legal/trust-and-security/legal-terms (or successor website).
#   You must not use this file separately from the product it is a part of or is associated with.

set -e

function print_usage()
{
echo "
Usage: ./orchestrator_migrator.sh -d -y \
  -k \"enc key value\" \
  -c appsettings.custom.json -l nlog.custom.json \
  -s blobstoragefolder -p pluginsfolder -n nlogextensionsfolder 

    -k|--encryption-key
        the value of the encryption key that will override the key generated at install

    -c|--app-settings
        application settings file containing json with key-value structure
    -l|--nlog-config-file
        nlog config file, json, including the NLog top level node (case sensitive)

    -s|--storage-folder
        location of the storage folder on the local disk
    -n|--nlog-extensions-folder
        location of the nlog extensions on the local disk
    -p|--securestore-plugins-folder
        location of the securestore plugins on the local disk
    --use-external-storage
        use external storage instead of in cluster CEPH storage

    -d|--dry-run
        do not update the orchestrator app with the new values
    -y|--accept-all
        do not prompt for confirmation of actions

    --skip-restart
        do not restart orchestrator
"
}

# Parse the input params and stores them in:
# APPCONFIG_FILE, NLOG_EXTENSIONS_CONFIGFILE - json files containing appConfig or nlog configuration
# STORAGE_FOLDER, NLOG_EXTENSIONS_FOLDER, SECURESTORE_PLUGINS_FOLDER - folders containing files to be copied to orchestrator
# QUIET, DRY_RUN - flags to specify if confirmation is required, or if changes should be omitted
# folders and file paths may be relative, but they must exist, otherwise the script will return an error
function parse_input() {
    if [[ $# -eq 0 ]]; then
        print_usage
        exit 1
    fi
    declare -a unexpected_args=()

    while [[ $# -gt 0 ]]; do
    local key="$1"

    case $key in

        -k|--encryption-key)
        ENCRYPTION_KEY="$2"
        shift # past argument
        shift # past value
        ;;
        -c|--app-settings)
        APPCONFIG_FILE="$2"
        shift # past argument
        shift # past value
        ;;
        -l|--nlog-config-file)
        NLOG_EXTENSIONS_CONFIGFILE="$2"
        shift # past argument
        shift # past value
        ;;

        -s|--storage-folder)
        STORAGE_FOLDER="$2"
        shift # past argument
        shift # past value
        ;;
        -n|--nlog-extensions-folder)
        NLOG_EXTENSIONS_FOLDER="$2"
        shift # past argument
        shift # past value
        ;;
        -p|--securestore-plugins-folder)
        SECURESTORE_PLUGINS_FOLDER="$2"
        shift # past argument
        shift # past value
        ;;
        
        --use-external-storage)
        USE_EXTERNAL_STORAGE="Yes"
        shift # past argument
        ;;
        
        -d|--dry-run)
        DRY_RUN="Yes"
        shift # past argument
        ;;
        -y|--accept-all)
        QUIET="Yes"
        shift # past argument
        ;;
        --skip-restart)
        SKIP_RESTART="Yes"
        shift # past argument
        ;;
        *)    # unknown option
        unexpected_args+=("$1") # save it in an array for later
        shift # past argument
        ;;

    esac
    done

    # no extra arguments for this command
    if [[ ${#unexpected_args[@]} -gt 0 ]]; then
        echo "Error: Unexpected arguments: ${unexpected_args[*]}"
        print_usage
        exit 1
    fi

    local current_folder
    current_folder="$(pwd)"
    local input_validation_error=0
    
    # check if the folders exist
    if [[ -n "$STORAGE_FOLDER" ]]; then
        if [[ ! -d "$STORAGE_FOLDER" ]]; then
            echo "Storage folder not found: $STORAGE_FOLDER"
            input_validation_error=1
        else
            cd "$STORAGE_FOLDER" || exit 1
            STORAGE_FOLDER=$(pwd)
            cd "$current_folder" || exit 1
        fi
    fi
    if [[ -n "$NLOG_EXTENSIONS_FOLDER" ]]; then
        if [[ ! -d "$NLOG_EXTENSIONS_FOLDER" ]]; then
            echo "Nlog extensions folder not found: $NLOG_EXTENSIONS_FOLDER"
            input_validation_error=1
        else
            cd "$NLOG_EXTENSIONS_FOLDER" || exit 1
            NLOG_EXTENSIONS_FOLDER=$(pwd)
            cd "$current_folder" || exit 1
        fi
    fi
    if [[ -n "$SECURESTORE_PLUGINS_FOLDER" ]]; then
        if [[ ! -d "$SECURESTORE_PLUGINS_FOLDER" ]]; then
            echo "Securestore plugins folder not found: $SECURESTORE_PLUGINS_FOLDER"
            input_validation_error=1
        else    
            cd "$SECURESTORE_PLUGINS_FOLDER" || exit 1
            SECURESTORE_PLUGINS_FOLDER=$(pwd)
            cd "$current_folder" || exit 1
        fi
    fi

    if [[ -n "$APPCONFIG_FILE" ]]; then
        if [[ ! -f "$APPCONFIG_FILE" ]]; then
            echo "Appconfig file not found: $APPCONFIG_FILE"
            input_validation_error=1
        fi
    fi
    if [[ -n "$NLOG_EXTENSIONS_CONFIGFILE" ]]; then
        if [[ ! -f "$NLOG_EXTENSIONS_CONFIGFILE" ]]; then
            echo "Nlog extensions configfile not found: $NLOG_EXTENSIONS_CONFIGFILE"
            input_validation_error=1
        fi
    fi

    if [[ $input_validation_error -ne 0 ]]; then
        print_usage
        exit $input_validation_error
    fi

}

function expect_user_yes()
{
    echo -n "Do you want to proceed? (y/N): "
    read -r PROCEED
    if ! [[ $PROCEED == "y" ]]; then
        echo "Execution aborted"
        exit 0
    fi
}

function user_confirm() {
    echo "Orchestrator Migration Tool"
    echo "==========================="

    if [[ -n "$ENCRYPTION_KEY" ]]; then
        echo "Override current EncryptionKey with ${ENCRYPTION_KEY:0:4}***"
    fi

    if [[ -n "$APPCONFIG_FILE" ]]; then 
        echo "$APPCONFIGKEY: $(jq -c < "$APPCONFIG_FILE")"
        configmap_override=1
    fi
    if [[ -n "$NLOG_EXTENSIONS_CONFIGFILE" ]]; then
        echo "NLog extensions config: $(jq -c < "$NLOG_EXTENSIONS_CONFIGFILE")"
        configmap_override=1
    fi

    if [[ -n "$STORAGE_FOLDER" ]]; then
        echo "Storage folder: $STORAGE_FOLDER"
    fi
    if [[ -n "$NLOG_EXTENSIONS_FOLDER" ]]; then
        echo "NLog extensions folder: $NLOG_EXTENSIONS_FOLDER"
    fi
    if [[ -n "$SECURESTORE_PLUGINS_FOLDER" ]]; then
        echo "Securestore plugins assemblies: $SECURESTORE_PLUGINS_FOLDER"
    fi

    if [[ -z "$QUIET" ]]; then
        expect_user_yes
    fi
}

# retrieves the name of an orchestrator pod
function get_orch_pod() {
    ORCH_POD=$(kubectl get pod \
        --selector=app.kubernetes.io/component=orchestrator,app.kubernetes.io/instance=orchestrator,app.kubernetes.io/name=orchestrator \
        --namespace uipath \
        --output jsonpath="{.items[0].metadata.name}")
    echo "OrchPod:$ORCH_POD"
}

function configure_storage() {
  local SECRET_NAME="$1"

  if [[ -z "$RCLONE_CONFIG" ]]; then
    RCLONE_CONFIG=$(mktemp /tmp/orch.XXXXX.rclone.conf)
    export RCLONE_CONFIG
    trap 'rm -f -- "$RCLONE_CONFIG"' INT TERM HUP EXIT
  fi
  
  RCLONE_ADDITIONAL_ARGS=""
  EXTERNAL_STORAGE_BUCKET=""
  [[ "$USE_EXTERNAL_STORAGE" == "Yes" ]] && SECRET_NAME="$ORCHESTRATOR_EXTERNAL_STORAGE_SECRET_NAME"
  STORAGE_SECRET_DATA=$(kubectl get secret "$SECRET_NAME" --namespace uipath --output jsonpath="{.data}")

  if [[ "$USE_EXTERNAL_STORAGE" == "Yes" ]]; then
    STORAGE_TYPE=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".STORAGE_TYPE" | base64 -d)
    EXTERNAL_STORAGE_BUCKET=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".BUCKET" | base64 -d)
    if [[ "${STORAGE_TYPE}" == "s3" ]]; then
        configure_s3_storage
    else
        configure_azure_storage
    fi
  else
    configure_storage_ceph
  fi

  echo "Use external: $USE_EXTERNAL_STORAGE $STORAGE_TYPE Bucket: $EXTERNAL_STORAGE_BUCKET"
}

function configure_storage_ceph() {
  local OBJECT_STORAGE_ACCESSKEY
  local OBJECT_STORAGE_SECRETKEY
  local OBJECT_STORAGE_HOST
  local OBJECT_STORAGE_PORT
  local OBJECT_STORAGE_PROTOCOL=http

  OBJECT_STORAGE_ACCESSKEY=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".OBJECT_STORAGE_ACCESSKEY" | base64 -d)
  OBJECT_STORAGE_SECRETKEY=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".OBJECT_STORAGE_SECRETKEY" | base64 -d)
  OBJECT_STORAGE_HOST=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".OBJECT_STORAGE_EXTERNAL_HOST" | base64 -d)
  OBJECT_STORAGE_PORT=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".OBJECT_STORAGE_EXTERNAL_PORT" | base64 -d)

  [[ "${OBJECT_STORAGE_PORT}" == "443" ]] && OBJECT_STORAGE_PROTOCOL=https

  rclone config create external-storage s3 provider=Other \
   access_key_id="${OBJECT_STORAGE_ACCESSKEY}" secret_access_key="${OBJECT_STORAGE_SECRETKEY}" \
   endpoint="${OBJECT_STORAGE_PROTOCOL}://${OBJECT_STORAGE_HOST}:${OBJECT_STORAGE_PORT}" region="us-east-1" acl="private" > /dev/null
  # rclone will return 403 when cutoff is not set to 0
  RCLONE_ADDITIONAL_ARGS="--s3-upload-cutoff 0"
}

function configure_s3_storage() {
  local S3_REGION
  local S3_USE_INSTANCE_PROFILE
  local S3_ACCESSKEY
  local S3_SECRETKEY
  local S3_HOST
  local S3_PORT

  S3_REGION=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".REGION" | base64 -d)
  S3_USE_INSTANCE_PROFILE=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".USE_INSTANCE_PROFILE" | base64 -d)
  
  if [[ "${S3_USE_INSTANCE_PROFILE}" == "true" ]]; then
    rclone config create external-storage s3 provider=AWS \
      location_constraint="${S3_REGION}" region="${S3_REGION}" \
      acl="private" env_auth="true" > /dev/null
  else
    S3_ACCESSKEY=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".ACCESSKEY" | base64 -d)
    S3_SECRETKEY=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".SECRETKEY" | base64 -d)
    S3_HOST=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".FQDN" | base64 -d)
    S3_PORT=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".PORT" | base64 -d)

    local url="https://${S3_HOST}"
    [[ "${S3_PORT}" != "443" ]] && url="${url}:${S3_PORT}"

    rclone config create external-storage s3 provider=Other \
      access_key_id="${S3_ACCESSKEY}" secret_access_key="${S3_SECRETKEY}" \
      endpoint="${url}" location_constraint="${S3_REGION}" region="${S3_REGION}" acl="private" > /dev/null
  fi
}

function configure_azure_storage() {
  local AZURE_USE_MANAGED_IDENTITY
  local AZURE_ACCOUNTNAME
  local AZURE_CLIENT_ID
  local azure_msi_client_id_field
  local AZURE_ACCOUNTKEY

  AZURE_USE_MANAGED_IDENTITY=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".USE_MANAGED_IDENTITY" | base64 -d)
  AZURE_ACCOUNTNAME=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".ACCOUNTNAME" | base64 -d)
  AZURE_ACCOUNTNAME=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".ACCOUNTNAME" | base64 -d)
  AZURE_FQDN_SUFFIX=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".AZURE_FQDN_SUFFIX" | base64 -d)

  if [[ -z "$AZURE_FQDN_SUFFIX" ]]; then
    AZURE_FQDN_SUFFIX="core.windows.net"
  fi

  if [[ "${AZURE_USE_MANAGED_IDENTITY}" == "true" ]]; then
    AZURE_CLIENT_ID=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".CLIENT_ID" | base64 -d)
    azure_msi_client_id_field=""
    [[ "${AZURE_CLIENT_ID}" == "CLIENT_ID" ]] && AZURE_CLIENT_ID=""
    [[ -n "${AZURE_CLIENT_ID}" ]] && azure_msi_client_id_field="msi_client_id  ${AZURE_CLIENT_ID}"

    #shellcheck disable=SC2086
    rclone config create external-storage azureblob \
      endpoint="blob.$AZURE_FQDN_SUFFIX" \
      account="${AZURE_ACCOUNTNAME}" use_msi "true" ${azure_msi_client_id_field} > /dev/null
  else
    AZURE_ACCOUNTKEY=$(echo "$STORAGE_SECRET_DATA" | jq  -r ".ACCOUNTKEY" | base64 -d)
    rclone config create external-storage azureblob \
      endpoint="blob.$AZURE_FQDN_SUFFIX" \
      account="${AZURE_ACCOUNTNAME}" key="${AZURE_ACCOUNTKEY}" > /dev/null
  fi
}

# uploads a folder to the Automation Suite configured storage
# parameters: source_local_folder, destination_bucket, destination_prefix
# if the folder exists, then it uploads each of the individual folders/files
# after running this command the contents of the destination folder will be the same as the contents of the source folder
function upload_to_storage() {
    local source_local_folder="$1"
    local destination_bucket="${2,,}"
    local destination_prefix="$3"

    if [[ -n "$destination_prefix" ]]; then
        destination_prefix="$destination_prefix/"
    fi
    local current_folder
    current_folder="$(pwd)"
    cd "$source_local_folder"
    local args
    args="--log-level INFO $RCLONE_ADDITIONAL_ARGS"
    [[ -n "$DRY_RUN" ]] && args="$args --dry-run"
    
    #shellcheck disable=SC2086
    rclone copy --s3-no-check-bucket . "external-storage:$destination_bucket/$destination_prefix" $args
    cd "$current_folder"
}

function override_encryption_key()
{
    local new_encryption_key=$1
    new_encryption_key=$(echo -n "$new_encryption_key" | base64)

    local encryption_key_secret_patch
    encryption_key_secret_patch="{}"
    encryption_key_secret_patch=$(echo "$encryption_key_secret_patch" | jq ".data[\"$ENCRYPTION_KEY_NAME\"]+=\"$new_encryption_key\"")
    encryption_key_secret_patch=$(echo "$encryption_key_secret_patch" | jq -c)

    if [[ -z "$DRY_RUN" ]]; then
        kubectl -n uipath patch secret "$ENCRYPTION_KEY_SECRET" --type merge -p "$encryption_key_secret_patch"
    else
        echo "Patching secret $ENCRYPTION_KEY_SECRET with $encryption_key_secret_patch"
    fi
}

function create_custom_configmap_ifnotexists()
{
    if [[ -z "$(kubectl -n uipath get configmap "$CONFIGMAP_NAME" -o jsonpath='{.metadata.name}' --ignore-not-found)" ]]; then
        kubectl -n uipath create configmap "$CONFIGMAP_NAME"
    fi
}

# appends custom config to the configmap in the appconfig file
# parameters: new appconfig file (containing the key value contents of the appconfig section of values.json)
function add_appconfig_overrides() # $1: appconfig file
{
    local newappconfig
    # load the new appconfig json
    newappconfig=$(jq -c < "$1")
    local customconfig
    # download the configmap
    customconfig="$(kubectl -n uipath get configmap "$CONFIGMAP_NAME" -o json)"
    local appsettings
    # extract the values.json from the configmap
    appsettings=$(echo "$customconfig" | jq '.data?["values.json"]' | jq -r)
    if [[ -z "$appsettings" ]]; then
        appsettings="{}"
    fi
    # jq append thenew appconfig under the .appConfig key in values.json and return the merged values.json 
    appsettings="$(jq ".$APPCONFIGKEY+=$newappconfig" <<< "$appsettings")"
    # json escape the new values.json, turning it in a string
    appsettings=$(echo "$appsettings" | jq -Rs)
    # add the new appsettings in the configmap patch unde "values.json" key
    CONFIGMAP_PATCH=$(echo "$CONFIGMAP_PATCH" | jq ".data[\"values.json\"]+=$appsettings" )
}

# replaces the nlog configuration with the specified config
# parameters: nlog config file
function add_nlogconfig_overrides()
{
    # load new nlog config
    NLOGCONFIG=$(jq < "$1")
    # extract the assembly files values
    NLOG_EXTENSIONS=$(echo "$NLOGCONFIG" | jq '.NLog.extensions[]?.assemblyFile' | sed -e 's/^"//' -e 's/"$//')
    if [[ -n "$NLOG_EXTENSIONS" ]]; then
        # prepend all assmblyFile from the extensions array with the well known orchestrator path for nlog extensions
        NLOG_EXTENSIONS_FULLY_QUALIFIED="[]"
        for NLOG_EXTENSION in ${NLOG_EXTENSIONS}; do
            if [[ -n "$NLOG_EXTENSION" && "$NLOG_EXTENSION" != "null" ]]; then
                echo "NLog assemblyFile: $NLOG_EXTENSION"
                if [[ ! $NLOG_EXTENSION =~ ^$DESTINATION_PLUGINS_FOLDER_NLOG* ]]; then
                    NLOG_EXTENSION="$DESTINATION_PLUGINS_FOLDER_NLOG/$NLOG_EXTENSION"
                fi
                # accumulate here the new assembly files values
                NLOG_EXTENSIONS_FULLY_QUALIFIED=$(jq ". += [{\"assemblyFile\":\"$NLOG_EXTENSION\"}]" <<< "$NLOG_EXTENSIONS_FULLY_QUALIFIED")
            fi
        done
        NLOG_EXTENSIONS=$(echo "$NLOGCONFIG" | jq '.NLog.extensions[]?.assembly' | sed -e 's/^"//' -e 's/"$//')
        for NLOG_EXTENSION in ${NLOG_EXTENSIONS}; do
            if [[ -n "$NLOG_EXTENSION" && "$NLOG_EXTENSION" != "null" ]]; then
            echo "NLog assembly: $NLOG_EXTENSION"
            NLOG_EXTENSIONS_FULLY_QUALIFIED=$(jq ". += [{\"assembly\":\"$NLOG_EXTENSION\"}]" <<< "$NLOG_EXTENSIONS_FULLY_QUALIFIED")
            fi
        done
        # compact json the nlog extensions so it can be used in the jq expression
        NLOG_EXTENSIONS_FULLY_QUALIFIED=$(echo "$NLOG_EXTENSIONS_FULLY_QUALIFIED" | jq -c)
        #  replace the extensions array with the new array with the fully qualified extensions
        NLOGCONFIG=$(echo "$NLOGCONFIG" | jq ".NLog.extensions=$NLOG_EXTENSIONS_FULLY_QUALIFIED")    
    fi
    # json escape the new config, turning it in a string
    NLOGCONFIG=$(echo "$NLOGCONFIG" | jq -Rs)
    # add the new config in the configmap patch unde "nlog.json" key
    CONFIGMAP_PATCH=$(echo "$CONFIGMAP_PATCH" | jq ".data[\"nlog.json\"]+=$NLOGCONFIG")
}

# patch the configmap
function apply_configmap_patch()
{
    CONFIGMAP_PATCH=$(jq -c <<< "$CONFIGMAP_PATCH")
    echo "$CONFIGMAP_PATCH" | jq

    kubectl -n uipath patch configmap orchestrator-customconfig --type merge -p "$CONFIGMAP_PATCH"

    # after patch get the configmap from kubernetes and print the updated values
    local customconfig
    customconfig="$(kubectl -n uipath get configmap orchestrator-customconfig -o json)"
    echo "$customconfig" | jq '.data' | jq '.["nlog.json"]' | jq -r
    echo "$customconfig" | jq '.data' | jq '.["values.json"]' | jq -r
}

function argo_login()
{
    #set +e
    #kubectl  port-forward svc/argocd-server -n argocd 8080:80 &
    #KUBECTL_PORT_FORWARD_PID="$!"
    #jobs
    #set -e

    ARGOCD_CLUSTER_IP=$(kubectl -n argocd get svc argocd-server -o jsonpath="{.spec.clusterIP}")

    ARGOPASS=$(kubectl  -n argocd get secret argocd-admin-password -o jsonpath="{.data.password}" | base64 -d)

    NEXT_WAIT_TIME=0
    until [ $NEXT_WAIT_TIME -eq 5 ] || argocd login $ARGOCD_CLUSTER_IP:443 --username admin --password "$ARGOPASS" --plaintext; do
        sleep $(( NEXT_WAIT_TIME++ ))
    done
    [ "$NEXT_WAIT_TIME" -lt 5 ]

    argocd app get orchestrator --show-params
}

# Main:
ORCHESTRATOR_EXTERNAL_STORAGE_SECRET_NAME="orchestrator-external-storage-secret"
CEPH_PLUGINS_SECRET_NAME="uipath-service-rook-ceph-secret"
CEPH_STORAGE_SECRET_NAME="ceph-object-store-secret"
PLUGINS_BUCKET_NAME="uipath"
NLOG_EXTENSIONS_PREFIX="orchestrator/plugins/nlog"
SECURESTORE_PLUGINS_PREFIX="orchestrator/plugins/securestore"
EXTERNAL_STORAGE_ORCHESTRATOR_PREFIX="orchestrator"
EXTERNAL_STORAGE_NLOG_EXTENSIONS_PREFIX="orchestrator-plugins/nlog"
EXTERNAL_STORAGE_SECURESTORE_PLUGINS_PREFIX="orchestrator-plugins/securestore"
CONFIGMAP_NAME="orchestrator-customconfig"
APPCONFIGKEY="AppSettings"
ENCRYPTION_KEY_SECRET="orchestrator-generated-secrets"
ENCRYPTION_KEY_NAME="APPSETTINGS__EncryptionKey"

ENCRYPTION_KEY=''

APPCONFIG_FILE=''
NLOG_EXTENSIONS_CONFIGFILE=''
DESTINATION_PLUGINS_FOLDER_NLOG="/var/orchestrator/plugins/nlog"

RCLONE_ADDITIONAL_ARGS=''
USE_EXTERNAL_STORAGE='No'
EXTERNAL_STORAGE_BUCKET=''
STORAGE_FOLDER=''
NLOG_EXTENSIONS_FOLDER=''
SECURESTORE_PLUGINS_FOLDER=''

QUIET=''
DRY_RUN=''
SKIP_RESTART=''

parse_input "$@"
user_confirm

if [[ -z "$DRY_RUN" ]]; then
    ORCH_POD=''
    get_orch_pod
    create_custom_configmap_ifnotexists
fi

# replace enc key generated at install time
if [[ -n "$ENCRYPTION_KEY" ]]; then
    override_encryption_key "$ENCRYPTION_KEY"
fi

# upload storage
if [[ -n "$STORAGE_FOLDER" ]]; then
    configure_storage "$CEPH_STORAGE_SECRET_NAME"
    echo "Uploading storage per tenant from $STORAGE_FOLDER"
    LS_SOURCE=$(ls "$STORAGE_FOLDER")
    for SOURCE in ${LS_SOURCE}; do
        if [[ -d "$STORAGE_FOLDER/$SOURCE" ]]; then
            if [[ -n "$EXTERNAL_STORAGE_BUCKET" ]]; then
                DEST_FOLDER_NAME=$SOURCE
                if [[ "$SOURCE" == "orchestrator-host" ]]; then
                    DEST_FOLDER_NAME="Orchestrator-Host"
                elif [[ "$SOURCE" == orchestrator-* ]]; then
                    DEST_FOLDER_NAME="O${SOURCE:1}"
                fi

                upload_to_storage "$STORAGE_FOLDER/$SOURCE" "$EXTERNAL_STORAGE_BUCKET" "$EXTERNAL_STORAGE_ORCHESTRATOR_PREFIX/$DEST_FOLDER_NAME"
            else
                upload_to_storage "$STORAGE_FOLDER/$SOURCE" "$SOURCE" ""
            fi
        else
            echo "$STORAGE_FOLDER/$SOURCE is not a directory, skipping"
        fi
    done
fi

if [[ -n "$NLOG_EXTENSIONS_FOLDER$SECURESTORE_PLUGINS_FOLDER" ]]; then
    configure_storage "$CEPH_PLUGINS_SECRET_NAME"

    # upload nlog extensions
    if [[ -n "$NLOG_EXTENSIONS_FOLDER" ]]; then
        if [[ -n "$EXTERNAL_STORAGE_BUCKET" ]]; then
            upload_to_storage "$NLOG_EXTENSIONS_FOLDER" "$EXTERNAL_STORAGE_BUCKET" "$EXTERNAL_STORAGE_NLOG_EXTENSIONS_PREFIX"
        else
            upload_to_storage "$NLOG_EXTENSIONS_FOLDER" "$PLUGINS_BUCKET_NAME" "$NLOG_EXTENSIONS_PREFIX"
        fi
    fi
    # upload securestore plugins
    if [[ -n "$SECURESTORE_PLUGINS_FOLDER" ]]; then
        if [[ -n "$EXTERNAL_STORAGE_BUCKET" ]]; then
            upload_to_storage "$SECURESTORE_PLUGINS_FOLDER" "$EXTERNAL_STORAGE_BUCKET" "$EXTERNAL_STORAGE_SECURESTORE_PLUGINS_PREFIX"
        else
            upload_to_storage "$SECURESTORE_PLUGINS_FOLDER" "$PLUGINS_BUCKET_NAME" "$SECURESTORE_PLUGINS_PREFIX"
        fi
    fi
fi

# accumulate configuration changes in $CONFIGMAP_PATCH
CONFIGMAP_PATCH="{}"
configmap_override=0
if [[ -n "$APPCONFIG_FILE" ]]; then 
    add_appconfig_overrides "$APPCONFIG_FILE"
    configmap_override=1
fi
if [[ -n "$NLOG_EXTENSIONS_CONFIGFILE" ]]; then
    add_nlogconfig_overrides "$NLOG_EXTENSIONS_CONFIGFILE"
    configmap_override=1
fi
if [[ $configmap_override -ne 0 ]]; then
    if [[ -n "$DRY_RUN" ]]; then
        echo "$CONFIGMAP_PATCH" | jq
    else
        apply_configmap_patch
    fi
fi

if [[ -z "$DRY_RUN" && -z "$SKIP_RESTART" ]]; then
    echo "Restart orchestrator deployment"
    set -x
    argo_login
    argocd app sync orchestrator --force
    argocd app actions run orchestrator restart --kind Deployment --all
    argocd app wait orchestrator
    #kill -9 $KUBECTL_PORT_FORWARD_PID
fi

  1. Save the file:
  • Save the file by pressing the following keys in sequence: "esc" ":" "wq" "!" "enter"
  1. Make the File Executable:
  • Set execute permissions for the script:
chmod +x ./updated-orchestrator-configurator.sh

  1. Run the Configurator Script:
    1. Execute the configurator script to update the appsettings file
    2. It should update the customize settings in Orchestrator.