func getEventRecorder() record.EventRecorder {
	eventBroadcaster := record.NewBroadcaster()
	eventBroadcaster.StartRecordingToSink(
		&typedcorev1.EventSinkImpl{
			Interface: ClientSet().CoreV1().Events(""),
		},
	)
	operatorName, _ := k8sutil.GetOperatorName()
	recorder := eventBroadcaster.NewRecorder(
		scheme.Scheme,
		corev1.EventSource{Component: operatorName},
	)
	return recorder
}
eventRecorder returns an EventRecorder type that can be
used to post Events to different object's lifecycles.
package shared
import (
	"context"
	"os"
	"github.com/operator-framework/operator-sdk/pkg/k8sutil"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/kubernetes/scheme"
	typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/record"
	"sigs.k8s.io/controller-runtime/pkg/cache"
	k8sClient "sigs.k8s.io/controller-runtime/pkg/client"
	k8sConfig "sigs.k8s.io/controller-runtime/pkg/client/config"
	logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)
var (
	config *rest.Config
	client k8sClient.Client
	directClient k8sClient.Client
	clientSet kubernetes.Interface
	eventRecorder record.EventRecorder
	log = logf.Log.WithName("kubedirector")
)
func init() {
	config = getConfigFromServiceAccount()
	client = getClient(config)
	directClient = getClient(config)
	clientSet = getClientSet(config)
	eventRecorder = getEventRecorder()
}
func getClientSet(
	config *rest.Config,
) kubernetes.Interface {
	clientset, err := kubernetes.NewForConfig(config)
	if err != nil {
		log.Error(err, "getClientSet")
		os.Exit(1)
	}
	return clientset
}
func getConfigFromServiceAccount() *rest.Config {
	config, err := k8sConfig.GetConfig()
	if err != nil {
		log.Error(err, "getConfigFromServiceAccount")
		os.Exit(1)
	}
	return config
}