Fix: DeleteInMemoryContext takes the namespace, so deleted contexts are removed
Description of your changes
Fixes #333
inMemoryContextStorage.DeleteInMemoryContext built its key as workflow-<name>-context without the namespace, while every other operation keys contexts under <ns>/workflow-<name>-context (contextKey). The keys never matched, so nothing was ever removed: with EnableInMemoryContext on, the context of every deleted Application stayed in memory for the life of the controller.
The method now takes the namespace and builds the key through the same contextKey + generateStoreName helpers the reads and writes use; the duplicate fmt.Sprintf is gone. An empty namespace resolves to default, matching create/get/update.
Carried as a separate first commit: storage_test.go imported the v1 crossplane-runtime test package while go.mod only requires crossplane-runtime/v2, so go test ./pkg/context/... failed on main with a missing go.sum entry. It now points at the v2 package like the other tests (identical helpers), which is required to run the test added here.
I have:
- Read and followed KubeVela's contribution process (the linked page has moved; this PR follows the conventions in active use: DCO sign-off,
Fix:title, PR template, tests included). - Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary. (N/A: bug fix, no config or feature surface.)
- Run
make reviewableto ensure this PR is ready for review. (Partially:makeis unavailable on this Windows machine. Ran instead:go test ./pkg/context/...,go vet ./...,gofmt,goimports -local github.com/oam-dev/kubevela,go build ./....manifests/helm-doc-genhave no input to regenerate from — no API or chart files touched. staticcheck could not run locally: the pinned v0.8.1 cannot read Go 1.27.4 export data (v5 > v4); CI will cover it.) - Added
backport release-x.ylabels to auto-backport this PR if necessary.
How has this code been tested
go test ./pkg/context/... passes, including the new TestDeleteInMemoryContext (namespaced delete, another namespace's context survives, empty namespace resolves to default). Both commits were checked independently: the test-only first commit passes on its own, and the second commit adds the fix plus the test. go vet ./..., gofmt, goimports -local github.com/oam-dev/kubevela clean; go build ./... ok.
Special notes for your reviewer
The signature change affects the caller in kubevela/kubevela (pkg/controller/core.oam.dev/v1beta1/application/application_controller.go, MemStore.DeleteInMemoryContext(app.Name)), which needs app.Namespace after a bump, per the sequencing noted in #333. Happy to send that one-line PR once this lands.
Summary by cubic
Fixes deletion of in-memory Application contexts. DeleteInMemoryContext built its lookup key without the namespace, so with EnableInMemoryContext on, the context of every deleted Application stayed in memory for the controller's lifetime. The method now takes the namespace and builds the delete key with the same contextKey + generateStoreName helpers the reads and writes use; an empty namespace resolves to default, matching create, get, and update.
Also unblocks the tests: storage_test.go imported the v1 crossplane-runtime test package while go.mod requires crossplane-runtime/v2, so go test ./pkg/context/... failed on main. The import now points at the v2 package the other tests use.
Migration
- The caller in
kubevela/kubevela(application_controller.go) must passapp.NamespacetoDeleteInMemoryContextwhen bumping.