Skip to content

Commit b97156c

Browse files
Merge pull request #420 from kstrenkova/rename-workflow-step-vars
Rename workflow number variables for clarity
2 parents 7f84631 + e07e9b4 commit b97156c

5 files changed

Lines changed: 61 additions & 61 deletions

File tree

internal/controller/ansibletest_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
127127
instance.Status.ObservedGeneration = instance.Generation
128128

129129
workflowLength := len(instance.Spec.Workflow)
130-
nextAction, nextWorkflowStep, err := r.NextAction(ctx, instance, workflowLength)
131-
if nextWorkflowStep < workflowLength {
132-
MergeSections(&instance.Spec, instance.Spec.Workflow[nextWorkflowStep])
130+
nextAction, workflowStepIndex, err := r.NextAction(ctx, instance, workflowLength)
131+
if workflowStepIndex < workflowLength {
132+
MergeSections(&instance.Spec, instance.Spec.Workflow[workflowStepIndex])
133133
}
134134

135135
switch nextAction {
@@ -166,7 +166,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
166166
return ctrl.Result{RequeueAfter: RequeueAfterValue}, err
167167
}
168168

169-
Log.Info(fmt.Sprintf(InfoCreatingFirstPod, nextWorkflowStep))
169+
Log.Info(fmt.Sprintf(InfoCreatingFirstPod, workflowStepIndex))
170170

171171
case CreateNextPod:
172172
// Confirm that we still hold the lock. This is useful to check if for
@@ -178,15 +178,15 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
178178
return ctrl.Result{RequeueAfter: RequeueAfterValue}, err
179179
}
180180

181-
Log.Info(fmt.Sprintf(InfoCreatingNextPod, nextWorkflowStep))
181+
Log.Info(fmt.Sprintf(InfoCreatingNextPod, workflowStepIndex))
182182

183183
default:
184184
return ctrl.Result{}, ErrReceivedUnexpectedAction
185185
}
186186

187187
serviceLabels := map[string]string{
188188
common.AppSelector: ansibletest.ServiceName,
189-
workflowStepLabel: strconv.Itoa(nextWorkflowStep),
189+
workflowStepLabel: strconv.Itoa(workflowStepIndex),
190190
instanceNameLabel: instance.Name,
191191
operatorNameLabel: "test-operator",
192192
}
@@ -221,7 +221,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
221221

222222
// Create a new pod
223223
mountCerts := r.CheckSecretExists(ctx, instance, "combined-ca-bundle")
224-
podName := r.GetPodName(instance, nextWorkflowStep)
224+
podName := r.GetPodName(instance, workflowStepIndex)
225225
envVars := r.PrepareAnsibleEnv(instance)
226226
logsPVCName := r.GetPVCLogsName(instance, 0)
227227
containerImage, err := r.GetContainerImage(ctx, instance)
@@ -236,7 +236,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
236236
logsPVCName,
237237
mountCerts,
238238
envVars,
239-
nextWorkflowStep,
239+
workflowStepIndex,
240240
containerImage,
241241
)
242242

internal/controller/common.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ func (r *Reconciler) GetPodName(instance interface{}, stepNum int) string {
333333
}
334334

