Skip to content

Commit 89fe26f

Browse files
committed
fix: Reset DevSpace state on purge
Signed-off-by: Kyle Felter <kfelter@nvidia.com>
1 parent 5ca05f6 commit 89fe26f

3 files changed

Lines changed: 88 additions & 4 deletions

File tree

dev/deployment/devspace/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can use [DevSpace](https://www.devspace.sh) to deploy the complete local inf
44

55
The process is broken into two steps:
66

7-
1. Bootstrap Kubernetes prerequisites. (This only needs to be done once.)
7+
1. Bootstrap Kubernetes prerequisites. (This only needs to be done once per cluster.)
88
2. Run `devspace deploy` to deploy code from this repo
99

1010
The intent is that the app deploy path stays the same whether the prerequisites are:
@@ -120,6 +120,7 @@ Common usage:
120120
```bash
121121
devspace deploy
122122
devspace deploy -n nico-system
123+
devspace deploy --skip-build -n nico-system
123124
devspace deploy --force-build
124125
```
125126

@@ -164,17 +165,25 @@ docker build -t "machine-a-tron:<devspace-generated-tag>" -f dev/deployment/devs
164165

165166
DevSpace then deploys the Helm chart with the built `nico-api` image wired into `global.image.repository` and `global.image.tag`, the built `nico-bmc-proxy` image wired into the `nico-bmc-proxy` chart values, and applies the local-only `machine-a-tron` manifest with its image wired into the `Deployment` spec. The REST images are built from the existing `rest-api/docker/local` Dockerfiles and are passed to the three existing REST Helm charts with the same generated tag.
166167

167-
## Re-initializing Core state
168+
## Resetting the local environment
168169

169170
Once deployed, the `nico-api` container will run and initialize its database, and the `machine-a-tron` container will run a set of mock machines, which will be discovered and ingested into the database, and run through the state machine until they reach a Ready state.
170171

171-
You can purge the deployed product resources by running:
172+
Reset the complete local environment by running:
172173

173174
```bash
174175
devspace purge -n nico-system
175176
```
176177

177-
and it will delete the Core and REST Helm releases and the machine-a-tron deployment. Bootstrap-owned services such as PostgreSQL, Vault, Temporal, Keycloak, and cert-manager remain installed.
178+
The purge pipeline only runs when the current context is `kind-<cluster>`. It deletes and recreates that kind cluster with the same node image, then bootstraps clean prerequisites. This removes all Kubernetes state, including the Core and REST databases, Temporal namespaces and history, Vault data, Keycloak data, certificates, site registration, Helm releases, CRDs, and persistent volumes.
179+
180+
The host Docker images, BuildKit cache, and `.devspace` image metadata are outside the kind node and remain available. Redeploy the last built images without rebuilding them:
181+
182+
```bash
183+
devspace deploy --skip-build -n nico-system
184+
```
185+
186+
The pre-deploy hooks load the cached Core and REST images from the host Docker store into the new kind node. Omit `--skip-build` when the source or image definitions have changed since the last build.
178187

179188
To clear only the Core `nico` database, run the nuke-postgres.sh helper script:
180189

@@ -191,6 +200,7 @@ devspace deploy -n nico-system
191200
## Files
192201

193202
- [`bootstrap-prereqs.sh`](bootstrap-prereqs.sh)
203+
- [`reset-kind-cluster.sh`](reset-kind-cluster.sh)
194204
- [`setup-rest-integration.sh`](setup-rest-integration.sh)
195205
- [`devspace.yaml`](../../../devspace.yaml)
196206
- [`values.base.yaml`](values.base.yaml)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
20+
21+
log() {
22+
printf '[local-dev] %s\n' "$*"
23+
}
24+
25+
require_bin() {
26+
command -v "$1" >/dev/null 2>&1 || {
27+
printf 'missing required binary: %s\n' "$1" >&2
28+
exit 1
29+
}
30+
}
31+
32+
main() {
33+
require_bin docker
34+
require_bin helm
35+
require_bin kind
36+
require_bin kubectl
37+
require_bin base64
38+
39+
local current_context cluster_name control_plane node_image
40+
current_context="$(kubectl config current-context 2>/dev/null || true)"
41+
case "${current_context}" in
42+
kind-*) cluster_name="${current_context#kind-}" ;;
43+
*)
44+
printf 'purge requires a kind context; current context is %s\n' \
45+
"${current_context:-unset}" >&2
46+
exit 1
47+
;;
48+
esac
49+
50+
control_plane="${cluster_name}-control-plane"
51+
node_image="$(docker inspect --format '{{.Config.Image}}' "${control_plane}" 2>/dev/null || true)"
52+
if [[ -z "${node_image}" ]]; then
53+
printf 'could not determine the node image from container %s\n' \
54+
"${control_plane}" >&2
55+
exit 1
56+
fi
57+
58+
log "Deleting kind cluster ${cluster_name}"
59+
kind delete cluster --name "${cluster_name}"
60+
61+
log "Recreating kind cluster ${cluster_name} with ${node_image}"
62+
kind create cluster --name "${cluster_name}" --image "${node_image}"
63+
64+
log "Installing clean local prerequisites"
65+
"${SCRIPT_DIR}/bootstrap-prereqs.sh"
66+
67+
log "Reset complete; deploy with devspace deploy --skip-build"
68+
}
69+
70+
main "$@"

devspace.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ vars:
3030
source: env
3131
default: "18082"
3232

33+
pipelines:
34+
purge: |-
35+
LOCAL_DEV_NAMESPACE=${DEVSPACE_NAMESPACE} dev/deployment/devspace/reset-kind-cluster.sh
36+
3337
images:
3438
nico-api:
3539
image: nico-api

0 commit comments

Comments
 (0)