Skip to content

Conversation

briankane
Copy link
Contributor

@briankane briankane commented May 13, 2025

Description of your changes

Allows functions to be supplied into the CompilerOptions that will execute during the compilation process and allows mutations to be made on the cue value. These mutations run after initial parsing and before provider function resolution.

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

Compiler unit testing

Special notes for your reviewer

This feature won't do anything on it's own. This is to allow changes in the main Kubevela repo for loading of configuration within Components and Traits, in a similar fashion to the Trait processing field.

e.g:

config: {
  configName: {
    name: "a-kubevela-config"
    namespace: "vela-system" 
  }
}

someOtherField: config.configName.output.{configKey}

For this to work correctly, we need to load the config into the cue.Value{} after parsing but before CueX provider function processing, otherwise the use of a config field in the provider functions $params causes a compilation issue. To solve, the logic for reading the config will be moved from running after compilation in the template.go file, to being passed as a IntraResolveMutation that runs before provider function processing.

i.e.

config: {
  configName: {
    name: "a-kubevela-config"
    namespace: "vela-system" 
  }
}

cuexFunc: ext.#Example & {
  $params: {
    input: config.configName.output.{key}  // causes a compilation issue as the config isn't currently loaded until later
  }
}

Summary by mrge

Added support for intra resolve mutations in the compiler, allowing custom mutations to run after parsing but before provider function resolution.

  • New Features
    • Introduced WithIntraResolveMutation to let users inject mutation functions during compilation.
    • Updated tests to cover intra resolve mutation behavior.

@briankane briankane force-pushed the feature/intra-resolve-compiler-mutations branch from 64be190 to 0e6f92e Compare May 13, 2025 12:27
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mrge found 2 issues across 2 files. Review them in mrge.io

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mrge found 2 issues across 2 files. Review them in mrge.io

@briankane briankane marked this pull request as draft May 13, 2025 12:32
@briankane briankane force-pushed the feature/intra-resolve-compiler-mutations branch 4 times, most recently from 7029a1a to 4c0dd50 Compare May 13, 2025 15:15
Copy link

codecov bot commented May 13, 2025

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 86.68%. Comparing base (f76e317) to head (4c0dd50).

Files with missing lines Patch % Lines
cue/cuex/compiler.go 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
- Coverage   86.71%   86.68%   -0.03%     
==========================================
  Files          82       82              
  Lines        4071     4085      +14     
==========================================
+ Hits         3530     3541      +11     
- Misses        408      410       +2     
- Partials      133      134       +1     
Flag Coverage Δ
unit-test 86.68% <78.57%> (-0.03%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

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.

1 participant