Fix: delete an in-memory context under the key it was stored as
Description of your changes
Fixes #333
DeleteInMemoryContext built its key as workflow-<app>-context, but every write and read goes through contextKey, which is <namespace>/workflow-<app>-context (getKey, storage.go:39). The two could never match, so the delete was a no-op and the context of a deleted Application stayed in memory for the life of the controller whenever EnableInMemoryContext was on.
DeleteInMemoryContext(appName)now takes(appName, namespace)and builds the key withcontextKey(generateStoreName(appName), namespace), the same helpers the store writes with.fmtis no longer needed in the file.- New
TestDeleteInMemoryContext: deleting removes that namespace's context, leaves another namespace's alone, defaults an empty namespace the same way reads and writes do (both directions), and is a no-op for a context that was never stored.
Two things worth your attention:
- The signature change breaks the call site in kubevela/kubevela (
application_controller.gocallsMemStore.DeleteInMemoryContext(app.Name)); that repo has to passapp.Namespaceafter it bumps this module. The issue says the same, and a variadic or an extra method would leave the broken no-op delete reachable. pkg/context/storage_test.gostill importedgithub.com/crossplane/crossplane-runtime/pkg/testafter the v2 dependency bump, sogo test ./pkg/context/fails to build on main right now withmissing go.sum entry for module providing package github.com/crossplane/crossplane-runtime/pkg/test. I changed that one line to/v2/pkg/test; otherwise the package's tests, including the new one, cannot run. Nothing else from the v1 module is imported anywhere in the repo (git grep crossplane-runtime/pkg), so this is the only stale import.
I have:
- Read and followed KubeVela's contribution process.
- Related Docs updated properly. (No user-facing configuration changed.)
- Run
make reviewablefor the packages I touched:gofmt -l pkg/contextclean,go vet ./pkg/context/clean. I did not run the full target because it regenerates manifests and CRDs unrelated to this change. - Added
backport release-x.ylabels.
How has this code been tested
go test ./pkg/context/— ok, all tests in the package pass.- Fault injection: restoring the old key (
contextKey(generateStoreName(app.Name), ""), namespace dropped) makes the new test fail atstorage_test.go:94with "delete should remove the stored context"; the fix makes it pass. So the test fails for the reason the issue describes and not only for the signature. - The new test drives the exported methods only; the controller-level effect (a deleted Application's context going away) is not exercised here because
MemStoreis package-global and the call site lives in the other repo.
Special notes for your reviewer
The namespace argument is deliberately explicit rather than defaulted inside the delete: the store already treats "" as default, and the test pins both directions, so a caller that forgets app.Namespace gets default — which is what NewContext writes for a cluster-scoped or default-namespace Application.
Summary by cubic
Fixes in-memory context deletion so the stored context of a deleted Application is actually removed instead of remaining in memory for the life of the controller.
DeleteInMemoryContext built its key as workflow-<app>-context, but every read and write uses <namespace>/workflow-<app>-context; the keys never matched, so the delete was a no-op.
- The method now takes
(appName, namespace)and builds the key with the same helpers reads and writes use. This is a breaking change for callers, who must passapp.Namespace. - Adds
TestDeleteInMemoryContextcovering per-namespace deletion, empty-namespace defaulting in both directions, and no-ops on never-stored contexts. - Fixes a stale
crossplane-runtimev1 import inpkg/context/storage_test.gothat brokego test ./pkg/context/.