Skip to content

Commit

Permalink
feat: Add events in experiment (#880)
Browse files Browse the repository at this point in the history
* feat: Add events in experiment

Signed-off-by: Ce Gao <[email protected]>

* fix: Reorder import

Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Oct 14, 2019
1 parent 9d7164a commit d93b602
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
5 changes: 5 additions & 0 deletions pkg/controller.v1alpha3/experiment/experiment_consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package experiment

const (
ReconcileFailedReason = "ReconcileFailed"
)
27 changes: 17 additions & 10 deletions pkg/controller.v1alpha3/experiment/experiment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"sort"

"github.com/spf13/viper"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand All @@ -44,12 +46,14 @@ import (
"github.com/kubeflow/katib/pkg/controller.v1alpha3/experiment/util"
)

var log = logf.Log.WithName("experiment-controller")
const (
// ControllerName is the controller name.
ControllerName = "experiment-controller"
)

/**
* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller
* business logic. Delete these comments after modifying this file.*
*/
var (
log = logf.Log.WithName(ControllerName)
)

// Add creates a new Experiment Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
Expand All @@ -60,8 +64,9 @@ func Add(mgr manager.Manager) error {
// newReconciler returns a new reconcile.Reconciler
func newReconciler(mgr manager.Manager) reconcile.Reconciler {
r := &ReconcileExperiment{
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
recorder: mgr.GetRecorder(ControllerName),
}
imp := viper.GetString(consts.ConfigExperimentSuggestionName)
r.Suggestion = newSuggestion(imp, mgr.GetScheme(), mgr.GetClient())
Expand Down Expand Up @@ -147,7 +152,8 @@ var _ reconcile.Reconciler = &ReconcileExperiment{}
// ReconcileExperiment reconciles a Experiment object
type ReconcileExperiment struct {
client.Client
scheme *runtime.Scheme
scheme *runtime.Scheme
recorder record.EventRecorder

suggestion.Suggestion
manifest.Generator
Expand Down Expand Up @@ -181,9 +187,7 @@ func (r *ReconcileExperiment) Reconcile(request reconcile.Request) (reconcile.Re
}

if instance.IsCompleted() && !instance.HasRunningTrials() {

return reconcile.Result{}, nil

}
if !instance.IsCreated() {
if instance.Status.StartTime == nil {
Expand All @@ -199,6 +203,9 @@ func (r *ReconcileExperiment) Reconcile(request reconcile.Request) (reconcile.Re
err := r.ReconcileExperiment(instance)
if err != nil {
logger.Error(err, "Reconcile experiment error")
r.recorder.Eventf(instance,
corev1.EventTypeWarning, ReconcileFailedReason,
"Failed to reconcile: %v", err)
return reconcile.Result{}, err
}
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/controller.v1alpha3/trial/trial_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ var (
log = logf.Log.WithName(ControllerName)
)

/**
* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller
* business logic. Delete these comments after modifying this file.*
*/

// Add creates a new Trial Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
Expand Down

0 comments on commit d93b602

Please sign in to comment.