> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/self-managed-enterprise-edition/use-self-managed-enterprise-edition/smp-installationupgrade/operator-installation/install/discovery.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Discover an existing Harness SMP installation

Extract configuration from an existing Harness SMP installation so the SMP Operator can discover it.

If you have an existing Harness SMP installation and want it to be discovered by the Harness SMP Operator, use the script `generate-harness-values.sh` to extract your current configuration.

This topic covers what the script does, how to run it, the two files it generates, how to install with those files using either helm or clustermgr, and how to verify the result in the Installer UI.

***

## What the script does <a href="#what-the-script-does" id="what-the-script-does"></a>

The `generate-harness-values.sh` script connects to your running cluster, reads the existing Harness Helm release values and Kubernetes secrets, and generates the files needed for Operator to discover your existing installation.

***

## Usage <a href="#usage" id="usage"></a>

Save the following script to a file named `generate-harness-values.sh`:

<details>

<summary>View generate-harness-values.sh</summary>

```bash
#!/bin/bash
#
# generate-harness-values.sh
#
# Extracts values from running Harness helm release and generates
# --pi-set commands for clustermgr install-pi
#
# Usage:
#   ./generate-harness-values.sh [-n namespace] [-r release]
#
# Output Files:
#   - tfi-values.yaml: cluster.tfi.* (modules, license, db passwords)
#   - harness-values.yaml: helm values (global, harness sections)
#   - pi-commands.txt: install commands referencing above files
#

set -e

# Defaults
NAMESPACE="harness"
RELEASE="harness"
OUTPUT_FILE=""

usage() {
    cat << EOF
Usage: $(basename "$0") [OPTIONS]

Extract values from Harness helm release and generate --pi-set commands.

OPTIONS:
  -n, --namespace   Kubernetes namespace (default: harness)
  -r, --release     Helm release name (default: harness)
  -o, --output      Output file (default: stdout)
  -h, --help        Show this help

EXAMPLES:
  # Generate commands to stdout
  $(basename "$0")

  # Generate commands to file
  $(basename "$0") -o pi-set-commands.txt

  # Use with different namespace
  $(basename "$0") -n my-namespace -r my-release

OUTPUT FILES:
  tfi-values.yaml:
    cluster:
      tfi:
        ci: true
        cd: false
        harnessLicense: "..."
        postgresqlPassword: "..."
        mongodbPassword: "..."

  harness-values.yaml:
    global: ...
    harness: ...

  pi-commands.txt:
    --pi-values tfi-values.yaml
    --pi-set-file cluster.helmValues.harness=harness-values.yaml
EOF
    exit 0
}

log_info() {
    echo "[INFO] $*" >&2
}

log_error() {
    echo "[ERROR] $*" >&2
}

# Parse arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        -n|--namespace)
            NAMESPACE="$2"
            shift 2
            ;;
        -r|--release)
            RELEASE="$2"
            shift 2
            ;;
        -o|--output)
            OUTPUT_FILE="$2"
            shift 2
            ;;
        -h|--help)
            usage
            ;;
        *)
            log_error "Unknown option: $1"
            exit 1
            ;;
    esac
done

# Tool paths - tools are in ../tools relative to this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TOOLS_DIR="${SCRIPT_DIR}/../tools"

# Find helm
if [ -x "${TOOLS_DIR}/helm" ]; then
    HELM="${TOOLS_DIR}/helm"
elif command -v helm &>/dev/null; then
    HELM="helm"
else
    log_error "helm not found in ${TOOLS_DIR} or PATH"
    exit 1
fi

# Find kubectl or oc
if [ -x "${TOOLS_DIR}/kubectl" ] && "${TOOLS_DIR}/kubectl" version --client &>/dev/null 2>&1; then
    KUBECTL="${TOOLS_DIR}/kubectl"
elif kubectl version --client &>/dev/null 2>&1; then
    KUBECTL="kubectl"
elif oc version --client &>/dev/null 2>&1; then
    KUBECTL="oc"
else
    log_error "kubectl/oc not found in ${TOOLS_DIR} or PATH"
    exit 1
fi

# Find yq
if [ -x "${TOOLS_DIR}/yq" ]; then
    YQ="${TOOLS_DIR}/yq"
elif command -v yq &>/dev/null; then
    YQ="yq"
else
    log_error "yq not found in ${TOOLS_DIR} or PATH"
    exit 1
fi

# Get helm values
log_info "Getting helm values from release '$RELEASE' in namespace '$NAMESPACE'..."
HELM_VALUES=$(mktemp)
trap "rm -f $HELM_VALUES" EXIT

if ! $HELM get values "$RELEASE" -n "$NAMESPACE" > "$HELM_VALUES" 2>/dev/null; then
    log_error "Failed to get helm values. Is the release installed?"
    exit 1
fi

# Get database passwords early (before any file processing)
POSTGRES_PASSWORD=$($KUBECTL -n "$NAMESPACE" get secret postgres -o jsonpath='{.data.postgres-password}' 2>/dev/null | base64 -d 2>/dev/null || true)
MONGO_PASSWORD=$($KUBECTL -n "$NAMESPACE" get secret mongodb-replicaset-chart -o jsonpath='{.data.mongodb-root-password}' 2>/dev/null | base64 -d 2>/dev/null || true)
MINIO_PASSWORD=$($KUBECTL -n "$NAMESPACE" get secret minio -o jsonpath='{.data.root-password}' 2>/dev/null | base64 -d 2>/dev/null || true)

log_info "Extracting values..."

# Function to output (to file or stdout)
output() {
    if [ -n "$OUTPUT_FILE" ]; then
        echo "$@" >> "$OUTPUT_FILE"
    else
        echo "$@"
    fi
}

# Clear output file if specified
if [ -n "$OUTPUT_FILE" ]; then
    > "$OUTPUT_FILE"
fi

# Determine output directory
if [ -n "$OUTPUT_FILE" ]; then
    OUTPUT_DIR=$(dirname "$OUTPUT_FILE")
else
    OUTPUT_DIR="."
fi

# === Part 1: Generate tfi-values.yaml (cluster.tfi.*) ===
TFI_VALUES_FILE="${OUTPUT_DIR}/tfi-values.yaml"

log_info "Generating tfi-values.yaml..."

cat > "$TFI_VALUES_FILE" << 'YAML_HEADER'
# Traceable Installer TFI Values
# Use with: -f tfi-values.yaml
#
# Contains: module flags, license, database passwords, additionalFeatureFlags
YAML_HEADER

echo "" >> "$TFI_VALUES_FILE"
echo "cluster:" >> "$TFI_VALUES_FILE"
echo "  tfi:" >> "$TFI_VALUES_FILE"

# Module flags
MODULES="ci cd ccm sto srm ff chaos scs dbops code iacm idp"
for mod in $MODULES; do
    val=$($YQ eval ".global.${mod}.enabled // false" "$HELM_VALUES")
    if [ "$val" = "true" ]; then
        echo "    ${mod}: true" >> "$TFI_VALUES_FILE"
    else
        echo "    ${mod}: false" >> "$TFI_VALUES_FILE"
    fi
done

# License
LICENSE=$($YQ eval '.global.license.ng // ""' "$HELM_VALUES")
if [ -n "$LICENSE" ] && [ "$LICENSE" != "null" ]; then
    echo "    harnessLicense: \"$LICENSE\"" >> "$TFI_VALUES_FILE"
fi

# Database passwords
if [ -n "$POSTGRES_PASSWORD" ]; then
    echo "    postgresqlPassword: \"$POSTGRES_PASSWORD\"" >> "$TFI_VALUES_FILE"
else
    log_info "PostgreSQL password not found in secrets"
fi

if [ -n "$MONGO_PASSWORD" ]; then
    echo "    mongodbPassword: \"$MONGO_PASSWORD\"" >> "$TFI_VALUES_FILE"
else
    log_info "MongoDB password not found in secrets"
fi

if [ -n "$MINIO_PASSWORD" ]; then
    echo "    minioPassword: \"$MINIO_PASSWORD\"" >> "$TFI_VALUES_FILE"
else
    log_info "MinIO password not found in secrets"
fi

# Feature flags (platform.harness-manager.featureFlags.ADDITIONAL)
ADDITIONAL_FLAGS=$($YQ eval '.platform."harness-manager".featureFlags.ADDITIONAL // ""' "$HELM_VALUES")
if [ -n "$ADDITIONAL_FLAGS" ] && [ "$ADDITIONAL_FLAGS" != "null" ]; then
    FLAGS_NL=$(printf '%s' "$ADDITIONAL_FLAGS" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | grep -v '^$' | sort -u)
    {
        echo "    additionalFeatureFlags: |"
        echo "$FLAGS_NL" | sed 's/^/      /'
    } >> "$TFI_VALUES_FILE"
fi

# === Part 2: Generate harness-values.yaml (helm values) ===
HARNESS_VALUES_FILE="${OUTPUT_DIR}/harness-values.yaml"

log_info "Generating harness-values.yaml..."

# Strip "USER-SUPPLIED VALUES:" header from helm output
sed -i.bak '/^USER-SUPPLIED VALUES:$/d' "$HELM_VALUES"
rm -f "${HELM_VALUES}.bak"

# Create harness-values.yaml - keep FULL helm values as-is
# PI expects: global: → cluster.helm.global.*, rest → cluster.helm.harness.*
cat > "$HARNESS_VALUES_FILE" << 'YAML_HEADER'
# Harness Helm Values for Traceable Installer
# Use with: --pi-set-file cluster.helmValues.harness=harness-values.yaml
#
# Note: Module flags (cd, ci, etc.) are in --pi-set cluster.tfi.* commands
YAML_HEADER

# Add global section WITHOUT module flags (they're in --pi-set cluster.tfi.*)
# Remove: ci, cd, ccm, sto, srm, ff, chaos, scs, dbops, code, iacm, idp, license
echo "" >> "$HARNESS_VALUES_FILE"
echo "global:" >> "$HARNESS_VALUES_FILE"
$YQ eval '.global | del(.ci) | del(.cd) | del(.ccm) | del(.sto) | del(.srm) | del(.ff) | del(.chaos) | del(.scs) | del(.dbops) | del(.code) | del(.iacm) | del(.idp) | del(.license)' "$HELM_VALUES" | sed 's/^/  /' >> "$HARNESS_VALUES_FILE"

# Add harness section (everything except global: platform, srm, etc.)
NON_GLOBAL=$($YQ eval 'del(.global)' "$HELM_VALUES")
if [ -n "$NON_GLOBAL" ] && [ "$NON_GLOBAL" != "null" ] && [ "$NON_GLOBAL" != "{}" ]; then
    echo "" >> "$HARNESS_VALUES_FILE"
    echo "harness:" >> "$HARNESS_VALUES_FILE"
    echo "$NON_GLOBAL" | sed 's/^/  /' >> "$HARNESS_VALUES_FILE"
fi

# === Part 3: Generate pi-commands.txt ===
output "# Generated PI install parameters to use in clustermgr command"
output "# Release: $RELEASE, Namespace: $NAMESPACE"
output "# Generated: $(date)"
output ""
output "# TFI values (modules, license, db passwords)"
output "--pi-values $TFI_VALUES_FILE"
output ""
output "# Helm values in user/values.yaml of harness chart"
output "--pi-set-file cluster.helmValues.harness=$HARNESS_VALUES_FILE"
output ""

log_info "Done!"
log_info "Generated files:"
log_info "  - $TFI_VALUES_FILE (modules, license, db passwords)"
log_info "  - $HARNESS_VALUES_FILE (helm values)"
if [ -n "$OUTPUT_FILE" ]; then
    log_info "  - $OUTPUT_FILE (install commands)"
fi
```

