Skip to content

Commit

Permalink
fix(status): Define status handler
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege committed May 14, 2019
1 parent b5d3cc1 commit a5fc355
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/controller/v1alpha2/experiment/experiment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func Add(mgr manager.Manager) error {

// newReconciler returns a new reconcile.Reconciler
func newReconciler(mgr manager.Manager) reconcile.Reconciler {
return &ReconcileExperiment{Client: mgr.GetClient(), scheme: mgr.GetScheme()}
r := &ReconcileExperiment{
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
}
r.updateStatusHandler = r.updateStatus
return r
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
Expand Down Expand Up @@ -155,6 +160,9 @@ var _ reconcile.Reconciler = &ReconcileExperiment{}
type ReconcileExperiment struct {
client.Client
scheme *runtime.Scheme

// updateStatusHandler is defined for test purpose.
updateStatusHandler updateStatusFunc
}

// Reconcile reads that state of the cluster for a Experiment object and makes changes based on the state read
Expand Down Expand Up @@ -215,7 +223,7 @@ func (r *ReconcileExperiment) Reconcile(request reconcile.Request) (reconcile.Re
logger.Error(err, "Update experiment status in DB error")
return reconcile.Result{}, err
}
err = r.Status().Update(context.TODO(), instance)
err = r.updateStatusHandler(instance)
if err != nil {
logger.Error(err, "Update experiment instance status error")
return reconcile.Result{}, err
Expand Down
17 changes: 17 additions & 0 deletions pkg/controller/v1alpha2/experiment/experiment_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package experiment

import (
"context"

experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
)

type updateStatusFunc func(instance *experimentsv1alpha2.Experiment) error

func (r *ReconcileExperiment) updateStatus(instance *experimentsv1alpha2.Experiment) error {
err := r.Status().Update(context.TODO(), instance)
if err != nil {
return err
}
return nil
}

0 comments on commit a5fc355

Please sign in to comment.