2
0
mirror of synced 2025-02-22 21:18:15 +00:00

Loops in kubeconfig and namespace for discord bot.

This commit is contained in:
benbierens 2023-11-08 11:49:21 +01:00
parent 9f0f7c374a
commit 8d12bc45a1
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 29 additions and 5 deletions

View File

@ -16,12 +16,16 @@ namespace CodexDiscordBotPlugin
AddEnvVar("SERVERNAME", config.ServerName);
AddEnvVar("ADMINROLE", config.AdminRoleName);
AddEnvVar("ADMINCHANNELNAME", config.AdminChannelName);
AddEnvVar("KUBECONFIG", "/opt/kubeconfig.yaml");
AddEnvVar("KUBENAMESPACE", config.KubeNamespace);
if (!string.IsNullOrEmpty(config.DataPath))
{
AddEnvVar("DATAPATH", config.DataPath);
AddVolume(config.DataPath, 1.GB());
}
AddVolume(name: "kubeconfig", mountPath: "/opt/kubeconfig.yaml", subPath: "kubeconfig.yaml", secret: "codex-dist-tests-app-kubeconfig");
}
}
}

View File

@ -2,13 +2,14 @@
{
public class DiscordBotStartupConfig
{
public DiscordBotStartupConfig(string name, string token, string serverName, string adminRoleName, string adminChannelName)
public DiscordBotStartupConfig(string name, string token, string serverName, string adminRoleName, string adminChannelName, string kubeNamespace)
{
Name = name;
Token = token;
ServerName = serverName;
AdminRoleName = adminRoleName;
AdminChannelName = adminChannelName;
KubeNamespace = kubeNamespace;
}
public string Name { get; }
@ -16,6 +17,7 @@
public string ServerName { get; }
public string AdminRoleName { get; }
public string AdminChannelName { get; }
public string KubeNamespace { get; }
public string? DataPath { get; set; }
}
}

View File

@ -19,6 +19,12 @@ namespace BiblioTech
[Uniform("admin-channel-name", "ac", "ADMINCHANNELNAME", true, "Name of the Discord server channel where admin commands are allowed.")]
public string AdminChannelName { get; set; } = "admin-channel";
[Uniform("kube-config", "kc", "KUBECONFIG", true, "Path to Kubeconfig file. Use a Kubeconfig with read-only access.")]
public string KubeConfigFile { get; set; } = "null";
[Uniform("kube-namespace", "kn", "KUBENAMESPACE", true, "Kubernetes namespace.")]
public string KubeNamespace { get; set; } = string.Empty;
public string EndpointsPath
{
get

View File

@ -28,7 +28,7 @@ namespace BiblioTech
try
{
var deploy = JsonConvert.DeserializeObject<CodexDeployment>(str);
if (deploy != null)
if (IsDeploymentOk(deploy))
{
var targetFile = Path.Combine(Program.Config.EndpointsPath, Guid.NewGuid().ToString().ToLowerInvariant() + ".json");
File.WriteAllText(targetFile, str);
@ -59,6 +59,17 @@ namespace BiblioTech
return false;
}
private bool IsDeploymentOk(CodexDeployment? deploy)
{
if (deploy == null) return false;
if (deploy.CodexInstances == null) return false;
if (!deploy.CodexInstances.Any()) return false;
if (!deploy.CodexInstances.All(i => i.Containers != null && i.Info != null)) return false;
if (deploy.GethDeployment == null) return false;
if (deploy.GethDeployment.Containers == null) return false;
return true;
}
private void LoadDeployments()
{
var path = Program.Config.EndpointsPath;

View File

@ -41,10 +41,10 @@ namespace BiblioTech
ProjectPlugin.Load<CodexContractsPlugin.CodexContractsPlugin>();
var entryPoint = new EntryPoint(new ConsoleLog(), new KubernetesWorkflow.Configuration(
kubeConfigFile: null,
kubeConfigFile: Config.KubeConfigFile,
operationTimeout: TimeSpan.FromMinutes(5),
retryDelay: TimeSpan.FromSeconds(10),
kubernetesNamespace: "not-applicable"), "datafiles");
kubernetesNamespace: Config.KubeNamespace), "datafiles");
var ci = entryPoint.CreateInterface();

View File

@ -131,7 +131,8 @@ namespace CodexNetDeployer
token: config.DiscordBotToken,
serverName: config.DiscordBotServerName,
adminRoleName: config.DiscordBotAdminRoleName,
adminChannelName: config.DiscordBotAdminChannelName)
adminChannelName: config.DiscordBotAdminChannelName,
kubeNamespace: config.KubeNamespace)
{
DataPath = config.DiscordBotDataPath
});