Skip to content

Commit

Permalink
test/e2e: multik8s: requeue reconciliation immediately to speed up te…
Browse files Browse the repository at this point in the history
…sting

Signed-off-by: Ryotaro Banno <[email protected]>
  • Loading branch information
ushitora-anqou committed Jan 8, 2025
1 parent 531fe48 commit 0173ae9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions charts/mantle/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ spec:
fieldPath: metadata.namespace
- name: POD_IMAGE
value: {{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
{{- toYaml .Values.controller.env | nindent 12 }}
ports:
{{- toYaml .Values.controller.ports | nindent 12 }}
- command:
Expand Down
1 change: 1 addition & 0 deletions charts/mantle/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ affinity: {}
controller:
role: standalone
ports: []
env: []

secondaryService:
# type:
Expand Down
32 changes: 16 additions & 16 deletions internal/controller/mantlebackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (r *MantleBackupReconciler) getSnapshotTarget(ctx context.Context, backup *
}
if !ok {
logger.Info("waiting for PVC bound.")
return nil, ctrl.Result{Requeue: true}, nil
return nil, requeueReconciliation(), nil
}

pvName := pvc.Spec.VolumeName
Expand Down Expand Up @@ -392,7 +392,7 @@ func (r *MantleBackupReconciler) reconcileAsStandalone(ctx context.Context, back
default:
return ctrl.Result{}, getSnapshotTargetErr
}
if result.Requeue {
if !result.IsZero() {
return result, nil
}

Expand All @@ -415,7 +415,7 @@ func (r *MantleBackupReconciler) reconcileAsStandalone(ctx context.Context, back
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

if err := r.expire(ctx, backup); err != nil {
Expand Down Expand Up @@ -461,7 +461,7 @@ func (r *MantleBackupReconciler) reconcileAsSecondary(ctx context.Context, backu
default:
return ctrl.Result{}, getSnapshotTargetErr
}
if result.Requeue {
if !result.IsZero() {
return result, nil
}

Expand Down Expand Up @@ -564,7 +564,7 @@ func (r *MantleBackupReconciler) replicateManifests(
*backup1.Status.SnapID < *backup.Status.SnapID &&
backup1.ObjectMeta.DeletionTimestamp.IsZero() &&
!meta.IsStatusConditionTrue(backup1.Status.Conditions, mantlev1.BackupConditionSyncedToRemote) {
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}
}

Expand Down Expand Up @@ -703,7 +703,7 @@ func (r *MantleBackupReconciler) finalizeStandalone(
) (ctrl.Result, error) {
logger := log.FromContext(ctx)
if _, ok := backup.GetAnnotations()[annotDiffTo]; ok {
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

if !controllerutil.ContainsFinalizer(backup, MantleBackupFinalizerName) {
Expand Down Expand Up @@ -741,7 +741,7 @@ func (r *MantleBackupReconciler) finalizeSecondary(
) (ctrl.Result, error) {
logger := log.FromContext(ctx)
if _, ok := backup.GetAnnotations()[annotDiffTo]; ok {
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

if !controllerutil.ContainsFinalizer(backup, MantleBackupFinalizerName) {
Expand Down Expand Up @@ -965,7 +965,7 @@ func (r *MantleBackupReconciler) export(
return ctrl.Result{}, err
}

return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

func (r *MantleBackupReconciler) annotateExportTargetMantleBackup(
Expand Down Expand Up @@ -1025,7 +1025,7 @@ func (r *MantleBackupReconciler) checkIfNewJobCanBeCreated(ctx context.Context)
}

if len(jobs.Items) >= r.primarySettings.MaxExportJobs {
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

return ctrl.Result{}, nil
Expand Down Expand Up @@ -1271,7 +1271,7 @@ func (r *MantleBackupReconciler) checkIfExportJobIsCompleted(
return ctrl.Result{}, nil
}

return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

func (r *MantleBackupReconciler) createOrUpdateExportDataUploadJob(ctx context.Context, target *mantlev1.MantleBackup) error {
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (r *MantleBackupReconciler) startImport(
) (ctrl.Result, error) {
if !r.doesMantleBackupHaveSyncModeAnnot(backup) {
// SetSynchronizingg is not called yet or the cache is stale.
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

if result, err := r.isExportDataAlreadyUploaded(ctx, backup); err != nil || !result.IsZero() {
Expand All @@ -1431,7 +1431,7 @@ func (r *MantleBackupReconciler) startImport(

// Requeue if the PV is smaller than the PVC. (This may be the case if pvc-autoresizer is used.)
if isPVSmallerThanPVC(target.pv, target.pvc) {
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

if err := r.updateStatusManifests(ctx, backup, target.pv, target.pvc); err != nil {
Expand Down Expand Up @@ -1528,7 +1528,7 @@ func (r *MantleBackupReconciler) isExportDataAlreadyUploaded(
if uploaded {
return ctrl.Result{}, nil
}
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

func isPVSmallerThanPVC(
Expand Down Expand Up @@ -1592,7 +1592,7 @@ func (r *MantleBackupReconciler) reconcileDiscardJob(
if completed {
return ctrl.Result{}, nil
}
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

func (r *MantleBackupReconciler) createOrUpdateDiscardPV(
Expand Down Expand Up @@ -1777,11 +1777,11 @@ func (r *MantleBackupReconciler) reconcileImportJob(
if err := r.createOrImportJob(ctx, backup, snapshotTarget); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

if !IsJobConditionTrue(job.Status.Conditions, batchv1.JobComplete) {
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

snapshot, err := ceph.FindRBDSnapshot(
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/mantlerestore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (r *MantleRestoreReconciler) restore(ctx context.Context, restore *mantlev1
// check if the backup is ReadyToUse
if !meta.IsStatusConditionTrue(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse) {
logger.Info("backup is not ready to use", "backup", backup.Name, "namespace", backup.Namespace)
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

// store the pool name in the status
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/persistentvolume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *PersistentVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Req

// Wait until the PV's status becomes Released.
if pv.Status.Phase != corev1.VolumeReleased {
return ctrl.Result{Requeue: true}, nil
return requeueReconciliation(), nil
}

// Delete the RBD clone image.
Expand Down
11 changes: 11 additions & 0 deletions internal/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"context"
"errors"
"fmt"
"os"
"strings"
"time"

batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -81,3 +84,11 @@ func IsJobConditionTrue(conditions []batchv1.JobCondition, conditionType batchv1
}
return false
}

func requeueReconciliation() ctrl.Result {
requeueAfter := os.Getenv("REQUEUE_RECONCILIATION_IMMEDIATELY")
if requeueAfter == "1" {
return ctrl.Result{RequeueAfter: time.Second}
}
return ctrl.Result{Requeue: true}
}
2 changes: 2 additions & 0 deletions test/e2e/testdata/values-mantle-primary-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ controller:
#httpProxy: http://host.minikube.internal:8899
#httpsProxy: http://host.minikube.internal:8899
#noProxy: localhost,127.0.0.1,10.96.0.0/12
env:
REQUEUE_RECONCILIATION_IMMEDIATELY: 1
2 changes: 2 additions & 0 deletions test/e2e/testdata/values-mantle-secondary-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ controller:
objectStorageEndpoint: {OBJECT_STORAGE_ENDPOINT}
envSecret: export-data
gcInterval: 1s
env:
REQUEUE_RECONCILIATION_IMMEDIATELY: 1

secondaryService:
type: NodePort
Expand Down

0 comments on commit 0173ae9

Please sign in to comment.