From e0bd223cadd610a31f9e6494acedd93493043fd5 Mon Sep 17 00:00:00 2001 From: Eddy Moulton Date: Thu, 18 Dec 2025 11:21:22 +1100 Subject: [PATCH] Add project group to k8a auth ctx --- .../KubernetesAgentAuthContext.cs | 10 +++++++++- .../Kubernetes/KubernetesScriptPodCreator.cs | 10 ++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/source/Octopus.Tentacle.Contracts/KubernetesAgentAuthContext.cs b/source/Octopus.Tentacle.Contracts/KubernetesAgentAuthContext.cs index a19b29e57..ffc9cf701 100644 --- a/source/Octopus.Tentacle.Contracts/KubernetesAgentAuthContext.cs +++ b/source/Octopus.Tentacle.Contracts/KubernetesAgentAuthContext.cs @@ -4,10 +4,17 @@ namespace Octopus.Tentacle.Contracts { public class KubernetesAgentAuthContext { - public KubernetesAgentAuthContext(string spaceSlug, string projectSlug, string environmentSlug, string? tenantSlug, string stepSlug) + public KubernetesAgentAuthContext( + string spaceSlug, + string projectSlug, + string? projectGroupSlug, + string environmentSlug, + string? tenantSlug, + string stepSlug) { SpaceSlug = spaceSlug; ProjectSlug = projectSlug; + ProjectGroupSlug = projectGroupSlug; EnvironmentSlug = environmentSlug; TenantSlug = tenantSlug; StepSlug = stepSlug; @@ -15,6 +22,7 @@ public KubernetesAgentAuthContext(string spaceSlug, string projectSlug, string e public string SpaceSlug { get; } public string ProjectSlug { get; } + public string? ProjectGroupSlug { get; } // This is only nullable for backwards compatibility public string EnvironmentSlug { get; } public string? TenantSlug { get; } public string StepSlug { get; } diff --git a/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs b/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs index 9bada0fa1..cba8ce96f 100644 --- a/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs +++ b/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs @@ -12,7 +12,6 @@ using Newtonsoft.Json; using Octopus.Tentacle.Configuration; using Octopus.Tentacle.Configuration.Instances; -using Octopus.Tentacle.Contracts; using Octopus.Tentacle.Contracts.KubernetesScriptServiceV1; using Octopus.Tentacle.Core.Diagnostics; using Octopus.Tentacle.Core.Services.Scripts.Locking; @@ -434,7 +433,7 @@ V1Affinity ParseScriptPodAffinity(InMemoryTentacleScriptLog tentacleScriptLog) KubernetesConfig.PodAnnotationsJsonVariableName, "pod annotations"); - Dictionary? GetScriptPodAnnotations(InMemoryTentacleScriptLog tentacleScriptLog, StartKubernetesScriptCommandV1 command) + Dictionary GetScriptPodAnnotations(InMemoryTentacleScriptLog tentacleScriptLog, StartKubernetesScriptCommandV1 command) { var annotations = ParseScriptPodAnnotations(tentacleScriptLog) ?? new Dictionary(); annotations.AddRange(GetAuthContext(command)); @@ -478,6 +477,13 @@ static Dictionary GetAuthContext(StartKubernetesScriptCommandV1 ? HashValue(command.AuthContext.ProjectSlug) : command.AuthContext.ProjectSlug; + if (command.AuthContext.ProjectGroupSlug is not null) + { + dict[$"{KubernetesConfig.AgentLabelNamespace}/project-group"] = hash + ? HashValue(command.AuthContext.ProjectGroupSlug) + : command.AuthContext.ProjectGroupSlug; + } + dict[$"{KubernetesConfig.AgentLabelNamespace}/environment"] = hash ? HashValue(command.AuthContext.EnvironmentSlug) : command.AuthContext.EnvironmentSlug;