microsoft / microsoft/aspire

Service Discovery environment variables don't resolve on all environments

Open
#16,613 1 comment 0 reactions 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Hyphens are not valid characters in environment variable names on Linux. Currently, if a resource has a name containing a hyphen, Aspire injects the service with an environment variable key that also includes a hyphen. This causes errors in deployments where (at least in k8s environments), the environment variable is completely missing.

### Expected Behavior

I'm not sure if the solution should be restricting hyphens from resource names under certain scenarios (like if it's being used as a service by another resource), or if the environment variable names should be normalized, along with updates to .NET's service discovery package to properly resolve those normalized names.

### Steps To Reproduce

```csharp
var service = builder.AddProject("my-project", filePath).WithHttpEndpoint();

var service2 = builder.AddProject("my-second-project").WithReference(service);

// resulting environment variable --> services__my-project__http__0
```

### Exceptions (if any)

_No response_

### Aspire doctor output

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.