Refactor: Migrate optional in-memory context storage to pkg/cache
Description of your changes
Moves MemStore onto github.com/kubevela/pkg/cache, same approach as the email change in #259. Entries go in with no expiry since this is live workflow context, and the exported methods stay the same because vela-core calls them.
GetOrCreateInMemoryContext now holds the lock for the whole lookup + create, and reads use the same namespace defaulting as writes (empty namespace -> default).
Fixes #254
I have:
- Read and followed KubeVela's contribution process.
- Related Docs updated properly. (internal refactor, no docs change)
- Run
make reviewableto ensure this PR is ready for review. (fmt, vet, golangci-lint and staticcheck; no manifest or chart changes) - Added
backport release-x.ylabels to auto-backport this PR if necessary.
How has this code been tested
Added pkg/context/storage_test.go: create/get/update, empty namespace, get-or-create returning a copy, concurrent access, and NewContext -> Commit -> LoadContext with EnableInMemoryContext on. go test -race ./pkg/context/... passes.
Special notes for your reviewer
Two existing bugs I left out to keep this a straight refactor:
DeleteInMemoryContext(appName)builds the key without the namespace, so the delete vela-core does on app deletion never matches anything (details on #254).- With in-memory context on,
sync()still falls through tocli.Patchafter updating the memory store. Looks like that came in with 9eda5ba.
I can send follow-ups for either if you want.
Summary by cubic
Migrates in-memory workflow context storage from a plain map to github.com/kubevela/pkg/cache without changing exported methods for vela-core callers. Entries are stored without expiry since they hold live workflow context. Fixes #254.
GetOrCreateInMemoryContextnow holds the lock across the whole lookup and create, so concurrent calls can't race.- Reads now apply the same namespace defaulting as writes (empty namespace ->
default). - Adds
pkg/context/storage_test.gocovering create/update/get, empty namespace handling, concurrent get-or-create asserting every caller ends up with the stored context, andNewContext/Commit/LoadContextwith in-memory storage enabled. - Known bugs left out of scope:
DeleteInMemoryContextbuilds its key without the namespace, andsync()still falls through tocli.Patchwhen in-memory context is on. Can be sent as follow-ups.