Skip to content

Commit

Permalink
chore: tidy up ops and component controller codes (#8274)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Oct 14, 2024
1 parent 5663202 commit f76d3a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 0 additions & 1 deletion apis/dataprotection/v1alpha1/backuppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ type PodSelectionStrategy string

const (
// PodSelectionStrategyAll selects all pods that match the labelsSelector.
// TODO: support PodSelectionStrategyAll
PodSelectionStrategyAll PodSelectionStrategy = "All"

// PodSelectionStrategyAny selects any one pod that match the labelsSelector.
Expand Down
6 changes: 3 additions & 3 deletions controllers/apps/component_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *componentPlanBuilder) Build() (graph.Plan, error) {
dag := graph.NewDAG()
err := c.transformers.ApplyTo(c.transCtx, dag)
if err != nil {
c.transCtx.Logger.V(1).Info(fmt.Sprintf("build error: %s", err.Error()))
c.transCtx.Logger.Info(fmt.Sprintf("build error: %s", err.Error()))
}
c.transCtx.Logger.V(1).Info(fmt.Sprintf("DAG: %s", dag))

Expand All @@ -130,7 +130,7 @@ func (c *componentPlanBuilder) Build() (graph.Plan, error) {
func (p *componentPlan) Execute() error {
err := p.dag.WalkReverseTopoOrder(p.walkFunc, nil)
if err != nil {
p.transCtx.Logger.V(1).Info(fmt.Sprintf("execute error: %s", err.Error()))
p.transCtx.Logger.Info(fmt.Sprintf("execute error: %s", err.Error()))
}
return err
}
Expand All @@ -154,7 +154,7 @@ func (c *componentPlanBuilder) defaultWalkFuncWithLogging(vertex graph.Vertex) e
err := c.defaultWalkFunc(vertex)
switch {
case err == nil:
c.transCtx.Logger.V(1).Info(fmt.Sprintf("reconcile object %T with action %s OK", node.Obj, *node.Action))
c.transCtx.Logger.Info(fmt.Sprintf("reconcile object %T with action %s OK", node.Obj, *node.Action))
return err
case !ok:
c.transCtx.Logger.Error(err, "")
Expand Down
5 changes: 5 additions & 0 deletions controllers/operations/opsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ func (r *OpsRequestReconciler) fetchCluster(reqCtx intctrlutil.RequestCtx, opsRe
}, cluster); err != nil {
if apierrors.IsNotFound(err) {
_ = operations.PatchClusterNotFound(reqCtx.Ctx, r.Client, opsRes)
if !opsRes.OpsRequest.DeletionTimestamp.IsZero() {
return intctrlutil.HandleCRDeletion(reqCtx, r, opsRes.OpsRequest, constant.OpsRequestFinalizerName, func() (*ctrl.Result, error) {
return nil, r.deleteCreatedPodsInKBNamespace(reqCtx, opsRes.OpsRequest)
})
}
}
return intctrlutil.ResultToP(intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, ""))
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/operations/ops_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,16 @@ func (opsMgr *OpsManager) Reconcile(reqCtx intctrlutil.RequestCtx, cli client.Cl
err = initOpsDefAndValidate(reqCtx, cli, opsRes)
if intctrlutil.IsTargetError(err, intctrlutil.ErrorTypeFatal) {
return requeueAfter, patchValidateErrorCondition(reqCtx.Ctx, cli, opsRes, err.Error())
} else if err != nil {
}
if err != nil {
return requeueAfter, err
}
}
if opsRequestPhase, requeueAfter, err = opsBehaviour.OpsHandler.ReconcileAction(reqCtx, cli, opsRes); err != nil &&
!isOpsRequestFailedPhase(opsRequestPhase) {
if intctrlutil.IsTargetError(err, intctrlutil.ErrorTypeFatal) {
return requeueAfter, patchFatalFailErrorCondition(reqCtx.Ctx, cli, opsRes, err)
}
// if the opsRequest phase is not failed, skipped
return requeueAfter, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/operations/ops_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ func PatchOpsStatus(ctx context.Context,

// PatchClusterNotFound patches ClusterNotFound condition to the OpsRequest.status.conditions.
func PatchClusterNotFound(ctx context.Context, cli client.Client, opsRes *OpsResource) error {
message := fmt.Sprintf("spec.clusterRef %s is not found", opsRes.OpsRequest.Spec.GetClusterName())
message := fmt.Sprintf("spec.clusterName %s is not found", opsRes.OpsRequest.Spec.GetClusterName())
condition := opsv1alpha1.NewValidateFailedCondition(opsv1alpha1.ReasonClusterNotFound, message)
return PatchOpsStatus(ctx, cli, opsRes, opsv1alpha1.OpsFailedPhase, condition)
opsPhase := opsv1alpha1.OpsFailedPhase
if opsRes.OpsRequest.IsComplete() {
opsPhase = opsRes.OpsRequest.Status.Phase
}
return PatchOpsStatus(ctx, cli, opsRes, opsPhase, condition)
}

// PatchOpsHandlerNotSupported patches OpsNotSupported condition to the OpsRequest.status.conditions.
Expand Down

0 comments on commit f76d3a4

Please sign in to comment.