</details>

Then run the following commands in your terminal.

```bash
# outputs two files: tfi-values.yaml and harness-values.yaml

# option 1: after saving the script from this page
chmod +x generate-harness-values.sh
./generate-harness-values.sh

# option 2: if running from extracted clustermgr package
./values-migrator/generate-harness-values.sh
```

| Flag              | Default   | Description                                      |
| ----------------- | --------- | ------------------------------------------------ |
| `-n, --namespace` | `harness` | Kubernetes namespace of existing Harness install |
| `-r, --release`   | `harness` | Helm release name                                |

***

## Generated files <a href="#generated-files" id="generated-files"></a>

The script generates two files:

1. **`tfi-values.yaml`** - Contains `cluster.tfi.*` values extracted from the existing install:

   ```yaml
   cluster:
     tfi:
       ci: false
       cd: true
       ccm: false
       sto: false
       srm: false
       ff: false
       chaos: false
       scs: false
       dbops: false
       code: false
       iacm: false
       idp: false
       harnessLicense: "..."
       postgresqlPassword: "..."
       mongodbPassword: "..."
       minioPassword: "..."
       additionalFeatureFlags: |
         FEATURE_FLAG_1
         FEATURE_FLAG_2
   ```
2. **`harness-values.yaml`** - Contains Helm values (`global:` and `harness:` sections, excluding module flags and license which are in `tfi-values.yaml`).

