Skip to content

Commit

Permalink
chore: use IsZero() for ctr.Result to make check
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed Sep 27, 2024
1 parent c3cf78b commit d3667c4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
8 changes: 4 additions & 4 deletions controller/controlplane/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
log.Debug(logger, "unable to update ControlPlane resource", cp, "error", err)
return res, err
}
if res.Requeue {
if !res.IsZero() {
log.Debug(logger, "unable to update ControlPlane resource", cp)
return res, nil
}
Expand Down Expand Up @@ -383,7 +383,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
log.Debug(logger, "unable to reconcile ControlPlane status", cp, "error", err)
return ctrl.Result{}, err
}
if res.Requeue {
if !res.IsZero() {
log.Debug(logger, "unable to update ControlPlane resource", cp)
return res, nil
}
Expand All @@ -406,7 +406,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
log.Debug(logger, "unable to patch ControlPlane status", cp, "error", err)
return ctrl.Result{}, err
}
if res.Requeue {
if !res.IsZero() {
log.Debug(logger, "unable to patch ControlPlane status", cp)
return res, nil
}
Expand All @@ -421,7 +421,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
log.Debug(logger, "unable to patch ControlPlane status", cp, "error", err)
return ctrl.Result{}, err
}
if result.Requeue {
if !result.IsZero() {
log.Debug(logger, "unable to patch ControlPlane status", cp)
return result, nil
}
Expand Down
4 changes: 2 additions & 2 deletions controller/dataplane/bluegreen_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

if res, err := r.ensureDataPlaneLiveReadyStatus(ctx, logger, &dataplane); err != nil {
return ctrl.Result{}, err
} else if res.Requeue {
} else if !res.IsZero() {
return res, nil
}

Expand All @@ -120,7 +120,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
// can update the Ready status condition of the DataPlane.
if res, err := ensureDataPlaneReadyStatus(ctx, r.Client, logger, &dataplane, dataplane.Generation); err != nil {
return ctrl.Result{}, err
} else if res.Requeue {
} else if !res.IsZero() {
return res, nil
}
} else if !ok || c.ObservedGeneration != dataplane.Generation {
Expand Down
2 changes: 1 addition & 1 deletion controller/dataplane/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu

if res, err := ensureDataPlaneReadyStatus(ctx, r.Client, logger, dataplane, dataplane.Generation); err != nil {
return ctrl.Result{}, err
} else if res.Requeue {
} else if !res.IsZero() {
return res, nil
}

Expand Down
4 changes: 2 additions & 2 deletions controller/gateway/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
}

log.Trace(logger, "managing cleanup for gateway resource", gateway)
if shouldReturnEarly, result, err := r.cleanup(ctx, logger, &gateway); err != nil || result.Requeue {
if shouldReturnEarly, result, err := r.cleanup(ctx, logger, &gateway); err != nil || !result.IsZero() {
return result, err
} else if shouldReturnEarly {
return ctrl.Result{}, nil
Expand All @@ -130,7 +130,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
if err != nil {
return res, fmt.Errorf("failed updating Gateway's finalizers: %w", err)
}
if res.Requeue {
if !res.IsZero() {
return res, nil
}
}
Expand Down
54 changes: 27 additions & 27 deletions controller/konnect/reconciler_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(

// If a type has a ControlPlane ref, handle it.
res, err := handleControlPlaneRef(ctx, r.Client, ent)
if err != nil || res.Requeue {
if err != nil || !res.IsZero() {
// If the referenced ControlPlane is not found and the object is deleted,
// remove the finalizer and update the status.
// There's no need to remove the entity on Konnect because the ControlPlane
Expand Down Expand Up @@ -167,7 +167,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
}
return ctrl.Result{}, nil
}
} else if res.Requeue {
} else if !res.IsZero() {
return res, nil
}
// If a type has a KongConsumer ref, handle it.
Expand Down Expand Up @@ -207,7 +207,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
}

return ctrl.Result{}, err
} else if res.Requeue {
} else if !res.IsZero() {
return res, nil
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
}

