[Backport release-0.8] Fix: delete an in-memory context under the key it was stored as
Backport of #336 to release-0.8, for workflow v0.8.0 (KubeVela 1.12.0). The fix is @marcus-beauregard's; the commit keeps him as author and is cherry-picked with -x.
What it fixes
DeleteInMemoryContext built its key as workflow-<app>-context, while every write and read keys the store as <namespace>/workflow-<app>-context. The keys never matched, so the delete did nothing and a deleted Application's context stayed in memory for the life of the controller. It now takes the namespace and builds the key the same way the writes do.
How it differs from #336
release-0.8 doesn't have #262, so the store is still a plain map rather than pkg/cache. The intent is unchanged:
contextKey(name, ns)is added here (on main it came with #262), defaulting an empty namespace todefault, andgetKey,GetInMemoryContextandDeleteInMemoryContextall build their keys with it.pkg/context/storage_test.godoesn't exist on this branch, so it's new, with #336'sTestDeleteInMemoryContextunchanged and two small helpers for the map-backed store.
As on main, DeleteInMemoryContext now takes (appName, namespace), so KubeVela's call site has to pass app.Namespace when it bumps to this release.
Testing
go build ./...andgo vet ./...clean.go test ./pkg/context -run TestDeleteInMemoryContext: passes (deletes the stored context, leaves another namespace's alone, defaults an empty namespace both ways, no-op on a missing key).go test ./pkg/...: everything passes except the two email packages, which fail on macOS arm64 with or without this change (gomonkey can't patch the binary there).
Summary by cubic
Fixes DeleteInMemoryContext so it deletes in-memory contexts under the same key format used by reads and writes.
Previously it built the key as workflow-<app>-context while all other operations used <namespace>/workflow-<app>-context, so the delete never matched and stale contexts lingered in memory for the controller's lifetime. It now takes the namespace and builds the key through the shared contextKey helper. Callers must pass app.Namespace when invoking the method.
- Adds tests covering namespace isolation, empty-namespace defaulting, and missing-key no-ops.