Skip to content

Commit 5b23e74

Browse files
authored
feat: Add Pod Labels as a configurable option (#1115)
1 parent 001f747 commit 5b23e74

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

source/Octopus.Tentacle/Kubernetes/KubernetesConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public static class KubernetesConfig
6868
public static readonly string PodAnnotationsJsonVariableName = $"{EnvVarPrefix}__PODANNOTATIONSJSON";
6969
public static string? PodAnnotationsJson => Environment.GetEnvironmentVariable(PodAnnotationsJsonVariableName);
7070

71+
public static readonly string PodLabelsJsonVariableName = $"{EnvVarPrefix}__PODLABELSJSON";
72+
public static string? PodLabelsJson => Environment.GetEnvironmentVariable(PodLabelsJsonVariableName);
73+
7174
public static readonly string TentacleConfigMapNameVariableName = $"{EnvVarPrefix}__TENTACLECONFIGMAPNAME";
7275
public static string TentacleConfigMapName => GetEnvironmentVariableOrDefault(TentacleConfigMapNameVariableName, "tentacle-config");
7376

source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ async Task CreatePod(StartKubernetesScriptCommandV1 command, IScriptWorkspace wo
199199
{
200200
Name = podName,
201201
NamespaceProperty = KubernetesConfig.Namespace,
202-
Labels = new Dictionary<string, string>
203-
{
204-
["octopus.com/serverTaskId"] = command.TaskId,
205-
["octopus.com/scriptTicketId"] = command.ScriptTicket.TaskId
206-
},
202+
Labels = GetScriptPodLabels(tentacleScriptLog, command),
207203
Annotations = ParseScriptPodAnnotations(tentacleScriptLog)
208204
},
209205
Spec = new V1PodSpec
@@ -419,6 +415,29 @@ V1Affinity ParseScriptPodAffinity(InMemoryTentacleScriptLog tentacleScriptLog)
419415
KubernetesConfig.PodAnnotationsJsonVariableName,
420416
"pod annotations");
421417

418+
Dictionary<string, string>? GetScriptPodLabels(InMemoryTentacleScriptLog tentacleScriptLog, StartKubernetesScriptCommandV1 command)
419+
{
420+
var labels = new Dictionary<string, string>
421+
{
422+
["octopus.com/serverTaskId"] = command.TaskId,
423+
["octopus.com/scriptTicketId"] = command.ScriptTicket.TaskId
424+
};
425+
var extraLabels = ParseScriptPodJson<Dictionary<string, string>>(
426+
tentacleScriptLog,
427+
KubernetesConfig.PodLabelsJson,
428+
KubernetesConfig.PodLabelsJsonVariableName,
429+
"pod labels");
430+
431+
if (extraLabels != null)
432+
{
433+
labels.AddRange(extraLabels);
434+
}
435+
436+
return labels;
437+
}
438+
439+
440+
422441
[return: NotNullIfNotNull("defaultValue")]
423442
T? ParseScriptPodJson<T>(InMemoryTentacleScriptLog tentacleScriptLog, string? json, string envVarName, string description, T? defaultValue = null) where T : class
424443
{

0 commit comments

Comments
 (0)