func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
	r.record = event.NewAPIRecorder(mgr.GetEventRecorderFor("Autoscaler")).
		WithAnnotations("controller", "Autoscaler")
	return ctrl.NewControllerManagedBy(mgr).
		For(&v1alpha1.Autoscaler{}).
		Complete(r)
}
SetupWithManager will setup with event recorder
package controllers
import (
	"context"
	"fmt"
	"time"
	cpv1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
	"github.com/crossplane/crossplane-runtime/pkg/event"
	"github.com/go-logr/logr"
	"github.com/pkg/errors"
	"k8s.io/apimachinery/pkg/runtime"
	ctrl "sigs.k8s.io/controller-runtime"
	"sigs.k8s.io/controller-runtime/pkg/client"
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
	"github.com/oam-dev/catalog/traits/autoscalertrait/api/v1alpha1"
	"github.com/oam-dev/kubevela/pkg/controller/common"
	"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
	"github.com/oam-dev/kubevela/pkg/oam/util"
)
const (
	SpecWarningTargetWorkloadNotSet         = "Spec.targetWorkload is not set"
	SpecWarningStartAtTimeFormat            = "startAt is not in the right format, which should be like `12:01`"
	SpecWarningStartAtTimeRequired          = "spec.triggers.condition.startAt: Required value"
	SpecWarningDurationTimeRequired         = "spec.triggers.condition.duration: Required value"
	SpecWarningReplicasRequired             = "spec.triggers.condition.replicas: Required value"
	SpecWarningDurationTimeNotInRightFormat = "spec.triggers.condition.duration: not in the right format"
)
var ReconcileWaitResult = reconcile.Result{RequeueAfter: 30 * time.Second}
type Reconciler struct {
	client.Client
	dm     discoverymapper.DiscoveryMapper
	Log    logr.Logger
	Scheme *runtime.Scheme
	record event.Recorder
}
func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
	log := r.Log.WithValues("autoscaler", req.NamespacedName)
	log.Info("Reconciling Autoscaler...")
	ctx := context.Background()
	var scaler v1alpha1.Autoscaler
	if err := r.Get(ctx, req.NamespacedName, &scaler); err != nil {
		log.Error(err, "Failed to get trait", "traitName", scaler.Name)
		return ReconcileWaitResult, client.IgnoreNotFound(err)
	}
	log.Info("Retrieved trait Autoscaler", "APIVersion", scaler.APIVersion, "Kind", scaler.Kind)
	ctx = util.SetNamespaceInCtx(ctx, scaler.Namespace)
	eventObj, err := util.LocateParentAppConfig(ctx, r.Client, &scaler)
	if err != nil {
		log.Error(err, "Failed to find the parent resource", "Autoscaler", scaler.Name)
		return util.ReconcileWaitResult, util.PatchCondition(ctx, r, &scaler,
			cpv1alpha1.ReconcileError(fmt.Errorf(util.ErrLocateAppConfig)))
	}
	if eventObj == nil {
		log.Info("There is no parent resource", "Autoscaler", scaler.Name)
		eventObj = &scaler
	}
	workload, err := util.FetchWorkload(ctx, r, log, &scaler)
	if err != nil {
		log.Error(err, "Error while fetching the workload", "workload reference",
			scaler.GetWorkloadReference())
		r.record.Event(&scaler, event.Warning(common.ErrLocatingWorkload, err))
		return util.ReconcileWaitResult,
			util.PatchCondition(ctx, r, &scaler,
				cpv1alpha1.ReconcileError(errors.Wrap(err, common.ErrLocatingWorkload)))
	}
	resources, err := util.FetchWorkloadChildResources(ctx, log, r, r.dm, workload)
	if err != nil {
		log.Error(err, "Error while fetching the workload child resources", "workload", workload.UnstructuredContent())
		r.record.Event(eventObj, event.Warning(util.ErrFetchChildResources, err))
		return util.ReconcileWaitResult, util.PatchCondition(ctx, r, &scaler,
			cpv1alpha1.ReconcileError(fmt.Errorf(util.ErrFetchChildResources)))
	}
	resources = append(resources, workload)
	targetWorkloadSetFlag := false
	for _, res := range resources {
		if res.GetKind() == "Deployment" || res.GetKind() == "StatefulSet" || res.GetKind() == "DaemonSet" || res.GetKind() == "ReplicaSet" {
			scaler.Spec.TargetWorkload = v1alpha1.TargetWorkload{
				APIVersion: res.GetAPIVersion(),
				Kind:       res.GetKind(),
				Name:       res.GetName(),
			}
			targetWorkloadSetFlag = true
			break
		}
	}
	if !targetWorkloadSetFlag {
		scaler.Spec.TargetWorkload = v1alpha1.TargetWorkload{
			APIVersion: workload.GetAPIVersion(),
			Kind:       workload.GetKind(),
			Name:       workload.GetName(),
		}
	}
	namespace := req.NamespacedName.Namespace
	if err := r.scaleByKEDA(scaler, namespace, log); err != nil {
		return ReconcileWaitResult, err
	}
	return ctrl.Result{}, nil
}