@@ -22,15 +22,12 @@ import (
2222 "fmt"
2323 "strconv"
2424
25- "reflect"
26-
2725 "github.com/go-logr/logr"
2826 "github.com/openstack-k8s-operators/lib-common/modules/common"
2927 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3028 "github.com/openstack-k8s-operators/lib-common/modules/common/env"
3129 "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
3230 testv1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
33- v1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
3431 "github.com/openstack-k8s-operators/test-operator/pkg/ansibletest"
3532 corev1 "k8s.io/api/core/v1"
3633 k8s_errors "k8s.io/apimachinery/pkg/api/errors"
@@ -129,6 +126,9 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
129126
130127 workflowLength := len (instance .Spec .Workflow )
131128 nextAction , nextWorkflowStep , err := r .NextAction (ctx , instance , workflowLength )
129+ if nextWorkflowStep < workflowLength {
130+ MergeSections (& instance .Spec , instance .Spec .Workflow [nextWorkflowStep ])
131+ }
132132
133133 switch nextAction {
134134 case Failure :
@@ -206,32 +206,14 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
206206 // Create a new pod
207207 mountCerts := r .CheckSecretExists (ctx , instance , "combined-ca-bundle" )
208208 podName := r .GetPodName (instance , nextWorkflowStep )
209- envVars , workflowOverrideParams := r .PrepareAnsibleEnv (instance , nextWorkflowStep )
209+ envVars , workflowOverrideParams := r .PrepareAnsibleEnv (instance )
210210 logsPVCName := r .GetPVCLogsName (instance , 0 )
211211 containerImage , err := r .GetContainerImage (ctx , workflowOverrideParams ["ContainerImage" ], instance )
212- privileged := r . OverwriteAnsibleWithWorkflow ( instance .Spec , "Privileged" , "pbool" , nextWorkflowStep ).( bool )
212+ privileged := instance .Spec . Privileged
213213 if err != nil {
214214 return ctrl.Result {}, err
215215 }
216216
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-
235217 podDef := ansibletest .Pod (
236218 instance ,
237219 serviceLabels ,
@@ -284,82 +266,32 @@ func (r *AnsibleTestReconciler) SetupWithManager(mgr ctrl.Manager) error {
284266 Complete (r )
285267}
286268
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-
325269// This function prepares env variables for a single workflow step.
326270func (r * AnsibleTestReconciler ) PrepareAnsibleEnv (
327271 instance * testv1beta1.AnsibleTest ,
328- step int ,
329272) (map [string ]env.Setter , map [string ]string ) {
330273 // Prepare env vars
331274 envVars := make (map [string ]env.Setter )
332275 workflowOverrideParams := make (map [string ]string )
333276
334277 // 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
338281
339282 // bool
340- debug := r . OverwriteAnsibleWithWorkflow ( instance .Spec , "Debug" , "pbool" , step ).( bool )
283+ debug := instance .Spec . Debug
341284 if debug {
342285 envVars ["POD_DEBUG" ] = env .SetValue ("true" )
343286 }
344287
345288 // 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 )
363295
364296 return envVars , workflowOverrideParams
365297}
0 commit comments