func NewController(config *daemonconfig.Configuration,
	hybridnetInformerFactory hybridnetinformer.SharedInformerFactory,
	kubeInformerFactory informers.SharedInformerFactory) (*Controller, error) {
	subnetInformer := hybridnetInformerFactory.Networking().V1().Subnets()
	networkInformer := hybridnetInformerFactory.Networking().V1().Networks()
	ipInstanceInformer := hybridnetInformerFactory.Networking().V1().IPInstances()
	nodeInformer := kubeInformerFactory.Core().V1().Nodes()
	routeV4Manager, err := route.CreateRouteManager(config.LocalDirectTableNum,
		config.ToOverlaySubnetTableNum,
		config.OverlayMarkTableNum,
		netlink.FAMILY_V4,
	)
	if err != nil {
		return nil, fmt.Errorf("create ipv4 route manager error: %v", err)
	}
	routeV6Manager, err := route.CreateRouteManager(config.LocalDirectTableNum,
		config.ToOverlaySubnetTableNum,
		config.OverlayMarkTableNum,
		netlink.FAMILY_V6,
	)
	if err != nil {
		return nil, fmt.Errorf("create ipv6 route manager error: %v", err)
	}
	neighV4Manager := neigh.CreateNeighManager(netlink.FAMILY_V4)
	neighV6Manager := neigh.CreateNeighManager(netlink.FAMILY_V6)
	iptablesV4Manager, err := iptables.CreateIPtablesManager(iptables.ProtocolIpv4)
	if err != nil {
		return nil, fmt.Errorf("create ipv4 iptables manager error: %v", err)
	}
	iptablesV6Manager, err := iptables.CreateIPtablesManager(iptables.ProtocolIpv6)
	if err != nil {
		return nil, fmt.Errorf("create ipv6 iptables manager error: %v", err)
	}
	addrV4Manager := addr.CreateAddrManager(netlink.FAMILY_V4, config.NodeName)
	if err := ipInstanceInformer.Informer().GetIndexer().AddIndexers(cache.Indexers{
		ByInstanceIPIndexer: indexByInstanceIP,
	}); err != nil {
		return nil, fmt.Errorf("add indexer to ip instance informer failed: %v", err)
	}
	controller := &Controller{
		subnetLister: subnetInformer.Lister(),
		subnetSynced: subnetInformer.Informer().HasSynced,
		subnetQueue:  workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Subnet"),
		networkLister: networkInformer.Lister(),
		networkSynced: networkInformer.Informer().HasSynced,
		ipInstanceLister:  ipInstanceInformer.Lister(),
		ipInstanceSynced:  ipInstanceInformer.Informer().HasSynced,
		ipInstanceQueue:   workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "IPInstance"),
		ipInstanceIndexer: ipInstanceInformer.Informer().GetIndexer(),
		nodeLister: nodeInformer.Lister(),
		nodeSynced: nodeInformer.Informer().HasSynced,
		nodeQueue:  workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Node"),
		config: config,
		routeV4Manager: routeV4Manager,
		routeV6Manager: routeV6Manager,
		neighV4Manager: neighV4Manager,
		neighV6Manager: neighV6Manager,
		addrV4Manager: addrV4Manager,
		iptablesV4Manager:  iptablesV4Manager,
		iptablesV6Manager:  iptablesV6Manager,
		iptablesSyncCh:     make(chan struct{}, 1),
		iptablesSyncTicker: time.NewTicker(config.IptablesCheckDuration),
		nodeIPCache: NewNodeIPCache(),
	}
	_, err = config.KubeClient.CoreV1().Nodes().Get(context.TODO(), config.NodeName, metav1.GetOptions{})
	if err != nil {
		return nil, fmt.Errorf("failed to get node %s info %v", config.NodeName, err)
	}
	networkInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc:    controller.enqueueAddOrDeleteNetwork,
		DeleteFunc: controller.enqueueAddOrDeleteNetwork,
		UpdateFunc: controller.enqueueUpdateNetwork,
	})
	subnetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc:    controller.enqueueAddOrDeleteSubnet,
		DeleteFunc: controller.enqueueAddOrDeleteSubnet,
		UpdateFunc: controller.enqueueUpdateSubnet,
	})
	ipInstanceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc:    controller.enqueueAddOrDeleteIPInstance,
		UpdateFunc: controller.enqueueUpdateIPInstance,
		DeleteFunc: controller.enqueueAddOrDeleteIPInstance,
	})
	nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc:    controller.enqueueAddOrDeleteNode,
		UpdateFunc: controller.enqueueUpdateNode,
		DeleteFunc: controller.enqueueAddOrDeleteNode,
	})
	return controller, nil
}
NewController returns a Controller to watch kubernetes CRD object events
package controller
import (
	"context"
	"fmt"
	"net"
	"net/http"
	"strings"
	"syscall"
	"time"
	"github.com/alibaba/hybridnet/pkg/daemon/addr"
	"github.com/vishvananda/netns"
	"github.com/alibaba/hybridnet/pkg/daemon/iptables"
	networkingv1 "github.com/alibaba/hybridnet/pkg/apis/networking/v1"
	hybridnetinformer "github.com/alibaba/hybridnet/pkg/client/informers/externalversions"
	networkinglister "github.com/alibaba/hybridnet/pkg/client/listers/networking/v1"
	"github.com/alibaba/hybridnet/pkg/constants"
	daemonconfig "github.com/alibaba/hybridnet/pkg/daemon/config"
	"github.com/alibaba/hybridnet/pkg/daemon/containernetwork"
	"github.com/alibaba/hybridnet/pkg/daemon/neigh"
	"github.com/alibaba/hybridnet/pkg/daemon/route"
	"github.com/heptiolabs/healthcheck"
	"github.com/vishvananda/netlink"
	"golang.org/x/sys/unix"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/client-go/informers"
	corev1 "k8s.io/client-go/listers/core/v1"
	"k8s.io/client-go/tools/cache"
	"k8s.io/client-go/util/workqueue"
	"k8s.io/klog"
)
const (
	ActionReconcileSubnet     = "ReconcileSubnet"
	ActionReconcileIPInstance = "ReconcileIPInstance"
	ActionReconcileNode       = "ReconcileNode"
	ByInstanceIPIndexer = "instanceIP"
)
type Controller struct {
	subnetLister networkinglister.SubnetLister
	subnetSynced cache.InformerSynced
	subnetQueue  workqueue.RateLimitingInterface
	ipInstanceLister  networkinglister.IPInstanceLister
	ipInstanceSynced  cache.InformerSynced
	ipInstanceQueue   workqueue.RateLimitingInterface
	ipInstanceIndexer cache.Indexer
	networkLister networkinglister.NetworkLister
	networkSynced cache.InformerSynced
	nodeLister corev1.NodeLister
	nodeSynced cache.InformerSynced
	nodeQueue  workqueue.RateLimitingInterface
	config *daemonconfig.Configuration
	routeV4Manager *route.Manager
	routeV6Manager *route.Manager
	neighV4Manager *neigh.Manager
	neighV6Manager *neigh.Manager
	addrV4Manager *addr.Manager
	iptablesV4Manager  *iptables.Manager
	iptablesV6Manager  *iptables.Manager
	iptablesSyncCh     chan struct{}
	iptablesSyncTicker *time.Ticker
	nodeIPCache *NodeIPCache
	upgradeWorkDone bool
}