-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Discovery.Kubernetes extension method to take options instead …
…of setup (#1200) Co-authored-by: Aaron Stannard <aaron@petabridge.com>
- Loading branch information
1 parent
9dab9cb
commit ce88f36
Showing
3 changed files
with
91 additions
and
31 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
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
66 changes: 66 additions & 0 deletions
66
src/discovery/kubernetes/Akka.Discovery.KubernetesApi/KubernetesDiscoveryOptions.cs
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,66 @@ | ||
// ----------------------------------------------------------------------- | ||
// <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: IHoconOption | ||
{ | ||
private const string FullPath = "akka.discovery.kubernetes-api"; | ||
|
||
public string ConfigPath { get; } = "kubernetes-api"; | ||
public Type Class { get; } = typeof(KubernetesApiServiceDiscovery); | ||
|
||
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 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($"{FullPath} {{"); | ||
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 (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("}"); | ||
|
||
builder.AddHocon(sb.ToString(), HoconAddMode.Prepend); | ||
builder.AddHocon(KubernetesDiscovery.DefaultConfiguration(), HoconAddMode.Append); | ||
} | ||
} |