Skip to content

Fix: inject the multicluster client into the workflow context - #251

Merged
briankane merged 1 commit into
kubevela:mainfrom
cuixiaojun001:main
Nov 21, 2026
Merged

briankane merged 1 commit into
kubevela:mainfrom
cuixiaojun001:main

Conversation

@cuixiaojun001

@cuixiaojun001 cuixiaojun001 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

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 #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.

Written for commit acfcdcc. Summary will update on new commits.

Review in cubic

@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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread controllers/workflow_test.go Resolved
@codecov

codecov Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.97%. Comparing base (d7db9c4) to head (acfcdcc).
⚠️ Report is 51 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #251      +/-   ##
==========================================
+ Coverage   62.49%   69.97%   +7.48%     
==========================================
  Files          62       74      +12     
  Lines        4415     5842    +1427     
==========================================
+ Hits         2759     4088    +1329     
- Misses       1324     1365      +41     
- Partials      332      389      +57     
Flag Coverage Δ
e2etests 24.62% <100.00%> (?)
unit-test 64.39% <100.00%> (+1.90%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@briankane briankane changed the title [紧急] fix: inject multicluster client into workflow context Fix: inject the multicluster client into the workflow context Nov 20, 2026
@briankane briankane added area/multicluster Cluster targeting and cluster-gateway routing area/provider priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. type/bug Something isn't working labels Nov 21, 2026
@briankane
briankane merged commit 2df730a into kubevela:main Nov 21, 2026
22 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/multicluster Cluster targeting and cluster-gateway routing area/provider priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standalone vela-workflow ignores kube.#Apply cluster parameter and applies resources to the control-plane cluster

2 participants