Skip to content

Feat(workflow): name forEach items by a key, with each.key typed at admission - #7468

Merged
briankane merged 4 commits into
kubevela:masterfrom
briankane:feat/foreach-each-key
Oct 16, 2026
Merged

briankane merged 4 commits into
kubevela:masterfrom
briankane:feat/foreach-each-key

Conversation

@briankane

@briankane briankane commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Description of your changes

Brings forEach.key (kubevela/pkg#154) and each.key (kubevela/workflow#273) to an Application's workflow:

workflow:
  steps:
    - name: apply
      type: apply-object
      forEach:
        items: '$(source.inv.clusters)'
        key: [name]
      properties:
        value:
          apiVersion: v1
          kind: ConfigMap
          metadata:
            name: 'key-$(each.key)'     # key-c1, key-c2
  • The Application, ApplicationRevision and Workflow CRDs gain forEach.key.
  • Admission needs no rules of its own for the key: they come from the engine's ValidateForEachSteps, which the webhook already runs.
  • each.key is a string to the webhook's typed reads, as each.index is an int, so $(each.key) into an int parameter is refused at admission rather than at run time.

Fixes #

I have:

  • Read and followed KubeVela's pull request process.
  • All commits are signed off (DCO).
  • 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

  • EachReadKind types each.key as a string and nothing below it.
  • Webhook cases: $(each.key) into a string parameter is admitted, into an int parameter refused; a key naming the same path twice, or generating a name another step has, is refused.
  • e2e (e2e-source-test): a source-driven loop names its items by a key (apply-c1, apply-c2), and a keyed loop names its ConfigMaps from $(each.key) (key-c1, key-c2). The first ran on k3d before this rebase; both run in this PR's CI.
  • Unit tests of the touched packages pass; the repo's lint reports nothing.

Special notes for your reviewer

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

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 36 files

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

View guided diff | Re-trigger cubic

Comment thread pkg/schema/loop.go Resolved
Comment thread go.mod Resolved
Comment thread pkg/schema/definitions.go Resolved
Comment thread pkg/schema/patches.go Resolved
Comment thread pkg/schema/equivalence_test.go Resolved
Comment thread pkg/schema/kind.go Resolved
Comment thread pkg/workflow/workflow.go Resolved
@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 80.13%. Comparing base (6c4bab5) to head (94bc22b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7468   +/-   ##
=======================================
  Coverage   80.12%   80.13%           
=======================================
  Files         467      467           
  Lines       48619    48621    +2     
=======================================
+ Hits        38958    38963    +5     
+ Misses       9658     9655    -3     
  Partials        3        3           
Flag Coverage Δ
core-unittests 80.13% <100.00%> (+<0.01%) ⬆️

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 force-pushed the feat/foreach-each-key branch 6 times, most recently from 8bf4768 to b36a0a7 Compare October 15, 2026 16:06
briankane and others added 4 commits October 15, 2026 18:55
Picks up forEach.key from kubevela/pkg and kubevela/workflow: an
Application's looped step can name its items' steps by their values,
key: [cluster, namespace] giving deploy-prod-us-shop.

- The Application, ApplicationRevision and Workflow CRDs gain the field.
- Admission needs no code of its own: the key rules come from the
  engine's ValidateForEachSteps, which the webhook already runs.
- An e2e spec names the items of a source-driven loop by a key.

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>
each.key, the name of a forEach item's pass, is a string to the
webhook's typed reads, as each.index is an int. An e2e spec names a
keyed loop's ConfigMaps from it.

Signed-off-by: Brian Kane <briankane1@gmail.com>
…ch.key

Signed-off-by: Brian Kane <briankane1@gmail.com>
Signed-off-by: Brian Kane <briankane1@gmail.com>
@briankane
briankane force-pushed the feat/foreach-each-key branch from b36a0a7 to 94bc22b Compare October 15, 2026 17:56
@briankane
briankane merged commit 28372bb into kubevela:master Oct 16, 2026
45 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