From 118ba20927307ff871def3ece27a4399a23c49df Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Tue, 26 Nov 2024 14:00:40 +1100 Subject: [PATCH] extract agent upgrade secret volume creation --- .../KubernetesRawScriptPodCreator.cs | 18 +---------- .../Kubernetes/KubernetesScriptPodCreator.cs | 32 ++++++++++++------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/source/Octopus.Tentacle/Kubernetes/KubernetesRawScriptPodCreator.cs b/source/Octopus.Tentacle/Kubernetes/KubernetesRawScriptPodCreator.cs index 45725b02a..1b63a9b01 100644 --- a/source/Octopus.Tentacle/Kubernetes/KubernetesRawScriptPodCreator.cs +++ b/source/Octopus.Tentacle/Kubernetes/KubernetesRawScriptPodCreator.cs @@ -81,23 +81,7 @@ protected override IList CreateVolumes(StartKubernetesScriptCommandV1 ClaimName = KubernetesConfig.PodVolumeClaimName } }, - new() - { - Name = "agent-upgrade", - Secret = new V1SecretVolumeSource - { - SecretName = "agent-upgrade-secret", - Items = new List() - { - new() - { - Key = ".dockerconfigjson", - Path = "config.json" - } - }, - Optional = true, - }, - }, + CreateAgentUpgradeSecretVolume(), }; } diff --git a/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs b/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs index 33e9f61af..9c6dc95f2 100644 --- a/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs +++ b/source/Octopus.Tentacle/Kubernetes/KubernetesScriptPodCreator.cs @@ -182,6 +182,9 @@ async Task CreatePod(StartKubernetesScriptCommandV1 command, IScriptWorkspace wo .Select(secretName => new V1LocalObjectReference(secretName)) .ToList(); + var volumes = CreateVolumes(command); + volumes.Append(CreateAgentUpgradeSecretVolume()); + var pod = new V1Pod { Metadata = new V1ObjectMeta @@ -241,22 +244,27 @@ protected virtual IList CreateVolumes(StartKubernetesScriptCommandV1 c ClaimName = KubernetesConfig.PodVolumeClaimName } }, - new() + CreateAgentUpgradeSecretVolume(), + }; + } + + protected V1Volume CreateAgentUpgradeSecretVolume() + { + return new() + { + Name = "agent-upgrade", + Secret = new V1SecretVolumeSource { - Name = "agent-upgrade", - Secret = new V1SecretVolumeSource + SecretName = "agent-upgrade-secret", + Items = new List() { - SecretName = "agent-upgrade-secret", - Items = new List() + new() { - new() - { - Key = ".dockerconfigjson", - Path = "config.json" - } - }, - Optional = true, + Key = ".dockerconfigjson", + Path = "config.json" + } }, + Optional = true, }, }; }