99using Octopus . Tentacle . Core . Diagnostics ;
1010using Octopus . Tentacle . Core . Services . Scripts . Locking ;
1111using Octopus . Tentacle . Kubernetes . Crypto ;
12- using Octopus . Tentacle . Scripts ;
1312
1413namespace Octopus . Tentacle . Kubernetes
1514{
@@ -25,6 +24,7 @@ public KubernetesRawScriptPodCreator(
2524 IKubernetesPodService podService ,
2625 IKubernetesPodMonitor podMonitor ,
2726 IKubernetesSecretService secretService ,
27+ IKubernetesCustomResourceService customResourceService ,
2828 IKubernetesPodContainerResolver containerResolver ,
2929 IApplicationInstanceSelector appInstanceSelector ,
3030 ISystemLog log ,
@@ -33,31 +33,34 @@ public KubernetesRawScriptPodCreator(
3333 KubernetesPhysicalFileSystem kubernetesPhysicalFileSystem ,
3434 IScriptPodLogEncryptionKeyProvider scriptPodLogEncryptionKeyProvider ,
3535 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 )
3737 {
3838 this . containerResolver = containerResolver ;
3939 }
4040
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 )
4242 {
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" ) } ) ;
5255
5356 return new List < V1Container > { container } ;
5457 }
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 )
5760 {
5861 return new List < V1Container >
5962 {
60- await CreateScriptContainer ( command , podName , scriptName , homeDir , workspacePath , scriptArguments , tentacleScriptLog )
63+ await CreateScriptContainer ( command , podName , scriptName , homeDir , workspacePath , scriptArguments , tentacleScriptLog , spec ? . ScriptContainerSpec )
6164 } ;
6265 }
6366
@@ -82,7 +85,7 @@ protected override IList<V1Volume> CreateVolumes(StartKubernetesScriptCommandV1
8285 } ;
8386 }
8487
85- string GetInitExecutionScript ( string nfsVolumeDirectory , string homeDir , string workspacePath )
88+ static string GetInitExecutionScript ( string nfsVolumeDirectory , string homeDir , string workspacePath )
8689 {
8790 var nfsWorkspacePath = Path . Combine ( nfsVolumeDirectory , workspacePath ) ;
8891 var homeWorkspacePath = Path . Combine ( homeDir , workspacePath ) ;
0 commit comments