Fix: inject the multicluster client into the workflow context

Merged
CU
6h ago
+62-0

Description of your changes

This PR fixes multi-cluster workflow steps executed by the standalone vela-workflow controller.

Previously, Kubernetes providers could fall back to the global singleton client because the reconciler's cluster-aware Kubernetes client was not injected into the workflow context. As a result, steps such as kube.#Apply could ignore the requested target cluster and apply resources to the control-plane cluster instead.

This change:

  • Injects the reconciler's Kubernetes client into the workflow context.
  • Injects a Kubernetes-backed configuration factory into the workflow context.
  • Ensures providers receive and use the cluster-aware client.
  • Adds a regression test verifying that the target cluster from the step context reaches the Kubernetes client.

Fixes kubevela/workflow#250

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

The following automated checks passed:

  • go test ./controllers ./pkg/providers/kube -count=1
  • go vet ./...

The fix was also validated in a Kubernetes environment using a WorkflowRun containing a build step:

  • The workflow controller ran in the control-plane cluster.
  • The step targeted cluster k8s-cloud01-thor-test.
  • The Kaniko Pod was created in the target cluster's cloudstudio-ci namespace.
  • The build Pod completed successfully.
  • The resulting container image was successfully built and pushed.

A regression test was added using a recording Kubernetes client to verify that the requested cluster name is propagated through the workflow context to provider client operations.

Special notes for your reviewer

The provider fallback to singleton.KubeClient is intentionally preserved for contexts where no Kubernetes client has been injected.

The standalone workflow reconciler now explicitly injects its cluster-aware client before workflow step execution, allowing providers to honor multi-cluster context without changing the provider API.


Summary by cubic

Injects the reconciler’s multi‑cluster Kubernetes client into the workflow context so kube provider calls run against the step’s target cluster. Previously, steps could fall back to the global client and apply to the control‑plane cluster; now providers use the reconciler client and operate on the requested cluster. Fallback to the global client remains when no client is injected.

Review focus

  • controllers/workflowrun_controller.go: injects the client via providertypes.WithKubeClient(ctx, r.Client) before step execution.
  • pkg/providers/types: adds WithKubeClient to carry the client in context.
  • controllers/workflow_test.go: regression test uses a recording client to assert the cluster from context reaches client ops and that the applied object exists.
  • No provider API changes; behavior change is limited to the standalone controller honoring multi‑cluster targets.