func newNodeWatch(parent *watcher) *watch {
	w := newWatch(parent, "Node", namespace(""),
		func(ns namespace, name string) (k8swatch.Interface, error) {
			selector := meta_v1.ListOptions{FieldSelector: "metadata.name=" + name}
			k8w, err := parent.k8sCli.CoreV1().Nodes().Watch(context.TODO(), selector)
			if err != nil {
				return nil, err
			}
			return k8w, nil
		},
		func(ns namespace, name string) (interface{}, error) {
			noopts := meta_v1.GetOptions{}
			node, err := parent.k8sCli.CoreV1().Nodes().Get(context.TODO(), name, noopts)
			if err != nil {
				return nil, err
			}
			return node, nil
		})
	w.Start(nodeName)
	return w
}
newNodeWatch creates a watch for k8s Node
package agent
import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"time"
	core_v1 "k8s.io/api/core/v1"
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/types"
	k8swatch "k8s.io/apimachinery/pkg/watch"
	k8sclient "k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/clientcmd"
	resmgr "github.com/intel/cri-resource-manager/pkg/apis/resmgr/generated/clientset/versioned/typed/resmgr/v1alpha1"
	agent_v1 "github.com/intel/cri-resource-manager/pkg/agent/api/v1"
)
type namespace string
var nodeName string
func (a *agent) getK8sClient(kubeconfig string) (*k8sclient.Clientset, *resmgr.CriresmgrV1alpha1Client, error) {
	var config *rest.Config
	var err error
	if kubeconfig == "" {
		a.Info("using in-cluster kubeconfig")
		config, err = rest.InClusterConfig()
	} else {
		config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
	}
	if err != nil {
		return nil, nil, err
	}
	genCli, err := k8sclient.NewForConfig(config)
	if err != nil {
		return nil, nil, err
	}
	resmgr, err := resmgr.NewForConfig(config)
	if err != nil {
		return nil, nil, err
	}
	return genCli, resmgr, nil
}
func getNodeObject(cli *k8sclient.Clientset) (*core_v1.Node, error) {
	node, err := cli.CoreV1().Nodes().Get(context.TODO(), nodeName, meta_v1.GetOptions{})
	if err != nil {
		return nil, agentError("failed to get node object for node %q: %v", nodeName, err)
	}
	return node, nil
}
func patchNode(cli *k8sclient.Clientset, patchList []*agent_v1.JsonPatch) error {
	data, err := json.Marshal(patchList)
	if err != nil {
		return agentError("failed to marshal Node patches: %v", err)
	}
	pt := types.JSONPatchType
	_, err = cli.CoreV1().Nodes().Patch(context.TODO(), nodeName, pt, data, meta_v1.PatchOptions{})
	if err != nil {
		return err
	}
	return nil
}
func patchNodeStatus(cli *k8sclient.Clientset, fields map[string]string) error {
	patch, sep := fmt.Sprintf(`{"status": {`), ""
	for f, v := range fields {
		patch += sep + fmt.Sprintf(`"%s": %s`, f, v)
		sep = ","
	}
	patch += "}}"
	_, err := cli.CoreV1().Nodes().PatchStatus(context.TODO(), nodeName, []byte(patch))
	return err
}
func patchAdjustmentStatus(cli *resmgr.CriresmgrV1alpha1Client, status *resmgrStatus, names ...string) error {
	return nil
}
type watch struct {
	parent  *watcher
	kind    string
	ns      namespace
	name    string
	openfn  func(namespace, string) (k8swatch.Interface, error)
	queryfn func(namespace, string) (interface{}, error)
	stop    chan struct{}
	events  chan k8swatch.Event
}
type openFn func(ns namespace, name string) (k8swatch.Interface, error)
type queryFn func(ns namespace, name string) (interface{}, error)
const (
	SyntheticMissing = k8swatch.EventType("SyntheticMissing")
)
func newWatch(parent *watcher, kind string, ns namespace, open openFn, query queryFn) *watch {
	return &watch{
		parent:  parent,
		kind:    kind,
		ns:      ns,
		stop:    make(chan struct{}),
		events:  make(chan k8swatch.Event),
		openfn:  open,
		queryfn: query,
	}
}