@@ -7,7 +7,12 @@ import (
77 corev1 "k8s.io/api/core/v1"
88)
99
10- // GetVolumes -
10+ const (
11+ computeName = "compute-ssh-secret"
12+ workloadName = "workload-ssh-secret"
13+ )
14+
15+ // GetVolumes - returns a list of volumes for the test pod
1116func GetVolumes (
1217 instance * testv1beta1.AnsibleTest ,
1318 logsPVCName string ,
@@ -16,258 +21,74 @@ func GetVolumes(
1621 externalWorkflowCounter int ,
1722) []corev1.Volume {
1823
19- var scriptsVolumeConfidentialMode int32 = 0420
20- var tlsCertificateMode int32 = 0444
21- var privateKeyMode int32 = 0600
22- var publicInfoMode int32 = 0744
23-
24- //source_type := corev1.HostPathDirectoryOrCreate
2524 volumes := []corev1.Volume {
26- {
27- Name : "openstack-config" ,
28- VolumeSource : corev1.VolumeSource {
29- ConfigMap : & corev1.ConfigMapVolumeSource {
30- DefaultMode : & scriptsVolumeConfidentialMode ,
31- LocalObjectReference : corev1.LocalObjectReference {
32- Name : "openstack-config" ,
33- },
34- },
35- },
36- },
37- {
38- Name : "openstack-config-secret" ,
39- VolumeSource : corev1.VolumeSource {
40- Secret : & corev1.SecretVolumeSource {
41- DefaultMode : & tlsCertificateMode ,
42- SecretName : "openstack-config-secret" ,
43- },
44- },
45- },
46- {
47- Name : "test-operator-logs" ,
48- VolumeSource : corev1.VolumeSource {
49- PersistentVolumeClaim : & corev1.PersistentVolumeClaimVolumeSource {
50- ClaimName : logsPVCName ,
51- ReadOnly : false ,
52- },
53- },
54- },
55- {
56- Name : util .TestOperatorEphemeralVolumeNameWorkdir ,
57- VolumeSource : corev1.VolumeSource {
58- EmptyDir : & corev1.EmptyDirVolumeSource {},
59- },
60- },
61- {
62- Name : util .TestOperatorEphemeralVolumeNameTmp ,
63- VolumeSource : corev1.VolumeSource {
64- EmptyDir : & corev1.EmptyDirVolumeSource {},
65- },
66- },
25+ util .CreateOpenstackConfigMapVolume ("openstack-config" ),
26+ util .CreateOpenstackConfigSecretVolume (),
27+ util .CreateLogsPVCVolume (logsPVCName ),
28+ util .CreateWorkdirVolume (),
29+ util .CreateTmpVolume (),
6730 }
6831
6932 if mountCerts {
70- caCertsVolume := corev1.Volume {
71- Name : "ca-certs" ,
72- VolumeSource : corev1.VolumeSource {
73- Secret : & corev1.SecretVolumeSource {
74- DefaultMode : & scriptsVolumeConfidentialMode ,
75- SecretName : "combined-ca-bundle" ,
76- },
77- },
78- }
79-
80- volumes = append (volumes , caCertsVolume )
81- }
82-
83- keysVolume := corev1.Volume {
84- Name : "compute-ssh-secret" ,
85- VolumeSource : corev1.VolumeSource {
86- Secret : & corev1.SecretVolumeSource {
87- SecretName : instance .Spec .ComputeSSHKeySecretName ,
88- DefaultMode : & privateKeyMode ,
89- },
90- },
33+ volumes = util .AppendCACertsVolume (volumes )
9134 }
9235
93- volumes = append (volumes , keysVolume )
94-
9536 if instance .Spec .WorkloadSSHKeySecretName != "" {
96- keysVolume = corev1.Volume {
97- Name : "workload-ssh-secret" ,
98- VolumeSource : corev1.VolumeSource {
99- Secret : & corev1.SecretVolumeSource {
100- SecretName : instance .Spec .WorkloadSSHKeySecretName ,
101- DefaultMode : & privateKeyMode ,
102- },
103- },
104- }
105-
106- volumes = append (volumes , keysVolume )
37+ volumes = util .AppendSSHKeyVolume (volumes , workloadName , instance .Spec .WorkloadSSHKeySecretName )
10738 }
10839
109- for _ , exv := range instance .Spec .ExtraMounts {
110- for _ , vol := range exv .Propagate (svc ) {
111- for _ , v := range vol .Volumes {
112- volumeSource , _ := v .ToCoreVolumeSource ()
113- convertedVolume := corev1.Volume {
114- Name : v .Name ,
115- VolumeSource : * volumeSource ,
116- }
117- volumes = append (volumes , convertedVolume )
118- }
119- }
120- }
40+ volumes = util .AppendSSHKeyVolume (volumes , computeName , instance .Spec .ComputeSSHKeySecretName )
12141
122- for _ , vol := range instance .Spec .ExtraConfigmapsMounts {
123- extraVol := corev1.Volume {
124- Name : vol .Name ,
125- VolumeSource : corev1.VolumeSource {
126- ConfigMap : & corev1.ConfigMapVolumeSource {
127- DefaultMode : & publicInfoMode ,
128- LocalObjectReference : corev1.LocalObjectReference {
129- Name : vol .Name ,
130- },
131- },
132- },
133- }
42+ volumes = util .AppendExtraMountsVolumes (volumes , instance .Spec .ExtraMounts , svc )
43+ volumes = util .AppendExtraConfigmapsVolumes (volumes , instance .Spec .ExtraConfigmapsMounts , util .ScriptsVolumeDefaultMode )
13444
135- volumes = append (volumes , extraVol )
45+ cmMounts := instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts
46+ if len (instance .Spec .Workflow ) > 0 && cmMounts != nil {
47+ volumes = util .AppendExtraConfigmapsVolumes (volumes , * cmMounts , util .ScriptsVolumeDefaultMode )
13648 }
13749
138- if len (instance .Spec .Workflow ) > 0 && instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts != nil {
139- for _ , vol := range * instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts {
140- extraWorkflowVol := corev1.Volume {
141- Name : vol .Name ,
142- VolumeSource : corev1.VolumeSource {
143- ConfigMap : & corev1.ConfigMapVolumeSource {
144- DefaultMode : & publicInfoMode ,
145- LocalObjectReference : corev1.LocalObjectReference {
146- Name : vol .Name ,
147- },
148- },
149- },
150- }
151-
152- volumes = append (volumes , extraWorkflowVol )
153- }
154- }
15550 return volumes
15651}
15752
158- // GetVolumeMounts -
53+ // GetVolumeMounts - returns a list of volume mounts for the test container
15954func GetVolumeMounts (
16055 mountCerts bool ,
16156 svc []storage.PropagationType ,
16257 instance * testv1beta1.AnsibleTest ,
16358 externalWorkflowCounter int ,
16459) []corev1.VolumeMount {
16560 volumeMounts := []corev1.VolumeMount {
166- {
167- Name : util .TestOperatorEphemeralVolumeNameWorkdir ,
168- MountPath : "/var/lib/ansible" ,
169- ReadOnly : false ,
170- },
171- {
172- Name : util .TestOperatorEphemeralVolumeNameTmp ,
173- MountPath : "/tmp" ,
174- ReadOnly : false ,
175- },
176- {
177- Name : "test-operator-logs" ,
178- MountPath : "/var/lib/AnsibleTests/external_files" ,
179- ReadOnly : false ,
180- },
181- {
182- Name : "openstack-config" ,
183- MountPath : "/etc/openstack/clouds.yaml" ,
184- SubPath : "clouds.yaml" ,
185- ReadOnly : true ,
186- },
187- {
188- Name : "openstack-config" ,
189- MountPath : "/var/lib/ansible/.config/openstack/clouds.yaml" ,
190- SubPath : "clouds.yaml" ,
191- ReadOnly : true ,
192- },
193- {
194- Name : "openstack-config-secret" ,
195- MountPath : "/var/lib/ansible/.config/openstack/secure.yaml" ,
196- ReadOnly : false ,
197- SubPath : "secure.yaml" ,
198- },
61+ util .CreateVolumeMount (util .TestOperatorEphemeralVolumeNameWorkdir , "/var/lib/ansible" , false ),
62+ util .CreateVolumeMount (util .TestOperatorEphemeralVolumeNameTmp , "/tmp" , false ),
63+ util .CreateVolumeMount (util .TestOperatorLogsVolumeName , "/var/lib/AnsibleTests/external_files" , false ),
64+ util .CreateOpenstackConfigVolumeMount ("/etc/openstack/clouds.yaml" ),
65+ util .CreateOpenstackConfigVolumeMount ("/var/lib/ansible/.config/openstack/clouds.yaml" ),
66+ util .CreateOpenstackConfigSecretVolumeMount ("/var/lib/ansible/.config/openstack/secure.yaml" ),
19967 }
20068
20169 if mountCerts {
202- caCertVolumeMount := corev1.VolumeMount {
203- Name : "ca-certs" ,
204- MountPath : "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" ,
205- ReadOnly : true ,
206- SubPath : "tls-ca-bundle.pem" ,
207- }
208-
209- volumeMounts = append (volumeMounts , caCertVolumeMount )
210-
211- caCertVolumeMount = corev1.VolumeMount {
212- Name : "ca-certs" ,
213- MountPath : "/etc/pki/tls/certs/ca-bundle.trust.crt" ,
214- ReadOnly : true ,
215- SubPath : "tls-ca-bundle.pem" ,
216- }
217-
218- volumeMounts = append (volumeMounts , caCertVolumeMount )
70+ volumeMounts = append (volumeMounts ,
71+ util .CreateCACertVolumeMount ("/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" ),
72+ util .CreateCACertVolumeMount ("/etc/pki/tls/certs/ca-bundle.trust.crt" ),
73+ )
21974 }
22075
22176 if instance .Spec .WorkloadSSHKeySecretName != "" {
222- workloadSSHKeyMount := corev1.VolumeMount {
223- Name : "workload-ssh-secret" ,
224- MountPath : "/var/lib/ansible/test_keypair.key" ,
225- SubPath : "ssh-privatekey" ,
226- ReadOnly : true ,
227- }
228-
229- volumeMounts = append (volumeMounts , workloadSSHKeyMount )
230- }
231-
232- computeSSHKeyMount := corev1.VolumeMount {
233- Name : "compute-ssh-secret" ,
234- MountPath : "/var/lib/ansible/.ssh/compute_id" ,
235- SubPath : "ssh-privatekey" ,
236- ReadOnly : true ,
237- }
238-
239- volumeMounts = append (volumeMounts , computeSSHKeyMount )
240-
241- for _ , exv := range instance .Spec .ExtraMounts {
242- for _ , vol := range exv .Propagate (svc ) {
243- volumeMounts = append (volumeMounts , vol .Mounts ... )
244- }
245- }
246-
247- for _ , vol := range instance .Spec .ExtraConfigmapsMounts {
248-
249- extraConfigmapsMounts := corev1.VolumeMount {
250- Name : vol .Name ,
251- MountPath : vol .MountPath ,
252- SubPath : vol .SubPath ,
253- ReadOnly : true ,
254- }
255-
256- volumeMounts = append (volumeMounts , extraConfigmapsMounts )
77+ volumeMounts = append (volumeMounts ,
78+ util .CreateVolumeMountWithSubPath (workloadName , "/var/lib/ansible/test_keypair.key" , "ssh-privatekey" , true ),
79+ )
25780 }
25881
259- if len (instance .Spec .Workflow ) > 0 && instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts != nil {
260- for _ , vol := range * instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts {
82+ volumeMounts = append (volumeMounts ,
83+ util .CreateVolumeMountWithSubPath (computeName , "/var/lib/ansible/.ssh/compute_id" , "ssh-privatekey" , true ),
84+ )
26185
262- extraConfigmapsMounts := corev1.VolumeMount {
263- Name : vol .Name ,
264- MountPath : vol .MountPath ,
265- SubPath : vol .SubPath ,
266- ReadOnly : true ,
267- }
86+ volumeMounts = util .AppendExtraMountsVolumeMounts (volumeMounts , instance .Spec .ExtraMounts , svc )
87+ volumeMounts = util .AppendExtraConfigmapsVolumeMounts (volumeMounts , instance .Spec .ExtraConfigmapsMounts )
26888
269- volumeMounts = append (volumeMounts , extraConfigmapsMounts )
270- }
89+ cmMounts := instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts
90+ if len (instance .Spec .Workflow ) > 0 && cmMounts != nil {
91+ volumeMounts = util .AppendExtraConfigmapsVolumeMounts (volumeMounts , * cmMounts )
27192 }
27293
27394 return volumeMounts
0 commit comments