Skip to content

Commit 74f7140

Browse files
seansonAPErebus
andauthored
Adds support for ScriptPods having configurable Annotations (#1071)
* Adds support for ScriptPods having configurable Annotations (#1070) --------- Co-authored-by: Alastair Pitts <[email protected]>
1 parent 1855b05 commit 74f7140

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Currently we can only debug netcore apps running in WSL from VSCode, Visual Stud
101101
```
102102
## Debugging the Kubernetes Agent Tentacle
103103

104-
The Kubernetes Agent Tentacle is a bit more complex to debug, as it normally runs inside a Kubernetes Pod. To debug it locally, you can run the `setup-k8s-agent-for-local-debug.sh` script in the root of this repo which will guide you through the process of installing a specially configured kind cluster, deploying the agent to it and then scaling back the installed agent so you can run a local copy to take it's place.
104+
The Kubernetes Agent Tentacle is more complex to debug, as it normally runs inside a Kubernetes Pod. To debug it locally, you can run the `setup-k8s-agent-for-local-debug.sh` script in the root of this repo which will guide you through the process of installing a specially configured kind cluster, deploying the agent to it and then scaling back the installed agent so you can run a local copy to take it's place.
105105

106106
NOTE: This script has only been tested on MacOS so far and requires Docker Desktop, Kubectl, Go CLI and Kind to be installed. It is also only for the Kubernetes Agent Tentacle running as a Deployment Target, not as a Worker.
107107

source/Octopus.Tentacle/Kubernetes/KubernetesConfig.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public static class KubernetesConfig
6464

6565
public static readonly string PodSecurityContextJsonVariableName = $"{EnvVarPrefix}__PODSECURITYCONTEXTJSON";
6666
public static string? PodSecurityContextJson => Environment.GetEnvironmentVariable(PodSecurityContextJsonVariableName);
67-
67+
68+
public static readonly string PodAnnotationsJsonVariableName = $"{EnvVarPrefix}__PODANNOTATIONSJSON";
69+
public static string? PodAnnotationsJson => Environment.GetEnvironmentVariable(PodAnnotationsJsonVariableName);
70+
6871
public static readonly string TentacleConfigMapNameVariableName = $"{EnvVarPrefix}__TENTACLECONFIGMAPNAME";
6972
public static string TentacleConfigMapName => GetEnvironmentVariableOrDefault(TentacleConfigMapNameVariableName, "tentacle-config");
7073

@@ -109,7 +112,7 @@ public static string[] ServerCommsAddresses
109112
static string GetRequiredEnvVar(string variable, string errorMessage)
110113
=> Environment.GetEnvironmentVariable(variable)
111114
?? throw new InvalidOperationException($"{errorMessage} The environment variable '{variable}' must be defined with a non-null value.");
112-
115+
113116
static string GetEnvironmentVariableOrDefault(string variable, string defaultValue)
114117
=> Environment.GetEnvironmentVariable(variable) ?? defaultValue;
115118
}

source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task CreatePod(StartKubernetesScriptCommandV1 command, IScriptWorks
8080
{
8181
//Write the log encryption key here
8282
await scriptPodLogEncryptionKeyProvider.GenerateAndWriteEncryptionKeyfileToWorkspace(command.ScriptTicket, cancellationToken);
83-
83+
8484
//Possibly create the image pull secret name
8585
var imagePullSecretName = await CreateImagePullSecret(command, cancellationToken);
8686

@@ -188,7 +188,7 @@ async Task CreatePod(StartKubernetesScriptCommandV1 command, IScriptWorkspace wo
188188
.WhereNotNull()
189189
.Select(secretName => new V1LocalObjectReference(secretName))
190190
.ToList();
191-
191+
192192
var pod = new V1Pod
193193
{
194194
Metadata = new V1ObjectMeta
@@ -199,7 +199,8 @@ async Task CreatePod(StartKubernetesScriptCommandV1 command, IScriptWorkspace wo
199199
{
200200
["octopus.com/serverTaskId"] = command.TaskId,
201201
["octopus.com/scriptTicketId"] = command.ScriptTicket.TaskId
202-
}
202+
},
203+
Annotations = ParseScriptPodAnnotations(tentacleScriptLog)
203204
},
204205
Spec = new V1PodSpec
205206
{
@@ -406,6 +407,13 @@ V1Affinity ParseScriptPodAffinity(InMemoryTentacleScriptLog tentacleScriptLog)
406407
KubernetesConfig.PodSecurityContextJsonVariableName,
407408
"pod security context");
408409

410+
Dictionary<string, string>? ParseScriptPodAnnotations(InMemoryTentacleScriptLog tentacleScriptLog)
411+
=> ParseScriptPodJson<Dictionary<string, string>>(
412+
tentacleScriptLog,
413+
KubernetesConfig.PodAnnotationsJson,
414+
KubernetesConfig.PodAnnotationsJsonVariableName,
415+
"pod annotations");
416+
409417
[return: NotNullIfNotNull("defaultValue")]
410418
T? ParseScriptPodJson<T>(InMemoryTentacleScriptLog tentacleScriptLog, string? json, string envVarName, string description, T? defaultValue = null) where T : class
411419
{

0 commit comments

Comments
 (0)