Skip to content

Fix: DeleteInMemoryContext takes the namespace, so deleted contexts are removed - #337

Open
KTEC0230 wants to merge 2 commits into
kubevela:mainfrom
KTEC0230:fix/delete-in-memory-context-namespace
Open

KTEC0230 wants to merge 2 commits into
kubevela:mainfrom
KTEC0230:fix/delete-in-memory-context-namespace

Conversation

@KTEC0230

@KTEC0230 KTEC0230 commented Nov 21, 2026 •

Copy link
Copy Markdown

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 reviewable to ensure this PR is ready for review. (Partially: make is 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-gen have 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.y labels 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 pass app.Namespace to DeleteInMemoryContext when bumping.

Written for commit 21b43f0. Summary will update on new commits.

View guided diff

storage_test.go imports the v1 crossplane-runtime test package, while go.mod
only requires crossplane-runtime/v2. go test ./pkg/context/... fails on main
with a missing go.sum entry for the v1 module. Point the import at the same
v2 test package the other tests use, which exposes the identical helpers
(test.MockClient, test.NewMockGetFn, ...).

Signed-off-by: KTEC0230 <354444639+KTEC0230@users.noreply.github.com>
…re removed

With EnableInMemoryContext on, contexts are stored under <ns>/workflow-<name>-context
(contextKey), but DeleteInMemoryContext built its key without the namespace, so the
keys never matched and nothing was ever removed (kubevela#333): the context of every deleted
Application stayed in memory for the life of the controller.

Build the delete key through contextKey + generateStoreName, the same helpers the
reads and writes use, and drop the now-unused duplicate fmt.Sprintf. The signature
change needs the call site in kubevela/kubevela
(pkg/controller/core.oam.dev/v1beta1/application/application_controller.go) to pass
app.Namespace after a bump, per kubevela#333.

Signed-off-by: KTEC0230 <354444639+KTEC0230@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

View guided diff | Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DeleteInMemoryContext never removes anything, so in-memory contexts pile up

1 participant