-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Diagram to display workload links
- Loading branch information
Showing
6 changed files
with
161 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Blazor.Diagrams; | ||
using Blazor.Diagrams.Core.Geometry; | ||
using Blazor.Diagrams.Core.Models; | ||
using k8s; | ||
using k8s.Models; | ||
|
||
namespace BlazorApp.Diagrams; | ||
|
||
public class KubeNode<T> : NodeModel where T : IKubernetesObject<V1ObjectMeta> | ||
{ | ||
public KubeNode(BlazorDiagram diagram, T item, Point position = null) : base(position) | ||
{ | ||
Item = item; | ||
Name = Item.Name(); | ||
Title = Name; | ||
Diagram = diagram; | ||
|
||
AddPort(PortAlignment.Left); | ||
AddPort(PortAlignment.Right); | ||
AddNode(item); | ||
} | ||
|
||
public T Item { get; set; } | ||
public string Name { get; set; } | ||
private BlazorDiagram Diagram { get; set; } | ||
|
||
private void AddNode(T item) | ||
{ | ||
var key = $"{item.Namespace()}/{item.Name()}"; | ||
KubeNodeContainer.Instance.AddNode(key, this); | ||
Diagram.Nodes.Add(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Collections.Generic; | ||
using Blazor.Diagrams.Core.Models; | ||
using BlazorApp.Utils; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BlazorApp.Diagrams; | ||
|
||
public class KubeNodeContainer | ||
{ | ||
private static readonly ILogger<KubeNodeContainer> Logger = LoggingHelper<KubeNodeContainer>.Logger(); | ||
private static readonly IDictionary<string, NodeModel> Map = new Dictionary<string, NodeModel>(); | ||
|
||
public static KubeNodeContainer Instance => KubeNodeContainer.Nested.Instance; | ||
|
||
public void Clear() | ||
{ | ||
Map.Clear(); | ||
} | ||
|
||
public IDictionary<string, NodeModel> AddNode(string key, NodeModel node) | ||
{ | ||
if (!Map.ContainsKey(key)) | ||
{ | ||
Map.Add(key, node); | ||
} | ||
|
||
return Map; | ||
} | ||
|
||
public NodeModel Get(string key) | ||
{ | ||
return Map.TryGetValue(key, out var nodeModel) ? nodeModel : null; | ||
} | ||
|
||
private class Nested | ||
{ | ||
internal static readonly KubeNodeContainer Instance = new KubeNodeContainer(); | ||
|
||
// Explicit static constructor to tell C# compiler | ||
// not to mark type as beforefieldinit | ||
static Nested() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@typeparam T | ||
@using k8s.Models | ||
@inherits BlazorApp.Pages.Common.PageBase | ||
|
||
<div class="default-node container"> | ||
|
||
|
||
@foreach (var port in Node.Ports.Where(x => x.Alignment == PortAlignment.Left)) | ||
{ | ||
<PortRenderer @key="port" Port="port" Class="default"/> | ||
} | ||
|
||
|
||
@foreach (var port in Node.Ports.Where(x => x.Alignment == PortAlignment.Right)) | ||
{ | ||
<PortRenderer @key="port" Port="port" Class="default"/> | ||
} | ||
|
||
<div> | ||
@Node.Item.Name() | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using BlazorApp.Pages.Common; | ||
using k8s; | ||
using k8s.Models; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace BlazorApp.Diagrams; | ||
|
||
public partial class KubeNodeWidget<T> : PageBase where T : IKubernetesObject<V1ObjectMeta> | ||
{ | ||
[Parameter] public KubeNode<T> Node { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters