9
9
using Octopus . Tentacle . Core . Diagnostics ;
10
10
using Octopus . Tentacle . Core . Services . Scripts . Locking ;
11
11
using Octopus . Tentacle . Kubernetes . Crypto ;
12
- using Octopus . Tentacle . Scripts ;
13
12
14
13
namespace Octopus . Tentacle . Kubernetes
15
14
{
@@ -25,6 +24,7 @@ public KubernetesRawScriptPodCreator(
25
24
IKubernetesPodService podService ,
26
25
IKubernetesPodMonitor podMonitor ,
27
26
IKubernetesSecretService secretService ,
27
+ IKubernetesCustomResourceService customResourceService ,
28
28
IKubernetesPodContainerResolver containerResolver ,
29
29
IApplicationInstanceSelector appInstanceSelector ,
30
30
ISystemLog log ,
@@ -33,31 +33,34 @@ public KubernetesRawScriptPodCreator(
33
33
KubernetesPhysicalFileSystem kubernetesPhysicalFileSystem ,
34
34
IScriptPodLogEncryptionKeyProvider scriptPodLogEncryptionKeyProvider ,
35
35
ScriptIsolationMutex scriptIsolationMutex )
36
- : base ( podService , podMonitor , secretService , containerResolver , appInstanceSelector , log , scriptLogProvider , homeConfiguration , kubernetesPhysicalFileSystem , scriptPodLogEncryptionKeyProvider , scriptIsolationMutex )
36
+ : base ( podService , podMonitor , secretService , customResourceService , containerResolver , appInstanceSelector , log , scriptLogProvider , homeConfiguration , kubernetesPhysicalFileSystem , scriptPodLogEncryptionKeyProvider , scriptIsolationMutex )
37
37
{
38
38
this . containerResolver = containerResolver ;
39
39
}
40
40
41
- protected override async Task < IList < V1Container > > CreateInitContainers ( StartKubernetesScriptCommandV1 command , string podName , string homeDir , string workspacePath , InMemoryTentacleScriptLog tentacleScriptLog )
41
+ protected override async Task < IList < V1Container > > CreateInitContainers ( StartKubernetesScriptCommandV1 command , string podName , string homeDir , string workspacePath , InMemoryTentacleScriptLog tentacleScriptLog , V1Container ? containerSpec )
42
42
{
43
- var container = new V1Container
44
- {
45
- Name = $ "{ podName } -init",
46
- Image = command . PodImageConfiguration ? . Image ?? await containerResolver . GetContainerImageForCluster ( ) ,
47
- ImagePullPolicy = KubernetesConfig . ScriptPodPullPolicy ,
48
- Command = new List < string > { "sh" , "-c" , GetInitExecutionScript ( "/nfs-mount" , homeDir , workspacePath ) } ,
49
- VolumeMounts = new List < V1VolumeMount > { new ( "/nfs-mount" , "init-nfs-volume" ) , new ( homeDir , "tentacle-home" ) } ,
50
- Resources = GetScriptPodResourceRequirements ( tentacleScriptLog )
51
- } ;
43
+ // Deep clone the container spec to avoid modifying the original
44
+ var container = containerSpec . Clone ( ) ??
45
+ new V1Container
46
+ {
47
+ Resources = GetScriptPodResourceRequirements ( tentacleScriptLog )
48
+ } ;
49
+
50
+ container . Name = $ "{ podName } -init";
51
+ container . Image = command . PodImageConfiguration ? . Image ?? await containerResolver . GetContainerImageForCluster ( ) ;
52
+ container . ImagePullPolicy = KubernetesConfig . ScriptPodPullPolicy ;
53
+ container . Command = new List < string > { "sh" , "-c" , GetInitExecutionScript ( "/nfs-mount" , homeDir , workspacePath ) } ;
54
+ container . VolumeMounts = Merge ( container . VolumeMounts , new [ ] { new V1VolumeMount ( "/nfs-mount" , "init-nfs-volume" ) , new V1VolumeMount ( homeDir , "tentacle-home" ) } ) ;
52
55
53
56
return new List < V1Container > { container } ;
54
57
}
55
-
56
- protected override async Task < IList < V1Container > > CreateScriptContainers ( StartKubernetesScriptCommandV1 command , string podName , string scriptName , string homeDir , string workspacePath , string [ ] ? scriptArguments , InMemoryTentacleScriptLog tentacleScriptLog )
58
+
59
+ protected override async Task < IList < V1Container > > CreateScriptContainers ( StartKubernetesScriptCommandV1 command , string podName , string scriptName , string homeDir , string workspacePath , string [ ] ? scriptArguments , InMemoryTentacleScriptLog tentacleScriptLog , ScriptPodTemplateSpec ? spec )
57
60
{
58
61
return new List < V1Container >
59
62
{
60
- await CreateScriptContainer ( command , podName , scriptName , homeDir , workspacePath , scriptArguments , tentacleScriptLog )
63
+ await CreateScriptContainer ( command , podName , scriptName , homeDir , workspacePath , scriptArguments , tentacleScriptLog , spec ? . ScriptContainerSpec )
61
64
} ;
62
65
}
63
66
@@ -82,7 +85,7 @@ protected override IList<V1Volume> CreateVolumes(StartKubernetesScriptCommandV1
82
85
} ;
83
86
}
84
87
85
- string GetInitExecutionScript ( string nfsVolumeDirectory , string homeDir , string workspacePath )
88
+ static string GetInitExecutionScript ( string nfsVolumeDirectory , string homeDir , string workspacePath )
86
89
{
87
90
var nfsWorkspacePath = Path . Combine ( nfsVolumeDirectory , workspacePath ) ;
88
91
var homeWorkspacePath = Path . Combine ( homeDir , workspacePath ) ;
0 commit comments