-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathKubernetesDiscoveryOptions.cs
75 lines (65 loc) · 3.29 KB
/
KubernetesDiscoveryOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// -----------------------------------------------------------------------
// <copyright file="KubernetesDiscoveryOptions.cs" company="Akka.NET Project">
// Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Linq;
using System.Text;
using Akka.Actor.Setup;
using Akka.Hosting;
namespace Akka.Discovery.KubernetesApi;
public class KubernetesDiscoveryOptions: IDiscoveryOptions
{
public string ConfigPath { get; set; } = KubernetesApiServiceDiscovery.DefaultPath;
public Type Class { get; } = typeof(KubernetesApiServiceDiscovery);
public bool IsDefaultPlugin { get; set; } = true;
public string? ApiCaPath { get; set; }
public string? ApiTokenPath { get; set; }
public string? ApiServiceHostEnvName { get; set; }
public string? ApiServicePortEnvName { get; set; }
public string? PodNamespacePath { get; set; }
public string? PodNamespace { get; set; }
public bool? AllNamespaces { get; set; }
public string? PodDomain { get; set; }
public string? PodLabelSelector { get; set; }
public bool? RawIp { get; set; }
public string? ContainerName { get; set; }
public void Apply(AkkaConfigurationBuilder builder, Setup? setup = null)
{
var sb = new StringBuilder();
sb.AppendLine($"{KubernetesApiServiceDiscovery.FullPath(ConfigPath)} {{");
sb.AppendLine($"class = {Class.AssemblyQualifiedName!.ToHocon()}");
if (ApiCaPath is { })
sb.AppendLine($"api-ca-path = {ApiCaPath.ToHocon()}");
if (ApiTokenPath is { })
sb.AppendLine($"api-token-path = {ApiTokenPath.ToHocon()}");
if (ApiServiceHostEnvName is { })
sb.AppendLine($"api-service-host-env-name = {ApiServiceHostEnvName.ToHocon()}");
if (ApiServicePortEnvName is { })
sb.AppendLine($"api-service-port-env-name = {ApiServicePortEnvName.ToHocon()}");
if (PodNamespacePath is { })
sb.AppendLine($"pod-namespace-path = {PodNamespacePath.ToHocon()}");
if (PodNamespace is { })
sb.AppendLine($"pod-namespace = {PodNamespace.ToHocon()}");
if (AllNamespaces is { })
sb.AppendLine($"all-namespaces = {AllNamespaces.ToHocon()}");
if (PodDomain is { })
sb.AppendLine($"pod-domain = {PodDomain.ToHocon()}");
if (PodLabelSelector is { })
sb.AppendLine($"pod-label-selector = {PodLabelSelector.ToHocon()}");
if (RawIp is { })
sb.AppendLine($"use-raw-ip = {RawIp.ToHocon()}");
if (ContainerName is { })
sb.AppendLine($"container-name = {ContainerName.ToHocon()}");
sb.AppendLine("}");
if(IsDefaultPlugin)
sb.AppendLine($"akka.discovery.method = {ConfigPath}");
builder.AddHocon(sb.ToString(), HoconAddMode.Prepend);
var fallback = KubernetesDiscovery.DefaultConfiguration()
.GetConfig(KubernetesApiServiceDiscovery.FullPath(KubernetesApiServiceDiscovery.DefaultPath))
.MoveTo(KubernetesApiServiceDiscovery.FullPath(ConfigPath));
builder.AddHocon(fallback, HoconAddMode.Append);
}
}