Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 1 addition & 56 deletions src/Aspire.Hosting/ApplicationModel/EndpointReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,61 +221,6 @@ public ReferenceExpression GetTlsValue(ReferenceExpression enabledValue, Referen
GetAllocatedEndpoint()
?? throw new InvalidOperationException($"The endpoint `{EndpointName}` is not allocated for the resource `{Resource.Name}`.");

internal async Task<AllocatedEndpoint> GetAllocatedEndpointAsync(NetworkIdentifier networkId, ValueProviderContext context, CancellationToken cancellationToken = default)
{
var endpointAnnotation = EndpointAnnotation;
if (endpointAnnotation.AllAllocatedEndpoints.TryGetAllocatedEndpoint(networkId, out var endpoint))
{
return endpoint;
}

var allocationAnnotations = Resource.Annotations.OfType<OnDemandEndpointAllocationAnnotation>().ToArray();
if (allocationAnnotations.Length > 0 && await ShouldAllocateEndpointOnDemandAsync(context, cancellationToken).ConfigureAwait(false))
{
foreach (var allocationAnnotation in allocationAnnotations)
{
endpoint = allocationAnnotation.TryAllocate(endpointAnnotation, networkId);
if (endpoint is not null)
{
return endpoint;
}
}
}

// Waiting here preserves late allocation for cases that don't need the on-demand fallback,
// such as proxyless container endpoints whose actual port is reported by DCP after startup.
return await endpointAnnotation.AllAllocatedEndpoints.GetAllocatedEndpointAsync(networkId, cancellationToken).ConfigureAwait(false);
}

private async Task<bool> ShouldAllocateEndpointOnDemandAsync(ValueProviderContext context, CancellationToken cancellationToken)
{
if (context.Caller is not { } caller)
{
return true;
}

if (Resource == caller)
{
return true;
}

if (context.ExecutionContext is not { } executionContext)
{
return true;
}

var dependencies = await Resource.GetResourceDependenciesAsync(
executionContext,
new ResourceDependencyDiscoveryOptions
{
DiscoveryMode = ResourceDependencyDiscoveryMode.Recursive,
CacheAnnotationCallbackResults = true
},
cancellationToken).ConfigureAwait(false);

return dependencies.Contains(caller);
}

private EndpointAnnotation? GetEndpointAnnotation()
{
if (_endpointAnnotation is not null)
Expand Down Expand Up @@ -426,7 +371,7 @@ public class EndpointReferenceExpression(EndpointReference endpointReference, En

async ValueTask<string?> ResolveValueWithAllocatedAddress()
{
var allocatedEndpoint = await Endpoint.GetAllocatedEndpointAsync(networkContext, context, cancellationToken).ConfigureAwait(false);
var allocatedEndpoint = await Endpoint.EndpointAnnotation.AllAllocatedEndpoints.GetAllocatedEndpointAsync(networkContext, cancellationToken).ConfigureAwait(false);

return Property switch
{
Expand Down

This file was deleted.

7 changes: 1 addition & 6 deletions src/Aspire.Hosting/Dcp/ContainerCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public IEnumerable<RenderedModelResource<Container>> PrepareObjects()
}

var containerAppResource = new RenderedModelResource<Container>(container, ctr);
DcpModelUtilities.AddServicesProducedInfo(containerAppResource, _appResources.Get(), _logger);
DcpModelUtilities.AddServicesProducedInfo(containerAppResource, _appResources.Get());
_appResources.Add(containerAppResource);
result.Add(containerAppResource);
}
Expand Down Expand Up @@ -316,11 +316,6 @@ private async Task BuildAndCreateContainerAsync(RenderedModelResource<Container>
spec.RunArgs = runArgs;

var (configuration, pemCertificates, createFiles) = await BuildContainerConfiguration(cr, logger, cToken).ConfigureAwait(false);
// Configuration callbacks are the last pre-creation point where on-demand allocation can run.
cr.ModelResource.Annotations
.OfType<OnDemandEndpointAllocationAnnotation>()
.SingleOrDefault()
?.StopAllocating();

if (configuration.Exception is not null)
{
Expand Down
Loading
Loading