***

## Install with discovered values <a href="#install-with-discovered-values" id="install-with-discovered-values"></a>

After the script generates the two files, pass them to your install command. In this step, the install command supplies your existing configuration to the operator.

{% tabs %}
{% tab title="helm" %}

```bash
helm install platform-installer ./platform-installer-<VERSION>.tgz -n harness --create-namespace \
  -f tfi-values.yaml \
  --set-file cluster.helmValues.harness=harness-values.yaml \
  -f override.yaml \
  -f override-<ingress>.yaml
```

* Use the generated `tfi-values.yaml` and `harness-values.yaml` with `helm install`.
* Reference the appropriate override and ingress files from the [Configure and Install](https://developer.harness.io/self-managed-enterprise-edition/use-self-managed-enterprise-edition/smp-installationupgrade/operator-installation/install/install-with-smp-operator.md#step-2-configure-and-install) section.
* If your release name differs from the default `harness`, append `-f override-harness-release-name.yaml`. Go to [Custom Helm release name](#custom-helm-release-name) for details.
  {% endtab %}

{% tab title="clustermgr" %}
After running the script, use the generated files with `clustermgr install-pi`:

```bash
./clustermgr install-pi \
  --dns <your-dns> \
  --namespace harness \
  --email <admin-email> \
  --password '<password>' \
  --version <version> \
  --multi-node \
  --pi-set cluster.triggerInstall=false \
  --pi-set cluster.tfi.storageClass=<storage-class> \
  --pi-set cluster.profile=<profile-type> \
  --pi-values tfi-values.yaml \
  --pi-set-file cluster.helmValues.harness=harness-values.yaml
```

For air-gapped environments, add the registry flags:

```bash
./clustermgr install-pi \
  --dns <your-dns> \
  --namespace harness \
  --registry-host registry.example.com \
  --registry-prefix your-prefix \
  --registry-user <user> \
  --registry-password '<password>' \
  --email <admin-email> \
  --password '<password>' \
  --version <version> \
  --multi-node \
  --pi-set cluster.triggerInstall=false \
  --pi-set cluster.tfi.storageClass=<storage-class> \
  --pi-set cluster.profile=<profile-type> \
  --pi-values tfi-values.yaml \
  --pi-set-file cluster.helmValues.harness=harness-values.yaml
```

{% endtab %}
{% endtabs %}

***

## Custom Helm release name <a href="#custom-helm-release-name" id="custom-helm-release-name"></a>

When your existing installation uses a Helm release name other than `harness` (for example, `harness-prod`), create an override file to tell the operator which release name to use:

**`override-harness-release-name.yaml`:**

```yaml
cluster:
  workflows:
    - name: install
      items:
        - name: harness
          helm:
            name: harness-prod
            valuesDir: harness
```

| Field            | Description                                                                            |
| ---------------- | -------------------------------------------------------------------------------------- |
| `helm.name`      | Sets the Helm release name used for all operator helm commands                         |
| `helm.valuesDir` | Keeps the values directory at the default `harness` path for correct sizing resolution |

Append this file to your install command:

* **helm**: `-f override-harness-release-name.yaml`
* **clustermgr**: `--pi-values override-harness-release-name.yaml`

***

## Post-Discovery verification <a href="#post-discovery-verification" id="post-discovery-verification"></a>

To verify the discovered values installed correctly, do the following:

1. Access the Installer UI at `https://<YOUR_DNS>/pi`
2. Navigate to **Global Variables** and verify that modules, license, and database passwords are populated correctly
3. Navigate to **Helm Releases → harness → user/values.yaml** and verify the values from `harness-values.yaml` are populated

***

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Confirm you have an existing Harness SMP installation and `kubectl` access to its cluster before you run the discovery script.

***

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

If `generate-harness-values.sh` fails to connect to the cluster, confirm your `kubectl` context points at the cluster running the existing Harness installation and that the namespace and release name flags match your deployment.

{% @harness-feedback/feedback %}
