@@ -22,15 +22,12 @@ import (
22
22
"fmt"
23
23
"strconv"
24
24
25
- "reflect"
26
-
27
25
"github.com/go-logr/logr"
28
26
"github.com/openstack-k8s-operators/lib-common/modules/common"
29
27
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
30
28
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
31
29
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
32
30
testv1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
33
- v1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
34
31
"github.com/openstack-k8s-operators/test-operator/pkg/ansibletest"
35
32
corev1 "k8s.io/api/core/v1"
36
33
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
@@ -129,6 +126,9 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
129
126
130
127
workflowLength := len (instance .Spec .Workflow )
131
128
nextAction , nextWorkflowStep , err := r .NextAction (ctx , instance , workflowLength )
129
+ if nextWorkflowStep < workflowLength {
130
+ MergeSections (& instance .Spec , instance .Spec .Workflow [nextWorkflowStep ])
131
+ }
132
132
133
133
switch nextAction {
134
134
case Failure :
@@ -206,32 +206,14 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
206
206
// Create a new pod
207
207
mountCerts := r .CheckSecretExists (ctx , instance , "combined-ca-bundle" )
208
208
podName := r .GetPodName (instance , nextWorkflowStep )
209
- envVars , workflowOverrideParams := r .PrepareAnsibleEnv (instance , nextWorkflowStep )
209
+ envVars , workflowOverrideParams := r .PrepareAnsibleEnv (instance )
210
210
logsPVCName := r .GetPVCLogsName (instance , 0 )
211
211
containerImage , err := r .GetContainerImage (ctx , workflowOverrideParams ["ContainerImage" ], instance )
212
- privileged := r . OverwriteAnsibleWithWorkflow ( instance .Spec , "Privileged" , "pbool" , nextWorkflowStep ).( bool )
212
+ privileged := instance .Spec . Privileged
213
213
if err != nil {
214
214
return ctrl.Result {}, err
215
215
}
216
216
217
- if nextWorkflowStep < len (instance .Spec .Workflow ) {
218
- if instance .Spec .Workflow [nextWorkflowStep ].NodeSelector != nil {
219
- instance .Spec .NodeSelector = * instance .Spec .Workflow [nextWorkflowStep ].NodeSelector
220
- }
221
-
222
- if instance .Spec .Workflow [nextWorkflowStep ].Tolerations != nil {
223
- instance .Spec .Tolerations = * instance .Spec .Workflow [nextWorkflowStep ].Tolerations
224
- }
225
-
226
- if instance .Spec .Workflow [nextWorkflowStep ].SELinuxLevel != nil {
227
- instance .Spec .SELinuxLevel = * instance .Spec .Workflow [nextWorkflowStep ].SELinuxLevel
228
- }
229
-
230
- if instance .Spec .Workflow [nextWorkflowStep ].Resources != nil {
231
- instance .Spec .Resources = * instance .Spec .Workflow [nextWorkflowStep ].Resources
232
- }
233
- }
234
-
235
217
podDef := ansibletest .Pod (
236
218
instance ,
237
219
serviceLabels ,
@@ -284,82 +266,32 @@ func (r *AnsibleTestReconciler) SetupWithManager(mgr ctrl.Manager) error {
284
266
Complete (r )
285
267
}
286
268
287
- func (r * Reconciler ) OverwriteAnsibleWithWorkflow (
288
- instance v1beta1.AnsibleTestSpec ,
289
- sectionName string ,
290
- workflowValueType string ,
291
- workflowStepNum int ,
292
- ) interface {} {
293
- if len (instance .Workflow )- 1 < workflowStepNum {
294
- reflected := reflect .ValueOf (instance )
295
- fieldValue := reflected .FieldByName (sectionName )
296
- return fieldValue .Interface ()
297
- }
298
-
299
- reflected := reflect .ValueOf (instance )
300
- SpecValue := reflected .FieldByName (sectionName ).Interface ()
301
-
302
- reflected = reflect .ValueOf (instance .Workflow [workflowStepNum ])
303
- WorkflowValue := reflected .FieldByName (sectionName ).Interface ()
304
-
305
- if workflowValueType == "pbool" {
306
- if val , ok := WorkflowValue .(* bool ); ok && val != nil {
307
- return * (WorkflowValue .(* bool ))
308
- }
309
- return SpecValue .(bool )
310
- } else if workflowValueType == "puint8" {
311
- if val , ok := WorkflowValue .(* uint8 ); ok && val != nil {
312
- return * (WorkflowValue .(* uint8 ))
313
- }
314
- return SpecValue
315
- } else if workflowValueType == "string" {
316
- if val , ok := WorkflowValue .(string ); ok && val != "" {
317
- return WorkflowValue
318
- }
319
- return SpecValue
320
- }
321
-
322
- return nil
323
- }
324
-
325
269
// This function prepares env variables for a single workflow step.
326
270
func (r * AnsibleTestReconciler ) PrepareAnsibleEnv (
327
271
instance * testv1beta1.AnsibleTest ,
328
- step int ,
329
272
) (map [string ]env.Setter , map [string ]string ) {
330
273
// Prepare env vars
331
274
envVars := make (map [string ]env.Setter )
332
275
workflowOverrideParams := make (map [string ]string )
333
276
334
277
// volumes workflow override
335
- workflowOverrideParams ["WorkloadSSHKeySecretName" ] = r . OverwriteAnsibleWithWorkflow ( instance .Spec , "WorkloadSSHKeySecretName" , "string" , step ).( string )
336
- workflowOverrideParams ["ComputesSSHKeySecretName" ] = r . OverwriteAnsibleWithWorkflow ( instance .Spec , "ComputesSSHKeySecretName" , "string" , step ).( string )
337
- workflowOverrideParams ["ContainerImage" ] = r . OverwriteAnsibleWithWorkflow ( instance .Spec , "ContainerImage" , "string" , step ).( string )
278
+ workflowOverrideParams ["WorkloadSSHKeySecretName" ] = instance .Spec . WorkloadSSHKeySecretName
279
+ workflowOverrideParams ["ComputesSSHKeySecretName" ] = instance .Spec . ComputesSSHKeySecretName
280
+ workflowOverrideParams ["ContainerImage" ] = instance .Spec . ContainerImage
338
281
339
282
// bool
340
- debug := r . OverwriteAnsibleWithWorkflow ( instance .Spec , "Debug" , "pbool" , step ).( bool )
283
+ debug := instance .Spec . Debug
341
284
if debug {
342
285
envVars ["POD_DEBUG" ] = env .SetValue ("true" )
343
286
}
344
287
345
288
// strings
346
- extraVars := r .OverwriteAnsibleWithWorkflow (instance .Spec , "AnsibleExtraVars" , "string" , step ).(string )
347
- envVars ["POD_ANSIBLE_EXTRA_VARS" ] = env .SetValue (extraVars )
348
-
349
- extraVarsFile := r .OverwriteAnsibleWithWorkflow (instance .Spec , "AnsibleVarFiles" , "string" , step ).(string )
350
- envVars ["POD_ANSIBLE_FILE_EXTRA_VARS" ] = env .SetValue (extraVarsFile )
351
-
352
- inventory := r .OverwriteAnsibleWithWorkflow (instance .Spec , "AnsibleInventory" , "string" , step ).(string )
353
- envVars ["POD_ANSIBLE_INVENTORY" ] = env .SetValue (inventory )
354
-
355
- gitRepo := r .OverwriteAnsibleWithWorkflow (instance .Spec , "AnsibleGitRepo" , "string" , step ).(string )
356
- envVars ["POD_ANSIBLE_GIT_REPO" ] = env .SetValue (gitRepo )
357
-
358
- playbookPath := r .OverwriteAnsibleWithWorkflow (instance .Spec , "AnsiblePlaybookPath" , "string" , step ).(string )
359
- envVars ["POD_ANSIBLE_PLAYBOOK" ] = env .SetValue (playbookPath )
360
-
361
- ansibleCollections := r .OverwriteAnsibleWithWorkflow (instance .Spec , "AnsibleCollections" , "string" , step ).(string )
362
- envVars ["POD_INSTALL_COLLECTIONS" ] = env .SetValue (ansibleCollections )
289
+ envVars ["POD_ANSIBLE_EXTRA_VARS" ] = env .SetValue (instance .Spec .AnsibleExtraVars )
290
+ envVars ["POD_ANSIBLE_FILE_EXTRA_VARS" ] = env .SetValue (instance .Spec .AnsibleVarFiles )
291
+ envVars ["POD_ANSIBLE_INVENTORY" ] = env .SetValue (instance .Spec .AnsibleInventory )
292
+ envVars ["POD_ANSIBLE_GIT_REPO" ] = env .SetValue (instance .Spec .AnsibleGitRepo )
293
+ envVars ["POD_ANSIBLE_PLAYBOOK" ] = env .SetValue (instance .Spec .AnsiblePlaybookPath )
294
+ envVars ["POD_INSTALL_COLLECTIONS" ] = env .SetValue (instance .Spec .AnsibleCollections )
363
295
364
296
return envVars , workflowOverrideParams
365
297
}
0 commit comments