Two BaseKubernetesResource with same Metadata.Name and then when running aspire publish the two resources overrides each other
- 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
When I create a custom BaseKubernetesResource for ServiceExport for my GKE setup it needs to have the same Metadata.Name as the built in KubernetesResource.Service property but if they are equal my custom BaseKubernetesResource overrides the output of service.yaml.
### Expected Behavior
Expected behavior is to either merge them to a single file with separator `---`
```yaml
#/k8s-artifacts/templates/api/service.yaml
---
apiVersion: "v1"
kind: "Service"
metadata:
name: "api-service"
labels:
app.kubernetes.io/name: "apphost"
app.kubernetes.io/component: "api"
app.kubernetes.io/instance: "{{.Release.Name}}"
spec:
type: "ClusterIP"
selector:
app.kubernetes.io/name: "apphost"
app.kubernetes.io/component: "api"
app.kubernetes.io/instance: "{{.Release.Name}}"
ports:
- name: "http"
protocol: "TCP"
port: "{{ .Values.parameters.api.port_http }}"
targetPort: "{{ .Values.parameters.api.port_http }}"
- name: "https"
protocol: "TCP"
port: "{{ .Values.parameters.api.port_https }}"
targetPort: "{{ .Values.parameters.api.port_https }}"
---
apiVersion: "net.gke.io/v1"
kind: "ServiceExport"
metadata:
name: "api-service"
labels:
app.kubernetes.io/name: "apphost"
app.kubernetes.io/component: "api"
app.kubernetes.io/instance: "{{.Release.Name}}"
```
or support two separate files
```yaml
#/k8s-artifacts/templates/api/service.yaml
---
apiVersion: "v1"
kind: "Service"
metadata:
name: "api-service"
labels:
app.kubernetes.io/name: "apphost"
app.kubernetes.io/component: "api"
app.kubernetes.io/instance: "{{.Release.Name}}"
spec:
type: "ClusterIP"
selector:
app.kubernetes.io/name: "apphost"
app.kubernetes.io/component: "api"
app.kubernetes.io/instance: "{{.Release.Name}}"
ports:
- name: "http"
protocol: "TCP"
port: "{{ .Values.parameters.api.port_http }}"
targetPort: "{{ .Values.parameters.api.port_http }}"
- name: "https"
protocol: "TCP"
port: "{{ .Values.parameters.api.port_https }}"
targetPort: "{{ .Values.parameters.api.port_https }}"
```
```yaml
#/k8s-artifacts/templates/api/service-export.yaml
---
apiVersion: "net.gke.io/v1"
kind: "ServiceExport"
metadata:
name: "api-service"
labels:
app.kubernetes.io/name: "apphost"
app.kubernetes.io/component: "api"
app.kubernetes.io/instance: "{{.Release.Name}}"
```
### Steps To Reproduce
```xml
Exe
net10.0
enable
enable
```
```c#
// Apphost.cs
using Aspire.Hosting.Kubernetes.Resources;
using YamlDotNet.Serialization;
var builder = DistributedApplication.CreateBuilder(args);
builder.AddKubernetesEnvironment("k8s");
var api = builder.AddProject("api", "../Api/Api.csproj")
.PublishAsKubernetesService(kubernetes =>
{
var serviceExport = new ServiceExportResource();
serviceExport.Metadata.Name = kubernetes.Service.Metadata.Name;
kubernetes.AdditionalResources.Add(serviceExport);
});
await builder.Build().RunAsync();
[YamlSerializable]
public class ServiceExportResource() : BaseKubernetesResource("net.gke.io/v1", "ServiceExport");
```
This code generates this when running `aspire publish -o ./k8s-artifacts`
```yaml
#/k8s-artifacts/templates/api/service.yaml
---
apiVersion: "net.gke.io/v1"
kind: "ServiceExport"
metadata:
name: "api-service"
labels:
app.kubernetes.io/name: "apphost"
app.kubernetes.io/component: "api"
app.kubernetes.io/instance: "{{.Release.Name}}"
```
### Exceptions (if any)
_No response_
### .NET Version info
dotnet --info
.NET SDK:
Version: 10.0.102
Commit: 4452502459
Workload version: 10.0.100-manifests.e5d3dea4
MSBuild version: 18.0.7+445250245
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.102\
.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.
Host:
Version: 10.0.2
Architecture: x64
Commit: 4452502459
.NET SDKs installed:
9.0.308 [C:\Program Files\dotnet\sdk]
10.0.100-rc.1.25451.107 [C:\Program Files\dotnet\sdk]
10.0.102 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0-rc.1.25451.107 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0-rc.1.25451.107 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0-rc.1.25451.107 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
### Anything else?
Aspire version 13.1.1
Aspire cli version 13.1.1
Contributor guide
Research direction
Start with the Aspire publish path involving BaseKubernetesResource, KubernetesResource.Service, and AdditionalResources, using the Apphost.cs reproduction and generated k8s-artifacts/templates/api/service.yaml. Verify behavior when Service and ServiceExport share Metadata.Name, then add coverage showing whether the resources are merged with a separator or emitted as separate files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, kubernetes
- Domain
- cloud, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100