335335
// GetPVCLogsName returns the name of the PVC for logs for the given instance and workflow step
336-
func (r *Reconciler) GetPVCLogsName(instance client.Object, workflowStepNum int) string {
336+
func (r *Reconciler) GetPVCLogsName(instance client.Object, pvcIndex int) string {
337337
instanceName := instance.GetName()
338338
instanceCreationTimestamp := instance.GetCreationTimestamp().Format(time.UnixDate)
339339
suffixLength := 5
340340
nameSuffix := GetStringHash(instanceName+instanceCreationTimestamp, suffixLength)
341-
workflowStep := strconv.Itoa(workflowStepNum)
341+
workflowStep := strconv.Itoa(pvcIndex)
342342
return instanceName + "-" + workflowStep + "-" + nameSuffix
343343
}
344344

@@ -446,10 +446,10 @@ func (r *Reconciler) EnsureLogsPVCExists(
446446
helper *helper.Helper,
447447
labels map[string]string,
448448
StorageClassName string,
449-
workflowStepNum int,
449+
pvcIndex int,
450450
) (ctrl.Result, error) {
451451
instanceNamespace := instance.GetNamespace()
452-
pvcName := r.GetPVCLogsName(instance, workflowStepNum)
452+
pvcName := r.GetPVCLogsName(instance, pvcIndex)
453453

454454
pvvc := &corev1.PersistentVolumeClaim{}
455455
err := r.Client.Get(ctx, client.ObjectKey{Namespace: instanceNamespace, Name: pvcName}, pvvc)
@@ -591,9 +591,9 @@ func (r *Reconciler) ReleaseLock(ctx context.Context, instance client.Object) (b
591591
}
592592

593593
// PodExists checks if a pod exists for the given instance and workflow step
594-
func (r *Reconciler) PodExists(ctx context.Context, instance client.Object, workflowStepNum int) bool {
594+
func (r *Reconciler) PodExists(ctx context.Context, instance client.Object, workflowStepIndex int) bool {
595595
pod := &corev1.Pod{}
596-
podName := r.GetPodName(instance, workflowStepNum)
596+
podName := r.GetPodName(instance, workflowStepIndex)
597597
objectKey := client.ObjectKey{Namespace: instance.GetNamespace(), Name: podName}
598598
err := r.Client.Get(ctx, objectKey, pod)
599599
if err != nil && k8s_errors.IsNotFound(err) {
@@ -678,11 +678,11 @@ func (r *Reconciler) VerifyNetworkAttachments(
678678
instance client.Object,
679679
networkAttachments []string,
680680
serviceLabels map[string]string,
681-
nextWorkflowStep int,
681+
workflowStepIndex int,
682682
conditions *condition.Conditions,
683683
networkAttachmentStatus *map[string][]string,
684684
) (ctrl.Result, error) {
685-
if !r.PodExists(ctx, instance, nextWorkflowStep) {
685+
if !r.PodExists(ctx, instance, workflowStepIndex) {
686686
return ctrl.Result{}, nil
687687
}
688688

internal/controller/horizontest_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (r *HorizonTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
122122
instance.Status.ObservedGeneration = instance.Generation
123123

124124
workflowLength := 0
125-
nextAction, nextWorkflowStep, err := r.NextAction(ctx, instance, workflowLength)
125+
nextAction, workflowStepIndex, err := r.NextAction(ctx, instance, workflowLength)
126126

127127
switch nextAction {
128128
case Failure:
@@ -158,7 +158,7 @@ func (r *HorizonTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
158158
return ctrl.Result{RequeueAfter: RequeueAfterValue}, err
159159
}
160160

161-
Log.Info(fmt.Sprintf(InfoCreatingFirstPod, nextWorkflowStep))
161+
Log.Info(fmt.Sprintf(InfoCreatingFirstPod, workflowStepIndex))
162162

163163
case CreateNextPod:
164164
// Confirm that we still hold the lock. This is useful to check if for
@@ -170,7 +170,7 @@ func (r *HorizonTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
170170
return ctrl.Result{RequeueAfter: RequeueAfterValue}, err
171171
}
172172

173-
Log.Info(fmt.Sprintf(InfoCreatingNextPod, nextWorkflowStep))
173+
Log.Info(fmt.Sprintf(InfoCreatingNextPod, workflowStepIndex))
174174

175175
default:
176176
return ctrl.Result{}, ErrReceivedUnexpectedAction

internal/controller/tempest_controller.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
146146
}
147147

148148
workflowLength := len(instance.Spec.Workflow)
149-
nextAction, nextWorkflowStep, err := r.NextAction(ctx, instance, workflowLength)
150-
if nextWorkflowStep < workflowLength {
151-
MergeSections(&instance.Spec, instance.Spec.Workflow[nextWorkflowStep])
149+
nextAction, workflowStepIndex, err := r.NextAction(ctx, instance, workflowLength)
150+
if workflowStepIndex < workflowLength {
151+
MergeSections(&instance.Spec, instance.Spec.Workflow[workflowStepIndex])
152152
}
153153

154154
switch nextAction {
@@ -185,7 +185,7 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
185185
return ctrl.Result{RequeueAfter: RequeueAfterValue}, err
186186
}
187187

188-
Log.Info(fmt.Sprintf(InfoCreatingFirstPod, nextWorkflowStep))
188+
Log.Info(fmt.Sprintf(InfoCreatingFirstPod, workflowStepIndex))
189189

190190
case CreateNextPod:
191191
// Confirm that we still hold the lock. This is useful to check if for
@@ -197,23 +197,23 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
197197
return ctrl.Result{RequeueAfter: RequeueAfterValue}, err
198198
}
199199

200-
Log.Info(fmt.Sprintf(InfoCreatingNextPod, nextWorkflowStep))
200+
Log.Info(fmt.Sprintf(InfoCreatingNextPod, workflowStepIndex))
201201

202202
default:
203203
return ctrl.Result{}, ErrReceivedUnexpectedAction
204204
}
205205

206206
serviceLabels := map[string]string{
207207
common.AppSelector: tempest.ServiceName,
208-
workflowStepLabel: strconv.Itoa(nextWorkflowStep),
208+
workflowStepLabel: strconv.Itoa(workflowStepIndex),
209209
instanceNameLabel: instance.Name,
210210
operatorNameLabel: "test-operator",
211211
}
212212

213-
workflowStepNum := 0
213+
pvcIndex := 0
214214
// Create multiple PVCs for parallel execution
215-
if instance.Spec.Parallel && nextWorkflowStep < len(instance.Spec.Workflow) {
216-
workflowStepNum = nextWorkflowStep
215+
if instance.Spec.Parallel && workflowStepIndex < len(instance.Spec.Workflow) {
216+
pvcIndex = workflowStepIndex
217217
}
218218

219219
err = r.ValidateOpenstackInputs(ctx, instance, instance.Spec.OpenStackConfigMap, instance.Spec.OpenStackConfigSecret)
@@ -248,7 +248,7 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
248248
helper,
249249
serviceLabels,
250250
instance.Spec.StorageClass,
251-
workflowStepNum,
251+
pvcIndex,
252252
)
253253

254254
if err != nil {
@@ -259,7 +259,7 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
259259
// Create PersistentVolumeClaim - end
260260

261261
// Generate ConfigMaps
262-
err = r.generateServiceConfigMaps(ctx, helper, instance, nextWorkflowStep)
262+
err = r.generateServiceConfigMaps(ctx, helper, instance, workflowStepIndex)
263263
if err != nil {
264264
instance.Status.Conditions.Set(condition.FalseCondition(
265265
condition.ServiceConfigReadyCondition,
@@ -286,10 +286,10 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
286286

287287
// Create a new pod
288288
mountCerts := r.CheckSecretExists(ctx, instance, "combined-ca-bundle")
289-
customDataConfigMapName := GetCustomDataConfigMapName(instance, nextWorkflowStep)
290-
EnvVarsConfigMapName := GetEnvVarsConfigMapName(instance, nextWorkflowStep)
291-
podName := r.GetPodName(instance, nextWorkflowStep)
292-
logsPVCName := r.GetPVCLogsName(instance, workflowStepNum)
289+
customDataConfigMapName := GetCustomDataConfigMapName(instance, workflowStepIndex)
290+
EnvVarsConfigMapName := GetEnvVarsConfigMapName(instance, workflowStepIndex)
291+
podName := r.GetPodName(instance, workflowStepIndex)
292+
logsPVCName := r.GetPVCLogsName(instance, pvcIndex)
293293
containerImage, err := r.GetContainerImage(ctx, instance)
294294
if err != nil {
295295
return ctrl.Result{}, err
@@ -341,7 +341,7 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
341341
instance,
342342
instance.Spec.NetworkAttachments,
343343
serviceLabels,
344-
nextWorkflowStep,
344+
workflowStepIndex,
345345
&instance.Status.Conditions,
346346
&instance.Status.NetworkAttachments,
347347
)
@@ -385,7 +385,7 @@ func (r *TempestReconciler) SetupWithManager(mgr ctrl.Manager) error {
385385
func (r *TempestReconciler) setTempestConfigVars(envVars map[string]string,
386386
customData map[string]string,
387387
instance *testv1beta1.Tempest,
388-
workflowStepNum int,
388+
workflowStepIndex int,
389389
) {
390390
tRun := instance.Spec.TempestRun
391391

@@ -421,7 +421,7 @@ func (r *TempestReconciler) setTempestConfigVars(envVars map[string]string,
421421
})
422422
}
423423

424-
envVars["TEMPEST_WORKFLOW_STEP_DIR_NAME"] = r.GetPodName(instance, workflowStepNum)
424+
envVars["TEMPEST_WORKFLOW_STEP_DIR_NAME"] = r.GetPodName(instance, workflowStepIndex)
425425

426426
for _, img := range tRun.ExtraImages {
427427
SetDictEnvVar(envVars, map[string]string{
@@ -509,7 +509,7 @@ func (r *TempestReconciler) generateServiceConfigMaps(
509509
ctx context.Context,
510510
h *helper.Helper,
511511
instance *testv1beta1.Tempest,
512-
workflowStepNum int,
512+
workflowStepIndex int,
513513
) error {
514514
// Create/update configmaps from template
515515
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(tempest.ServiceName), map[string]string{})
@@ -528,7 +528,7 @@ func (r *TempestReconciler) generateServiceConfigMaps(
528528
customData := make(map[string]string)
529529
envVars := make(map[string]string)
530530

531-
r.setTempestConfigVars(envVars, customData, instance, workflowStepNum)
531+
r.setTempestConfigVars(envVars, customData, instance, workflowStepIndex)
532532
r.setTempestconfConfigVars(envVars, customData, instance)
533533

534534
for key, data := range instance.Spec.ConfigOverwrite {
@@ -544,7 +544,7 @@ func (r *TempestReconciler) generateServiceConfigMaps(
544544
cms := []util.Template{
545545
// ConfigMap
546546
{
547-
Name: GetCustomDataConfigMapName(instance, workflowStepNum),
547+
Name: GetCustomDataConfigMapName(instance, workflowStepIndex),
548548
Namespace: instance.Namespace,
549549
InstanceType: instance.Kind,
550550
Labels: cmLabels,
@@ -553,7 +553,7 @@ func (r *TempestReconciler) generateServiceConfigMaps(
553553
},
554554
// configMap - EnvVars
555555
{
556-
Name: GetEnvVarsConfigMapName(instance, workflowStepNum),
556+
Name: GetEnvVarsConfigMapName(instance, workflowStepIndex),
557557
Namespace: instance.Namespace,
558558
InstanceType: instance.Kind,
559559
Labels: cmLabels,
@@ -566,11 +566,11 @@ func (r *TempestReconciler) generateServiceConfigMaps(
566566
}
567567

568568
// GetEnvVarsConfigMapName returns the name of the environment variables ConfigMap for the given workflow step
569-
func GetEnvVarsConfigMapName(instance *testv1beta1.Tempest, workflowStepNum int) string {
570-
return instance.Name + envVarsConfigMapInfix + strconv.Itoa(workflowStepNum)
569+
func GetEnvVarsConfigMapName(instance *testv1beta1.Tempest, workflowStepIndex int) string {
570+
return instance.Name + envVarsConfigMapInfix + strconv.Itoa(workflowStepIndex)
571571
}
572572

573573
// GetCustomDataConfigMapName returns the name of the custom data ConfigMap for the given workflow step
574-
func GetCustomDataConfigMapName(instance *testv1beta1.Tempest, workflowStepNum int) string {
575-
return instance.Name + customDataConfigMapInfix + strconv.Itoa(workflowStepNum)
574+
func GetCustomDataConfigMapName(instance *testv1beta1.Tempest, workflowStepIndex int) string {
575+
return instance.Name + customDataConfigMapInfix + strconv.Itoa(workflowStepIndex)
576576
}

0 commit comments

Comments
 (0)