Skip to content

Feat: name forEach items by a key - #154

Merged
briankane merged 1 commit into
kubevela:mainfrom
briankane:feat/foreach-item-key
Oct 15, 2026
Merged

briankane merged 1 commit into
kubevela:mainfrom
briankane:feat/foreach-item-key

Conversation

@briankane

@briankane briankane commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Description of your changes

Adds an optional key to ForEach, so a loop's steps can be named by each item's values rather than its position.

forEach:
  from: targets            # [{cluster: prod-us, namespace: shop}, ...]
  key: [cluster, namespace]
Looped Without key With key: [cluster, namespace]
a step deploy deploy-0 deploy-prod-us-shop
a group rollout, sub-step verify rollout-0-verify rollout-prod-us-shop-verify
  • key is a list of paths into each item, the same dotted syntax as inputs[].from. One field is still a list (key: [name]), so the CRD and the docs have one shape.
  • The values are joined with -. The engine checks each part is a string or an integer, none is missing, the joined key uses step-name characters and is unique in the loop; the schema bounds the list at one to eight paths.
  • The Workflow CRD is regenerated.

This is the API half. The engine is kubevela/workflow#273 and the Application support kubevela/kubevela#7468.

How has this code been tested

  • A round-trip test for key, its omission when unset, and deepcopy independence.
  • The engine and KubeVela changes are built and tested on top of this commit (unit, envtest and lint in both).

Special notes for your reviewer

Merge order: this PR first, then kubevela/workflow#273, then kubevela/kubevela#7468. The other two carry a temporary replace onto this branch until this merges.


Summary by cubic

Adds an optional key to ForEach so loop steps are named by each item's values instead of its position. With key: [cluster, namespace] over items like {cluster: prod-us, namespace: shop}, a step deploy becomes deploy-prod-us-shop instead of deploy-0; the Workflow CRD is regenerated.

  • key takes one to eight dotted paths into each item; values must be strings or integers, be present, and be unique after joining with -.
  • This is the API half only. The engine (kubevela/workflow) and Application (kubevela/kubevela) support land in follow-up PRs, so this PR must merge first.
  • The field is optional and omitted when unset, so existing loops behave as before.

Written for commit 2a2c76e. Summary will update on new commits.

View guided diff

ForEach gains an optional key: paths into each item whose values,
joined with "-", replace the index in the names of the item's steps
(deploy-prod-us-shop rather than deploy-0). A composite key is a list
of paths. The engine checks that each value is a string or an integer
and that the joined keys are unique; the schema bounds the list at one
to eight paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014vkPtmKeCEZo2EL7QWCMhH
Signed-off-by: Brian Kane <briankane1@gmail.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 4 files

View guided diff | Re-trigger cubic

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.49%. Comparing base (e56a460) to head (2a2c76e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #154      +/-   ##
==========================================
- Coverage   92.58%   92.49%   -0.09%     
==========================================
  Files         115      115              
  Lines        6930     6930              
==========================================
- Hits         6416     6410       -6     
- Misses        514      520       +6     
Flag Coverage Δ
unit-test 92.49% <ø> (-0.09%) ⬇️

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 merged commit a754071 into kubevela:main Oct 15, 2026
11 checks passed
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.

2 participants