77 corev1 "k8s.io/api/core/v1"
88)
99
10- // GetVolumes -
10+ // GetVolumes - returns a list of volumes for the test pod
1111func GetVolumes (
1212 instance * testv1beta1.AnsibleTest ,
1313 logsPVCName string ,
@@ -16,258 +16,69 @@ func GetVolumes(
1616 externalWorkflowCounter int ,
1717) []corev1.Volume {
1818
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
2519 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- },
20+ util .CreateOpenstackConfigMapVolume ("openstack-config" ),
21+ util .CreateOpenstackConfigSecretVolume (),
22+ util .CreateLogsPVCVolume (logsPVCName ),
23+ util .CreateWorkdirVolume (),
24+ util .CreateTmpVolume (),
6725 }
6826
6927 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- },
91- }
92-
93- volumes = append (volumes , keysVolume )
94-
95- 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 )
28+ volumes = util .AppendCACertsVolume (volumes )
10729 }
10830
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- }
31+ volumes = util .AppendSSHKeyVolume (volumes , "compute-ssh-secret" , instance .Spec .ComputeSSHKeySecretName )
32+ volumes = util .AppendSSHKeyVolume (volumes , "workload-ssh-secret" , instance .Spec .WorkloadSSHKeySecretName )
12133
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- }
134-
135- volumes = append (volumes , extraVol )
136- }
34+ volumes = util .AppendExtraMountsVolumes (volumes , instance .Spec .ExtraMounts , svc )
35+ volumes = util .AppendExtraConfigmapsVolumes (volumes , instance .Spec .ExtraConfigmapsMounts , util .ScriptsVolumeDefaultMode )
13736
13837 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- }
38+ volumes = util .AppendExtraConfigmapsVolumes (volumes , * instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts , util .ScriptsVolumeDefaultMode )
15439 }
40+
15541 return volumes
15642}
15743
158- // GetVolumeMounts -
44+ // GetVolumeMounts - returns a list of volume mounts for the test container
15945func GetVolumeMounts (
16046 mountCerts bool ,
16147 svc []storage.PropagationType ,
16248 instance * testv1beta1.AnsibleTest ,
16349 externalWorkflowCounter int ,
16450) []corev1.VolumeMount {
16551 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- },
52+ util .CreateVolumeMount (util .TestOperatorEphemeralVolumeNameWorkdir , "/var/lib/ansible" , false ),
53+ util .CreateVolumeMount (util .TestOperatorEphemeralVolumeNameTmp , "/tmp" , false ),
54+ util .CreateVolumeMount (util .VolumeNameTestOperatorLogs , "/var/lib/AnsibleTests/external_files" , false ),
55+ util .CreateOpenstackConfigVolumeMount ("/etc/openstack/clouds.yaml" ),
56+ util .CreateOpenstackConfigVolumeMount ("/var/lib/ansible/.config/openstack/clouds.yaml" ),
57+ util .CreateOpenstackConfigSecretVolumeMount ("/var/lib/ansible/.config/openstack/secure.yaml" ),
19958 }
20059
20160 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 )
61+ volumeMounts = append (volumeMounts ,
62+ util .CreateCACertVolumeMount ("/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" ),
63+ util .CreateCACertVolumeMount ("/etc/pki/tls/certs/ca-bundle.trust.crt" ),
64+ )
21965 }
22066
22167 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 )
68+ volumeMounts = append (volumeMounts ,
69+ util .CreateVolumeMountWithSubPath ("workload-ssh-secret" , "/var/lib/ansible/test_keypair.key" , "ssh-privatekey" , true ),
70+ )
23071 }
23172
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 )
73+ volumeMounts = append (volumeMounts ,
74+ util .CreateVolumeMountWithSubPath ("compute-ssh-secret" , "/var/lib/ansible/.ssh/compute_id" , "ssh-privatekey" , true ),
75+ )
24076
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 )
257- }
77+ volumeMounts = util .AppendExtraMountsVolumeMounts (volumeMounts , instance .Spec .ExtraMounts , svc )
78+ volumeMounts = util .AppendExtraConfigmapsVolumeMounts (volumeMounts , instance .Spec .ExtraConfigmapsMounts )
25879
25980 if len (instance .Spec .Workflow ) > 0 && instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts != nil {
260- for _ , vol := range * instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts {
261-
262- extraConfigmapsMounts := corev1.VolumeMount {
263- Name : vol .Name ,
264- MountPath : vol .MountPath ,
265- SubPath : vol .SubPath ,
266- ReadOnly : true ,
267- }
268-
269- volumeMounts = append (volumeMounts , extraConfigmapsMounts )
270- }
81+ volumeMounts = util .AppendExtraConfigmapsVolumeMounts (volumeMounts , * instance .Spec .Workflow [externalWorkflowCounter ].ExtraConfigmapsMounts )
27182 }
27283
27384 return volumeMounts
0 commit comments