2
0
mirror of synced 2025-02-23 13:38:07 +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("SERVERNAME", config.ServerName);
AddEnvVar("ADMINROLE", config.AdminRoleName); AddEnvVar("ADMINROLE", config.AdminRoleName);
AddEnvVar("ADMINCHANNELNAME", config.AdminChannelName); AddEnvVar("ADMINCHANNELNAME", config.AdminChannelName);
AddEnvVar("KUBECONFIG", "/opt/kubeconfig.yaml");
AddEnvVar("KUBENAMESPACE", config.KubeNamespace);
if (!string.IsNullOrEmpty(config.DataPath)) if (!string.IsNullOrEmpty(config.DataPath))
{ {
AddEnvVar("DATAPATH", config.DataPath); AddEnvVar("DATAPATH", config.DataPath);
AddVolume(config.DataPath, 1.GB()); 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 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; Name = name;
Token = token; Token = token;
ServerName = serverName; ServerName = serverName;
AdminRoleName = adminRoleName; AdminRoleName = adminRoleName;
AdminChannelName = adminChannelName; AdminChannelName = adminChannelName;
KubeNamespace = kubeNamespace;
} }
public string Name { get; } public string Name { get; }
@ -16,6 +17,7 @@
public string ServerName { get; } public string ServerName { get; }
public string AdminRoleName { get; } public string AdminRoleName { get; }
public string AdminChannelName { get; } public string AdminChannelName { get; }
public string KubeNamespace { get; }
public string? DataPath { get; set; } 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.")] [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"; 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 public string EndpointsPath
{ {
get get

View File

@ -28,7 +28,7 @@ namespace BiblioTech
try try
{ {
var deploy = JsonConvert.DeserializeObject<CodexDeployment>(str); var deploy = JsonConvert.DeserializeObject<CodexDeployment>(str);
if (deploy != null) if (IsDeploymentOk(deploy))
{ {
var targetFile = Path.Combine(Program.Config.EndpointsPath, Guid.NewGuid().ToString().ToLowerInvariant() + ".json"); var targetFile = Path.Combine(Program.Config.EndpointsPath, Guid.NewGuid().ToString().ToLowerInvariant() + ".json");
File.WriteAllText(targetFile, str); File.WriteAllText(targetFile, str);
@ -59,6 +59,17 @@ namespace BiblioTech
return false; 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() private void LoadDeployments()
{ {
var path = Program.Config.EndpointsPath; var path = Program.Config.EndpointsPath;

View File

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

View File

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