func (m *ReconcilePod) NeedLeaderElection() bool {
	return true
}
NeedLeaderElection need election
package pod
import (
	"context"
	"fmt"
	"time"
	"github.com/AliyunContainerService/terway/pkg/aliyun"
	"github.com/AliyunContainerService/terway/pkg/apis/network.alibabacloud.com/v1beta1"
	register "github.com/AliyunContainerService/terway/pkg/controller"
	"github.com/AliyunContainerService/terway/pkg/controller/common"
	"github.com/AliyunContainerService/terway/pkg/controller/vswitch"
	"github.com/AliyunContainerService/terway/pkg/utils"
	"github.com/AliyunContainerService/terway/types"
	"github.com/spf13/viper"
	corev1 "k8s.io/api/core/v1"
	k8sErr "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	k8stypes "k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/util/sets"
	"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"
	"sigs.k8s.io/controller-runtime/pkg/log"
	"sigs.k8s.io/controller-runtime/pkg/manager"
	"sigs.k8s.io/controller-runtime/pkg/predicate"
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
	"sigs.k8s.io/controller-runtime/pkg/source"
)
const controllerName = "pod"
func init() {
	register.Add(controllerName, func(mgr manager.Manager, aliyunClient *aliyun.OpenAPI, swPool *vswitch.SwitchPool) error {
		r := NewReconcilePod(mgr, aliyunClient, swPool)
		c, err := controller.NewUnmanaged(controllerName, mgr, controller.Options{
			Reconciler:              r,
			MaxConcurrentReconciles: viper.GetInt("podeni-max-concurrent-reconciles"),
		})
		if err != nil {
			return err
		}
		w := &Wrapper{
			ctrl: c,
			r:    r,
		}
		err = mgr.Add(w)
		if err != nil {
			return err
		}
		return c.Watch(
			&source.Kind{
				Type: &corev1.Pod{},
			},
			&handler.EnqueueRequestForObject{},
			&predicate.ResourceVersionChangedPredicate{},
			&predicateForPodEvent{},
		)
	})
}
var _ reconcile.Reconciler = &ReconcilePod{}
type ReconcilePod struct {
	client client.Client
	scheme *runtime.Scheme
	aliyun *aliyun.OpenAPI
	swPool *vswitch.SwitchPool
	record record.EventRecorder
}
type Wrapper struct {
	ctrl controller.Controller
	r    *ReconcilePod
}
func (w *Wrapper) Start(ctx context.Context) error {
	err := w.ctrl.Start(ctx)
	if err != nil {
		return err
	}
	<-ctx.Done()
	return nil
}
func (w *Wrapper) NeedLeaderElection() bool {
	return true
}
func NewReconcilePod(mgr manager.Manager, aliyunClient *aliyun.OpenAPI, swPool *vswitch.SwitchPool) *ReconcilePod {
	r := &ReconcilePod{
		client: mgr.GetClient(),
		scheme: mgr.GetScheme(),
		record: mgr.GetEventRecorderFor("Pod"),
		aliyun: aliyunClient,
		swPool: swPool,
	}
	return r
}
func (m *ReconcilePod) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
	l := log.FromContext(ctx)
	l.V(5).Info("Reconcile")
	pod := &corev1.Pod{}
	err := m.client.Get(context.Background(), request.NamespacedName, pod)
	if err != nil {
		if k8sErr.IsNotFound(err) {
			return m.podDelete(ctx, request.NamespacedName)
		}
		return reconcile.Result{}, err
	}
	if utils.IsJobPod(pod) {
		if utils.PodSandboxExited(pod) {
			return m.podDelete(ctx, request.NamespacedName)
		}
	}
	if !pod.DeletionTimestamp.IsZero() {
		return reconcile.Result{RequeueAfter: 2 * time.Second}, nil
	}
	return m.podCreate(ctx, pod)
}