Refactor: Use generalized cache for StepStatusCache.

Merged
KA
4mo ago
+119-52

Description of your changes

This PR replaces the sync.Map with the map cache that will be introduced in kubevela/pkg PR to use the centralized package instead of declaring as per the current status.

Fixes #239

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Since the PR for the generic cache hasn't been merged yet, used workspaces to test this features.

  1. Create a go workspace
go work init
go work use <workspace-folder-name>
go work use <kubevela-folder-name>
go work use <pkg-folder-name>
  1. Build the project to ensure the workspace dependency is used.
go build ./...

Note: Avoid running go mod tidy in any repo, as it updates the module graph and throws error saying that package cache doesn't exist in kubevela/pkg

  1. Update the sync-crds target in the KubeVela dependency.mk to disable the workspace when downloading the pinned module version for CRDs.
sync-crds: ## Copy CRD from pinned module version in go.mod
	@moddir=$$(GOWORK=off go mod download -json $(PKG_MODULE) 2>/dev/null | grep '"Dir"' | cut -d'"' -f4); \
	mkdir -p config/crd/base; \
	for file in $(COMMON_CRD_FILES); do \
		src="$$moddir/crds/$$file"; \
		cp -f "$$src" "config/crd/base/"; \
	done

This ensures that the CRDs are copied from the module version pinned in go.mod rather than from the local workspace checkout.

  1. Build and install the updated KubeVela controller.
  2. Deploy a sample application:
vela up -f https://kubevela.io/example/applications/first-app.yaml
  1. Verify that the application is successfully reconciled and deployed, confirming that the local workspace version of github.com/kubevela/pkg and github.com/kubevela/workflow is being used and that the changes work as expected.

Special notes for your reviewer

The CI pipeline and tests are expected to fail for this PR.

This change depends on the generic cache implementation introduced in the corresponding github.com/kubevela/pkg PR, which has not been merged yet. As a result, the cache package is not available in the published module version.


Summary by cubic

Refactor StepStatusCache to use the generalized github.com/kubevela/pkg/cache with TTL entries and safe, one-time initialization at startup and during workflow init. Adds skip-logic test coverage to address #239.

  • Refactors

    • Replace sync.Map with cache.Cache[string] from github.com/kubevela/pkg/cache.
    • Add InitStepStatusCache(ctx); call it in controller SetupWithManager, test suites’ BeforeSuite, and InitializeWorkflowInstance for nil-safe usage.
    • Use Put/Get with a 3-minute TTL for step count entries; use Put(..., ReconcileTimeout) on status update/patch errors.
    • Add unit test for WorkflowStateSkipped when cached step count exceeds status.
  • Dependencies

    • Update github.com/kubevela/pkg to a pseudo-version providing cache; align related minor deps.