Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
lpiwowar committed Oct 22, 2024
1 parent 87da611 commit 9a5a14b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
23 changes: 18 additions & 5 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,21 @@ const (
)

const (
ErrNetworkAttachments = "not all pods have interfaces with ips as configured in NetworkAttachments: %s"
ErrNetworkAttachments = "not all pods have interfaces with ips as configured in NetworkAttachments: %s"
ErrReceivedUnexpectedAction = "unexpected action received"
)

const (
InfoWaitingOnJob = "Waiting on either job to finish or release of the lock."
InfoTestingCompleted = "Testing completed. All pods spawned by the test-operator finished."
InfoCreatingFirstPod = "Creating first test pod (workflow step %d)."
InfoCreatingNextPod = "Creating next test pod (workflow step %d)."
)

const (
// How much time should we wait before calling Reconcile loop when we have to wait for a change
// or there is a failure
requeueAfter = time.Second * 60
)

type Reconciler struct {
Expand Down Expand Up @@ -383,7 +397,7 @@ func (r *Reconciler) ReleaseLock(ctx context.Context, instance client.Object) (b

cm, err := r.GetLockInfo(ctx, instance)
if err != nil && k8s_errors.IsNotFound(err) {
return false, nil
return true, nil
} else if err != nil {
return false, err
}
Expand All @@ -395,7 +409,7 @@ func (r *Reconciler) ReleaseLock(ctx context.Context, instance client.Object) (b

err = r.Client.Delete(ctx, cm)
if err != nil && k8s_errors.IsNotFound(err) {
return false, nil
return true, nil
}

// Check whether the lock was successfully deleted deleted
Expand Down Expand Up @@ -577,8 +591,7 @@ func (r *Reconciler) NextAction(

if isLastJob(len(jobs), workflowLength) {
if lockReleased, err := r.ReleaseLock(ctx, instance); !lockReleased {
// TODO(lpiwowar): No failure when releasing non-existing lock
return Failure, err
return EndTesting, err
}
return EndTesting, nil
}
Expand Down
25 changes: 14 additions & 11 deletions controllers/tempest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func (r *TempestReconciler) GetLogger(ctx context.Context) logr.Logger {
// Reconcile - Tempest
func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) {
Log := r.GetLogger(ctx)
// How much time should we wait before calling Reconcile loop when there is a failure
requeueAfter := time.Second * 60

// Fetch the Tempest instance
instance := &testv1beta1.Tempest{}
Expand Down Expand Up @@ -163,24 +161,30 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
nextWorkflowStep := 0
switch nextAction {
case Failure:
Log.Error(err, "Nopi")
return ctrl.Result{}, err

case Wait:
Log.Info("Waiting on job to finish or release of the lock.")
Log.Info(InfoWaitingOnJob)
return ctrl.Result{RequeueAfter: requeueAfter}, nil

case EndTesting:
Log.Info("Testing completed")
if lockReleased, err := r.ReleaseLock(ctx, instance); !lockReleased {
return ctrl.Result{}, err
}

Log.Info(InfoTestingCompleted)
return ctrl.Result{}, nil

case CreateFirstJob:
Log.Info("Creating first job")
lockAcquired, err := r.AcquireLock(ctx, instance, helper, instance.Spec.Parallel)
if !lockAcquired {
return ctrl.Result{}, err
}

nextWorkflowStep = 0
Log.Info(fmt.Sprintf(InfoCreatingFirstPod, nextWorkflowStep))

case CreateNextJob:
Log.Info("Creating next job")

lastJob, err := r.GetLastJob(ctx, instance)
if err != nil {
return ctrl.Result{}, err
Expand All @@ -192,10 +196,10 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
}

nextWorkflowStep = lastJobworkflowStep + 1
Log.Info(fmt.Sprintf(InfoCreatingNextPod, nextWorkflowStep))

default:
Log.Info("Unexpected action")
return ctrl.Result{}, nil
return ctrl.Result{}, fmt.Errorf(ErrReceivedUnexpectedAction)
}

// The job created by the instance was completed. Release the lock
Expand Down Expand Up @@ -380,7 +384,6 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
}
// Create a new job - end

Log.Info("Reconciled Service successfully")
return ctrl.Result{}, nil
}

Expand Down

0 comments on commit 9a5a14b

Please sign in to comment.