Registry Mirror
Skip to content

Conversation

@iplay88keys

Copy link
Copy Markdown
Contributor

Description

Refactor installation and uninstallation into a shared library to reduce duplication and make the workflow easier to extend. The existing implementation mixes setup and orchestration with CLI flags, environment reads, and terminal output, forcing other callers to duplicate that logic or depend on command internals.

Move the shared behavior into core/pkg/install in the existing Go module. The CLI becomes a thin consumer that resolves configuration and credentials, reports progress, and checks API reachability. Embedding applications can reuse the same workflow and setup operations.

Extension points are explicit inputs: chart artifacts, repositories, versions, values, worker images, and additional database setup SQL. An ordered plan keeps those choices separate from execution, while injected command and Kubernetes clients make the library testable without fake Helm and kubectl binaries on PATH.

The refactor preserves install ordering, signing-key reuse, controller service-account grants, and external-database cleanup protections. The upgrade-test manifest sentinel follows the moved asset. Plans retain values file paths and credential payloads.

Validation

  • go test -short -race ./core/pkg/install ./core/cli/... from go/
  • go vet ./core/pkg/install ./core/cli/... from go/
  • go build -o /tmp/kagent-install-library ./core/cli/cmd/kagent from go/
  • make -C go lint — zero issues
  • Built CLI install --help smoke check
  • Built controller and UI images and ran make kagent-cli-deploy AWK=/usr/bin/awk TOOLS_GO_VERSION=1.27.3 against the local Kind cluster
  • Repeated installation successfully: all five Helm releases deployed at revision 2, with all six signing pools unchanged
  • Read Session API through a dedicated port-forward to the installed controller
  • git diff --check

Tests cover custom controller service accounts, alternate charts and additional schemas, skipped database setup, failed install/uninstall steps, cancellation, plan-copy isolation, PostgreSQL assets, and repeated prerequisite setup without key rotation.

Verified with a successful local install.

Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
@iplay88keys
iplay88keys force-pushed the iplay88keys/refactor-kagent-install branch from 7961bb9 to a6c8cdf Compare October 28, 2026 20:59
@iplay88keys
iplay88keys marked this pull request as ready for review October 28, 2026 21:17
@iplay88keys
iplay88keys requested a review from a team as a code owner October 28, 2026 21:17
@iplay88keys
iplay88keys added this pull request to stack #3433 October 28, 2026 22:29

@codyhartsook codyhartsook left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI-generated review. I reviewed the findings before posting.

Two problems in the inputs the new library takes from embedders. I reproduced both with probe tests at a6c8cdf.

Comment thread go/core/pkg/install/plan.go Resolved
Comment thread go/core/pkg/install/postgres.go Resolved
Comment thread Makefile
KIND_SUBSTRATE_HELM_ARGS = --set atelet.extraArgs[0]=--localhost-registry-replacement=kind-registry:5000 --set ateApi.extraArgs[0]=--template-resync-interval=250ms
# A file only releases whose `kagent install` deploys the database contain.
CLI_DATABASE_SENTINEL = go/core/cli/internal/commands/bundled_postgres.yaml
CLI_DATABASE_SENTINEL = go/core/pkg/install/bundled_postgres.yaml

@iplay88keys iplay88keys Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we aren't supporting upgrades from 0.10.x releases. The upgrade matrix here:

  • adjacent: skips because the PR targets main and the adjacent tests only run on release branches.
  • prev-stable: selects v0.10.4, which lacks either of those paths, so changing it is fine here.

Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
@codyhartsook
codyhartsook self-requested a review October 29, 2026 15:28
@iplay88keys
iplay88keys added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 9ad75ae Oct 29, 2026
30 checks passed
@iplay88keys
iplay88keys deleted the iplay88keys/refactor-kagent-install branch October 29, 2026 16:01
adalundhe pushed a commit to adalundhe/kagent that referenced this pull request Oct 29, 2026
## Description

Add `kagent install --dry-run` to export a reviewable Helm installation
recipe without changing the cluster. This builds on the reusable
installation library in kagent-dev#3427 and exposes the exporter through
`install.Export` for other callers.

```sh
kagent --config config.yaml install --dry-run --output-dir ./kagent-install
```

The terminal reports the destination. The directory contains:

```text
kagent-install/
├── README.md
├── install.sh
└── values/
    ├── kagent-crds.yaml
    ├── substrate-crds.yaml
    ├── substrate-podcert.yaml
    ├── substrate.yaml
    └── kagent.yaml
```

`install.sh` contains ordered `helm upgrade --install` commands with the
configured chart references, versions and namespaces. Each values file
contains the merged installer overrides, including configured values
files and generated settings. Chart defaults are not included. The
README points to the Helm installation documentation and records the
database mode and required credential variables.

The CLI owns and embeds its README template. Library callers must
provide template text through `ExportOptions.ReadmeTemplate`; rendering
receives database mode and credential reference metadata. Optional
`ExportOptions.ReadmeData` accepts caller-provided structs or maps,
available to the template under `.Data`.

The destination defaults to `./kagent-install` and must not already
exist. Export requires Helm and chart access, but no kubectl, kubeconfig
or model API-key value. It captures values-file contents so the result
no longer depends on those input files. Local chart directories remain
dependencies and become absolute references.

