Background and Motivation
A common scenario for custom Resources and BaseKubernetesResources 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
public sealed class KubernetesEnvironmentResource : Resource, IComputeEnvironmentResource, IComputeEnvironmentWithVolumeMounts
{
- private async Task<string> ResolveExpressionAsync(ReferenceExpression expression, string owningResourceName, CancellationToken cancellationToken)
- {
- //...
- }
}
+ public static class KubernetesUtilities // Or some more compliant location
+ {
+ public static async Task<string> ResolveExpressionAsync(ReferenceExpression expression, string owningResourceName, CancellationToken cancellationToken)
+ {
+ //...
+ }
+ }
Usage Examples
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
Background and Motivation
A common scenario for custom
Resources andBaseKubernetesResources is the need for parameterized values in a Helm chart (e.g.,{{ .Values.parameters.my_resource.my_value }}). To do this,ReferenceExpressiontypes 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 theKubernetesEnvironmentResourcealready 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
public sealed class KubernetesEnvironmentResource : Resource, IComputeEnvironmentResource, IComputeEnvironmentWithVolumeMounts { - private async Task<string> ResolveExpressionAsync(ReferenceExpression expression, string owningResourceName, CancellationToken cancellationToken) - { - //... - } }Usage Examples
Alternative Designs
KubernetesResourceorKubernetesEnvironmentResource, however, that doesn't feel very idiomatic because it's not a behavior of either of those resources.ReferenceExpression, but namespaced under theAspire.Hosting.Kubernetesnamespace to avoid polluting the public API.Risks
No known risks