return ctrl.Result{}, err
} else if res.Requeue {
} else if !res.IsZero() {
return res, nil
}

Expand All @@ -264,7 +264,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
metav1.ConditionFalse,
conditions.KonnectEntityAPIAuthConfigurationResolvedRefReasonRefNotFound,
fmt.Sprintf("Referenced KonnectAPIAuthConfiguration %s not found", apiAuthRef),
); err != nil || res.Requeue {
); err != nil || !res.IsZero() {
return ctrl.Result{}, err
}

Expand All @@ -277,7 +277,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
metav1.ConditionFalse,
conditions.KonnectEntityAPIAuthConfigurationResolvedRefReasonRefInvalid,
fmt.Sprintf("KonnectAPIAuthConfiguration reference %s is invalid: %v", apiAuthRef, err),
); err != nil || res.Requeue {
); err != nil || !res.IsZero() {
return ctrl.Result{}, err
}

Expand All @@ -295,7 +295,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
metav1.ConditionTrue,
conditions.KonnectEntityAPIAuthConfigurationResolvedRefReasonResolvedRef,
fmt.Sprintf("KonnectAPIAuthConfiguration reference %s is resolved", apiAuthRef),
); err != nil || res.Requeue {
); err != nil || !res.IsZero() {
return res, err
}
return ctrl.Result{}, nil
Expand All @@ -314,7 +314,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
metav1.ConditionFalse,
conditions.KonnectEntityAPIAuthConfigurationReasonInvalid,
conditionMessageReferenceKonnectAPIAuthConfigurationInvalid(apiAuthRef),
); err != nil || res.Requeue {
); err != nil || !res.IsZero() {
return res, err
}

Expand All @@ -336,7 +336,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
metav1.ConditionTrue,
conditions.KonnectEntityAPIAuthConfigurationReasonValid,
conditionMessageReferenceKonnectAPIAuthConfigurationValid(apiAuthRef),
); err != nil || res.Requeue {
); err != nil || !res.IsZero() {
return res, err
}
return ctrl.Result{}, nil
Expand All @@ -350,7 +350,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
metav1.ConditionFalse,
conditions.KonnectEntityAPIAuthConfigurationReasonInvalid,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}
return ctrl.Result{}, err
Expand Down Expand Up @@ -385,7 +385,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
metav1.ConditionFalse,
conditions.KonnectEntityProgrammedReasonKonnectAPIOpFailed,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}
return ctrl.Result{}, err
Expand Down Expand Up @@ -451,7 +451,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(

if res, err := ops.Update[T, TEnt](ctx, sdk, r.SyncPeriod, r.Client, ent); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update object: %w", err)
} else if res.Requeue || res.RequeueAfter > 0 {
} else if !res.IsZero() {
return res, nil
}

