From 1ac8e131f98b2cfc018faab29112bb90bc03fd20 Mon Sep 17 00:00:00 2001 From: Karol Zadora-Przylecki Date: Fri, 6 Oct 2023 13:16:37 -0700 Subject: [PATCH] Remove dependency between K8s service and dashboard --- .../Dashboard/DashboardViewModelService.cs | 10 +++++++--- src/Aspire.Hosting/Dcp/KubernetesService.cs | 1 - src/Aspire.Hosting/Dcp/Model/ModelCommon.cs | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs b/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs index 0f3cd9f640..10656ae151 100644 --- a/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs +++ b/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs @@ -8,6 +8,7 @@ using Aspire.Hosting.Dcp; using Aspire.Hosting.Dcp.Model; using k8s; +using NamespacedName = Aspire.Dashboard.Model.NamespacedName; namespace Aspire.Hosting.Dashboard; @@ -46,7 +47,8 @@ public async IAsyncEnumerable> WatchContain IEnumerable? existingContainers = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - await foreach (var (watchEventType, container) in _kubernetesService.WatchAsync(existingObjects: existingContainers, cancellationToken: cancellationToken)) + var existingObjects = existingContainers?.Select(ec => new Dcp.Model.NamespacedName(ec.Name, ec.Namespace)); + await foreach (var (watchEventType, container) in _kubernetesService.WatchAsync(existingObjects: existingObjects, cancellationToken: cancellationToken)) { var objectChangeType = ToObjectChangeType(watchEventType); if (objectChangeType == ObjectChangeType.Other) @@ -64,7 +66,8 @@ public async IAsyncEnumerable> WatchExecut IEnumerable? existingExecutables = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - await foreach (var (watchEventType, executable) in _kubernetesService.WatchAsync(existingObjects: existingExecutables, cancellationToken: cancellationToken)) + var existingObjects = existingExecutables?.Select(ec => new Dcp.Model.NamespacedName(ec.Name, ec.Namespace)); + await foreach (var (watchEventType, executable) in _kubernetesService.WatchAsync(existingObjects: existingObjects, cancellationToken: cancellationToken)) { var objectChangeType = ToObjectChangeType(watchEventType); if (objectChangeType == ObjectChangeType.Other) @@ -87,7 +90,8 @@ public async IAsyncEnumerable> WatchProjectsA IEnumerable? existingProjects = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - await foreach (var (watchEventType, executable) in _kubernetesService.WatchAsync(existingObjects: existingProjects, cancellationToken: cancellationToken)) + var existingObjects = existingProjects?.Select(ec => new Dcp.Model.NamespacedName(ec.Name, ec.Namespace)); + await foreach (var (watchEventType, executable) in _kubernetesService.WatchAsync(existingObjects: existingObjects, cancellationToken: cancellationToken)) { var objectChangeType = ToObjectChangeType(watchEventType); if (objectChangeType == ObjectChangeType.Other) diff --git a/src/Aspire.Hosting/Dcp/KubernetesService.cs b/src/Aspire.Hosting/Dcp/KubernetesService.cs index 5d20c522fa..ed24d9acd8 100644 --- a/src/Aspire.Hosting/Dcp/KubernetesService.cs +++ b/src/Aspire.Hosting/Dcp/KubernetesService.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; -using Aspire.Dashboard.Model; using Aspire.Hosting.Dcp.Model; using k8s; using k8s.Exceptions; diff --git a/src/Aspire.Hosting/Dcp/Model/ModelCommon.cs b/src/Aspire.Hosting/Dcp/Model/ModelCommon.cs index 66a63d8425..286fd6ce21 100644 --- a/src/Aspire.Hosting/Dcp/Model/ModelCommon.cs +++ b/src/Aspire.Hosting/Dcp/Model/ModelCommon.cs @@ -153,6 +153,8 @@ public override int GetHashCode() } } +public sealed record NamespacedName(string Name, string? Namespace); + public static class Rules { public static bool IsValidObjectName(string candidate)