Expose KubernetesEnvironmentResource.ResolveExpressionAsync as a public utility method
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
## Background and Motivation
A common scenario for custom `Resource`s and `BaseKubernetesResource`s is the need for parameterized values in a Helm chart (e.g., `{{ .Values.parameters.my_resource.my_value }}`). To do this, `ReferenceExpression` types must be conditionally resolved or replaced with a Helm template string, similar to the previous example. With the current API, it is necessary for users to create their own implementations of this mapping, even though the `KubernetesEnvironmentResource` already contains a perfectly usable implementation. When custom resources provide their own publishing steps, they should have access to this functionality so they have the same first-class behavior as out-of-the-box Aspire resources.
## Proposed API
```diff
public sealed class KubernetesEnvironmentResource : Resource, IComputeEnvironmentResource, IComputeEnvironmentWithVolumeMounts
{
- private async Task ResolveExpressionAsync(ReferenceExpression expression, string owningResourceName, CancellationToken cancellationToken)
- {
- //...
- }
}
```
```diff
+ public static class KubernetesUtilities // Or some more compliant location
+ {
+ public static async Task ResolveExpressionAsync(ReferenceExpression expression, string owningResourceName, CancellationToken cancellationToken)
+ {
+ //...
+ }
+ }
```
## Usage Examples
```csharp
var myParameter = builder.AddParameter("my-parameter");
var myResource = builder.AddMyCustomResource("name")
.WithPipelineStepFactory((pipelineCtx) =>
{
var step = new PipelineStep()
{
Name = "publish-name-extensions",
Action = async (ctx) =>
{
myResource.WithAnnotation(new KubernetesServiceCustomizationAnnotation(configure =>
{
configure.AdditionalResources.Add(new CustomCRD()
{
CustomProperty = await KubernetesUtilities.ResolveExpressionAsync(myParameter, myResource.Resource.Name, ctx.CancellationToken);
});
}));
}
};
});
```
## Alternative Designs
* Considered exposing as an extension method of `KubernetesResource` or `KubernetesEnvironmentResource`, however, that doesn't feel very idiomatic because it's not a behavior of either of those resources.
* Could be exposed as an extension on `ReferenceExpression`, but namespaced under the `Aspire.Hosting.Kubernetes` namespace to avoid polluting the public API.
## Risks
No known risks
Contributor guide
Research direction
Start by locating KubernetesEnvironmentResource.ResolveExpressionAsync and read how it resolves ReferenceExpression values for Helm templates. Review the proposed KubernetesUtilities or alternative public placement with the API review guidance; done means custom resources can call the shared resolution behavior through an approved public API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, kubernetes
- Domain
- infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100