Expand Down Expand Up @@ -707,7 +707,7 @@ func handleKongServiceRef[T constraints.SupportedKonnectEntityType, TEnt constra
metav1.ConditionFalse,
conditions.KongServiceRefReasonInvalid,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand All @@ -731,7 +731,7 @@ func handleKongServiceRef[T constraints.SupportedKonnectEntityType, TEnt constra
metav1.ConditionFalse,
conditions.KongServiceRefReasonInvalid,
fmt.Sprintf("Referenced KongService %s is not programmed yet", nn),
); err != nil || res.Requeue {
); err != nil || !res.IsZero() {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, nil
Expand Down Expand Up @@ -764,7 +764,7 @@ func handleKongServiceRef[T constraints.SupportedKonnectEntityType, TEnt constra
metav1.ConditionTrue,
conditions.KongServiceRefReasonValid,
fmt.Sprintf("Referenced KongService %s programmed", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand All @@ -783,7 +783,7 @@ func handleKongServiceRef[T constraints.SupportedKonnectEntityType, TEnt constra
metav1.ConditionFalse,
conditions.ControlPlaneRefReasonInvalid,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}
if k8serrors.IsNotFound(err) {
Expand All @@ -803,7 +803,7 @@ func handleKongServiceRef[T constraints.SupportedKonnectEntityType, TEnt constra
metav1.ConditionFalse,
conditions.ControlPlaneRefReasonInvalid,
fmt.Sprintf("Referenced ControlPlane %s is not programmed yet", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand All @@ -823,7 +823,7 @@ func handleKongServiceRef[T constraints.SupportedKonnectEntityType, TEnt constra
metav1.ConditionTrue,
conditions.ControlPlaneRefReasonValid,
fmt.Sprintf("Referenced ControlPlane %s is programmed", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand Down Expand Up @@ -859,7 +859,7 @@ func handleKongConsumerRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionFalse,
conditions.KongConsumerRefReasonInvalid,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand Down Expand Up @@ -887,7 +887,7 @@ func handleKongConsumerRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionFalse,
conditions.KongConsumerRefReasonInvalid,
fmt.Sprintf("Referenced KongConsumer %s is not programmed yet", nn),
); err != nil || res.Requeue {
); err != nil || !res.IsZero() {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, nil
Expand Down Expand Up @@ -926,7 +926,7 @@ func handleKongConsumerRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionTrue,
conditions.KongConsumerRefReasonValid,
fmt.Sprintf("Referenced KongConsumer %s programmed", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand All @@ -945,7 +945,7 @@ func handleKongConsumerRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionFalse,
conditions.ControlPlaneRefReasonInvalid,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}
if k8serrors.IsNotFound(err) {
Expand All @@ -965,7 +965,7 @@ func handleKongConsumerRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionFalse,
conditions.ControlPlaneRefReasonInvalid,
fmt.Sprintf("Referenced ControlPlane %s is not programmed yet", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand All @@ -982,7 +982,7 @@ func handleKongConsumerRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionTrue,
conditions.ControlPlaneRefReasonValid,
fmt.Sprintf("Referenced ControlPlane %s is programmed", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand Down Expand Up @@ -1080,7 +1080,7 @@ func handleControlPlaneRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionFalse,
conditions.ControlPlaneRefReasonInvalid,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}
if k8serrors.IsNotFound(err) {
Expand All @@ -1100,7 +1100,7 @@ func handleControlPlaneRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionFalse,
conditions.ControlPlaneRefReasonInvalid,
fmt.Sprintf("Referenced ControlPlane %s is not programmed yet", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}

Expand Down Expand Up @@ -1137,7 +1137,7 @@ func handleControlPlaneRef[T constraints.SupportedKonnectEntityType, TEnt constr
metav1.ConditionTrue,
conditions.ControlPlaneRefReasonValid,
fmt.Sprintf("Referenced ControlPlane %s is programmed", nn),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}
return ctrl.Result{}, nil
Expand Down
6 changes: 3 additions & 3 deletions controller/konnect/reconciler_konnectapiauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (r *KonnectAPIAuthConfigurationReconciler) Reconcile(
metav1.ConditionFalse,
conditions.KonnectEntityAPIAuthConfigurationReasonInvalid,
err.Error(),
); errStatus != nil || res.Requeue {
); errStatus != nil || !res.IsZero() {
return res, errStatus
}
return ctrl.Result{}, err
Expand Down Expand Up @@ -167,7 +167,7 @@ func (r *KonnectAPIAuthConfigurationReconciler) Reconcile(
conditions.KonnectEntityAPIAuthConfigurationReasonInvalid,
err.Error(),
)
if errUpdate != nil || res.Requeue {
if errUpdate != nil || !res.IsZero() {
return res, errUpdate
}
return ctrl.Result{}, nil
Expand Down Expand Up @@ -205,7 +205,7 @@ func (r *KonnectAPIAuthConfigurationReconciler) Reconcile(
conditions.KonnectEntityAPIAuthConfigurationReasonValid,
condMessage,
)
if err != nil || res.Requeue {
if err != nil || !res.IsZero() {
return res, err
}
return ctrl.Result{}, nil
Expand Down
Loading

0 comments on commit d3667c4

Please sign in to comment.