CLI-managed API keys become environment references. The generated script
binds them at execution time through `--set-file` and private temporary
files. Other values are included as supplied; arbitrary secrets are not
detected or sanitized. Library callers can declare additional credential
references explicitly.

The directory contains no database manifests, SQL or prerequisite setup
scripts. Operators complete database and Substrate setup separately
before applying it. `--skip-database-setup` retains the normal install's
external-database configuration. The export does not calculate a diff
against the cluster.

## Example output

Examples from a local development export. Local chart paths are shown as
`/path/to/kagent`.

<details>
<summary><code>README.md</code></summary>

````markdown
# kagent Helm installation export

This directory contains the Helm commands and values that `kagent install` would apply. Each values file contains only the values that the CLI sets for that release. Chart defaults are not included.

Review every values file before you commit or share this directory. User-provided values are copied as supplied, and secrets in them are not detected or removed. Only the credentials in the Environment references section are replaced.

## Before you run the script

Complete the prerequisite steps in the Helm installation guide: https://kagent.dev/docs/kagent/1.x/setup/installation/#before-you-begin. This export does not set up prerequisites.

The values configure certificate authentication for the bundled database. This export does not provision the database.

## Environment references

Set these environment variables before you run `install.sh`:

- `OPENAI_API_KEY`: `providers.openAI.apiKey` in the `kagent` release

The script passes each value to Helm with `--set-file` through a temporary private file. Always apply the export with the script. Helm does not expand environment variables in YAML, so passing a values file to Helm directly installs the placeholder text as the value.

## Run the script

```sh
sh ./install.sh
```

The script installs the releases in order in the current kubeconfig context. Running it again upgrades the same releases. The export did not check the cluster or compute a diff.

````

</details>

<details>
<summary><code>install.sh</code></summary>

```sh
#!/bin/sh
set -eu

# Complete the prerequisites in README.md before running these commands.
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
: "${OPENAI_API_KEY:?Set OPENAI_API_KEY before running this script}"
umask 077
secret_dir=$(mktemp -d)
trap 'rm -rf "$secret_dir"' EXIT
trap 'exit 1' HUP INT TERM
printf '%s' "${OPENAI_API_KEY}" > "$secret_dir/OPENAI_API_KEY"

helm upgrade --install kagent-crds /path/to/kagent/helm/kagent-crds --version v1.0.0-alpha17-33-gba2448179 --namespace dry-run-validation --create-namespace --wait --wait-for-jobs --history-max 2 --timeout 5m -f "$script_dir/values/kagent-crds.yaml"

helm upgrade --install substrate-crds oci://ghcr.io/kagent-dev/substrate/helm/substrate-crds --version 0.7.0-alpha1 --namespace ate-system --create-namespace --wait --wait-for-jobs --history-max 2 --timeout 5m -f "$script_dir/values/substrate-crds.yaml"

helm upgrade --install substrate-podcert oci://ghcr.io/kagent-dev/substrate/helm/substrate-podcert --version 0.7.0-alpha1 --namespace podcertificate-controller-system --create-namespace --wait --wait-for-jobs --history-max 2 --timeout 5m -f "$script_dir/values/substrate-podcert.yaml"

helm upgrade --install substrate oci://ghcr.io/kagent-dev/substrate/helm/substrate --version 0.7.0-alpha1 --namespace ate-system --create-namespace --wait --wait-for-jobs --history-max 2 --timeout 5m -f "$script_dir/values/substrate.yaml"

helm upgrade --install kagent /path/to/kagent/helm/kagent --version v1.0.0-alpha17-33-gba2448179 --namespace dry-run-validation --create-namespace --wait --wait-for-jobs --history-max 2 --timeout 5m -f "$script_dir/values/kagent.yaml" --set-file providers.openAI.apiKey="$secret_dir/OPENAI_API_KEY"
```

</details>

<details>
<summary><code>values/kagent.yaml</code></summary>

```yaml
config:
  substrate:
    apiEndpoint: dns:///api.ate-system.svc:443
    routerUrl: http://atenet-router.ate-system.svc:80
controller:
  image:
    pullPolicy: Always
  substrateClientCertificate:
    enabled: true
database:
  postgres:
    clientCertificate:
      enabled: true
imagePullPolicy: Always
providers:
  default: openAI
  openAI:
    apiKey: ${OPENAI_API_KEY}
registry: localhost:5001
substrateWorkerPool:
  create: true
  workerImage: ghcr.io/kagent-dev/substrate/ateworker-gvisor:v0.7.0-alpha1
tag: v1.0.0-alpha17-33-gba2448179
ui:
  image:
    pullPolicy: Always
```

</details>

## Validation

- CLI and library race tests, vet, and Go lint passed.
- Helm tests compare exported overrides with normal install inputs,
including precedence, set parsing, local chart paths and both database
modes.
- Script tests cover runtime credential binding, quoting, missing
credentials and cleanup after success or failure.
- Local export worked without cluster access; checks confirmed the
expected files, valid shell syntax and no test API-key value.
- The generated script worked on a fresh local install and a repeat
install after prerequisite setup.
- All five releases deployed with values matching the export. Signing
pools were preserved, and CLI API access passed.

---------

Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants