Skip to content

Commit e99dffb

Browse files
authored
ate-setup: wait for the demo namespace in delete demo (agent-substrate#3553)
`delete demo` returned while the demo namespace was still terminating, so a `deploy demo` right after it failed: the API server refuses new objects in a terminating namespace. Delete now waits for the namespace to be gone, as `delete ate-system` does. Why is this needed? (Or link the issue. Open one first for features, API, install or CI changes.) Demo Fix. Fixes agent-substrate#3525 AI use: I wrote, claude polished. - [ ] Tests pass - [x] Docs updated Signed-off-by: Haven Xia <[email protected]>
1 parent 38e9ef6 commit e99dffb

5 files changed

Lines changed: 50 additions & 12 deletions

File tree

‎cmd/ate-setup/internal/cmd/demo.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ func init() {
7373
Short: "Delete " + demo.Name(),
7474
Args: cobra.NoArgs,
7575
RunE: func(cmd *cobra.Command, _ []string) error {
76-
return demo.Delete(cmd.Context(), env)
76+
namespaces, err := demo.Delete(cmd.Context(), env)
77+
if err != nil {
78+
return err
79+
}
80+
return env.WaitNamespacesDeleted(cmd.Context(), namespaces)
7781
},
7882
})
7983
}

‎cmd/ate-setup/internal/demos/claudemultiplex/claudemultiplex.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (d *demo) Deploy(ctx context.Context, e *steps.Env) error {
9393

9494
// Delete needs no credentials: only the pool manifest is rendered, and it
9595
// carries none of the deploy-time placeholders.
96-
func (d *demo) Delete(ctx context.Context, e *steps.Env) error {
96+
func (d *demo) Delete(ctx context.Context, e *steps.Env) ([]string, error) {
9797
return d.sub.Delete(ctx, e)
9898
}
9999

‎cmd/ate-setup/internal/demos/demos.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ type Demo interface {
4949
Settings() []config.Setting
5050
// Deploy installs the demo.
5151
Deploy(ctx context.Context, e *steps.Env) error
52-
// Delete removes the demo. It must succeed on a cluster where the demo was
53-
// never installed, because DeleteAll runs every demo's Delete.
54-
Delete(ctx context.Context, e *steps.Env) error
52+
// Delete removes the demo and returns the namespaces it left terminating,
53+
// for the caller to wait on. It must succeed on a cluster where the demo
54+
// was never installed, because DeleteAll runs every demo's Delete.
55+
Delete(ctx context.Context, e *steps.Env) ([]string, error)
5556
}
5657

5758
// registry holds every demo, keyed by name.

‎cmd/ate-setup/internal/demos/substrate.go‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,31 @@ func (d *Substrate) Deploy(ctx context.Context, e *steps.Env) error {
186186
return nil
187187
}
188188

189-
func (d *Substrate) Delete(ctx context.Context, e *steps.Env) error {
189+
func (d *Substrate) Delete(ctx context.Context, e *steps.Env) ([]string, error) {
190190
log.Step(d.DemoName + "_delete")
191191
refs := make([]resources.ActorTemplateRef, 0, len(d.Templates))
192192
for _, t := range d.Templates {
193193
refs = append(refs, t.Ref)
194194
}
195195
if err := e.DeleteSubstrateDemo(ctx, refs, d.atespaces()); err != nil {
196-
return err
196+
return nil, err
197197
}
198198
manifest, err := Render(e, d.WorkerPoolManifest, nil, ExternalVolumePlaceholders)
199199
if err != nil {
200-
return err
200+
return nil, err
201+
}
202+
objs, err := kube.DecodeManifestBytes(manifest)
203+
if err != nil {
204+
return nil, err
205+
}
206+
if err := e.Kube.Delete(ctx, objs); err != nil {
207+
return nil, err
208+
}
209+
var namespaces []string
210+
for _, obj := range objs {
211+
if gvk := obj.GroupVersionKind(); gvk.Group == "" && gvk.Kind == "Namespace" {
212+
namespaces = append(namespaces, obj.GetName())
213+
}
201214
}
202-
return e.Kube.DeleteBytes(ctx, manifest)
215+
return namespaces, nil
203216
}

‎cmd/ate-setup/internal/steps/delete.go‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,37 @@ func (e *Env) DeleteAtenet(ctx context.Context) error {
204204
// The demos live in their own packages, which import this one for Env, so the
205205
// interface is declared here rather than imported from there.
206206
type Deleter interface {
207-
Delete(ctx context.Context, e *Env) error
207+
Delete(ctx context.Context, e *Env) ([]string, error)
208208
}
209209

210210
// DeleteAll removes every registered demo and then the control plane.
211211
func (e *Env) DeleteAll(ctx context.Context, demos []Deleter) error {
212212
log.Step("delete_all")
213213

214+
// The demos' namespaces drain while the control plane is deleted, and are
215+
// waited for after it.
216+
var namespaces []string
214217
for _, demo := range demos {
215-
if err := demo.Delete(ctx, e); err != nil {
218+
demoNamespaces, err := demo.Delete(ctx, e)
219+
if err != nil {
220+
return err
221+
}
222+
namespaces = append(namespaces, demoNamespaces...)
223+
}
224+
if err := e.DeleteAteSystem(ctx); err != nil {
225+
return err
226+
}
227+
return e.WaitNamespacesDeleted(ctx, namespaces)
228+
}
229+
230+
// WaitNamespacesDeleted waits until each demo namespace is gone, because a
231+
// deploy cannot create objects in a namespace that is still terminating.
232+
func (e *Env) WaitNamespacesDeleted(ctx context.Context, names []string) error {
233+
namespace := schema.GroupVersionKind{Version: "v1", Kind: "Namespace"}
234+
for _, name := range names {
235+
if err := e.Kube.WaitDeleted(ctx, namespace, "", name, e.Cfg.WaitTimeout(DemoTimeout)); err != nil {
216236
return err
217237
}
218238
}
219-
return e.DeleteAteSystem(ctx)
239+
return nil
220240
}

0 commit comments

Comments
 (0)