本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/cache.NewListWatchFromClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewListWatchFromClient函数的具体用法?Golang NewListWatchFromClient怎么用?Golang NewListWatchFromClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewListWatchFromClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewSourceAPI
// NewSourceAPIserver creates config source that watches for changes to the services and endpoints.
func NewSourceAPI(c *client.Client, period time.Duration, servicesChan chan<- ServiceUpdate, endpointsChan chan<- EndpointsUpdate) {
servicesLW := cache.NewListWatchFromClient(c, "services", api.NamespaceAll, fields.Everything())
endpointsLW := cache.NewListWatchFromClient(c, "endpoints", api.NamespaceAll, fields.Everything())
newServicesSourceApiFromLW(servicesLW, period, servicesChan)
newEndpointsSourceApiFromLW(endpointsLW, period, endpointsChan)
}
开发者ID:previousnext,项目名称:kube-ingress,代码行数:8,代码来源:api.go
示例2: NewClient
// NewClient returns a usable Client. Don't forget to Stop it.
func NewClient(addr string, resyncPeriod time.Duration) (Client, error) {
c, err := unversioned.New(&unversioned.Config{Host: addr})
if err != nil {
return nil, err
}
podListWatch := cache.NewListWatchFromClient(c, "pods", api.NamespaceAll, fields.Everything())
podStore := cache.NewStore(cache.MetaNamespaceKeyFunc)
podReflector := cache.NewReflector(podListWatch, &api.Pod{}, podStore, resyncPeriod)
serviceListWatch := cache.NewListWatchFromClient(c, "services", api.NamespaceAll, fields.Everything())
serviceStore := cache.NewStore(cache.MetaNamespaceKeyFunc)
serviceReflector := cache.NewReflector(serviceListWatch, &api.Service{}, serviceStore, resyncPeriod)
quit := make(chan struct{})
podReflector.RunUntil(quit)
serviceReflector.RunUntil(quit)
return &client{
quit: quit,
client: c,
podReflector: podReflector,
podStore: &cache.StoreToPodLister{Store: podStore},
serviceReflector: serviceReflector,
serviceStore: &cache.StoreToServiceLister{Store: serviceStore},
}, nil
}
开发者ID:hrhelena,项目名称:scope,代码行数:28,代码来源:client.go
示例3: newIPVSController
// newIPVSController creates a new controller from the given config.
func newIPVSController(kubeClient *unversioned.Client, namespace string, useUnicast bool, password string) *ipvsControllerController {
ipvsc := ipvsControllerController{
client: kubeClient,
queue: workqueue.New(),
reloadRateLimiter: util.NewTokenBucketRateLimiter(reloadQPS, int(reloadQPS)),
reloadLock: &sync.Mutex{},
}
clusterNodes := getClusterNodesIP(kubeClient)
nodeInfo, err := getNodeInfo(clusterNodes)
if err != nil {
glog.Fatalf("Error getting local IP from nodes in the cluster: %v", err)
}
neighbors := getNodeNeighbors(nodeInfo, clusterNodes)
ipvsc.keepalived = &keepalived{
iface: nodeInfo.iface,
ip: nodeInfo.ip,
netmask: nodeInfo.netmask,
nodes: clusterNodes,
neighbors: neighbors,
priority: getNodePriority(nodeInfo.ip, clusterNodes),
useUnicast: useUnicast,
password: password,
}
enqueue := func(obj interface{}) {
key, err := keyFunc(obj)
if err != nil {
glog.Infof("Couldn't get key for object %+v: %v", obj, err)
return
}
ipvsc.queue.Add(key)
}
eventHandlers := framework.ResourceEventHandlerFuncs{
AddFunc: enqueue,
DeleteFunc: enqueue,
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
enqueue(cur)
}
},
}
ipvsc.svcLister.Store, ipvsc.svcController = framework.NewInformer(
cache.NewListWatchFromClient(
ipvsc.client, "services", namespace, fields.Everything()),
&api.Service{}, resyncPeriod, eventHandlers)
ipvsc.epLister.Store, ipvsc.epController = framework.NewInformer(
cache.NewListWatchFromClient(
ipvsc.client, "endpoints", namespace, fields.Everything()),
&api.Endpoints{}, resyncPeriod, eventHandlers)
return &ipvsc
}
开发者ID:thockin,项目名称:contrib,代码行数:61,代码来源:controller.go
示例4: NewSourceAPI
// NewSourceAPI creates config source that watches for changes to the services and endpoints.
func NewSourceAPI(c cache.Getter, period time.Duration, servicesChan chan<- ServiceUpdate, endpointsChan chan<- EndpointsUpdate) {
servicesLW := cache.NewListWatchFromClient(c, "services", api.NamespaceAll, fields.Everything())
cache.NewReflector(servicesLW, &api.Service{}, NewServiceStore(nil, servicesChan), period).Run()
endpointsLW := cache.NewListWatchFromClient(c, "endpoints", api.NamespaceAll, fields.Everything())
cache.NewReflector(endpointsLW, &api.Endpoints{}, NewEndpointsStore(nil, endpointsChan), period).Run()
}
开发者ID:40a,项目名称:bootkube,代码行数:8,代码来源:api.go
示例5: newLoadBalancerController
// newLoadBalancerController creates a new controller from the given config.
func newLoadBalancerController(cfg *loadBalancerConfig, kubeClient *unversioned.Client, namespace string) *loadBalancerController {
lbc := loadBalancerController{
cfg: cfg,
client: kubeClient,
queue: workqueue.New(),
reloadRateLimiter: util.NewTokenBucketRateLimiter(
reloadQPS, int(reloadQPS)),
targetService: *targetService,
forwardServices: *forwardServices,
httpPort: *httpPort,
tcpServices: map[string]int{},
}
for _, service := range strings.Split(*tcpServices, ",") {
portSplit := strings.Split(service, ":")
if len(portSplit) != 2 {
glog.Errorf("Ignoring misconfigured TCP service %v", service)
continue
}
if port, err := strconv.Atoi(portSplit[1]); err != nil {
glog.Errorf("Ignoring misconfigured TCP service %v: %v", service, err)
continue
} else {
lbc.tcpServices[portSplit[0]] = port
}
}
enqueue := func(obj interface{}) {
key, err := keyFunc(obj)
if err != nil {
glog.Infof("Couldn't get key for object %+v: %v", obj, err)
return
}
lbc.queue.Add(key)
}
eventHandlers := framework.ResourceEventHandlerFuncs{
AddFunc: enqueue,
DeleteFunc: enqueue,
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
enqueue(cur)
}
},
}
lbc.svcLister.Store, lbc.svcController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "services", namespace, fields.Everything()),
&api.Service{}, resyncPeriod, eventHandlers)
lbc.epLister.Store, lbc.epController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "endpoints", namespace, fields.Everything()),
&api.Endpoints{}, resyncPeriod, eventHandlers)
return &lbc
}
开发者ID:remoe,项目名称:contrib,代码行数:58,代码来源:service_loadbalancer.go
示例6: newIPVSController
// newIPVSController creates a new controller from the given config.
func newIPVSController(kubeClient *unversioned.Client, namespace string, useUnicast bool, configMapName string) *ipvsControllerController {
ipvsc := ipvsControllerController{
client: kubeClient,
reloadRateLimiter: util.NewTokenBucketRateLimiter(reloadQPS, int(reloadQPS)),
ruCfg: []vip{},
configMapName: configMapName,
}
clusterNodes := getClusterNodesIP(kubeClient)
nodeInfo, err := getNodeInfo(clusterNodes)
if err != nil {
glog.Fatalf("Error getting local IP from nodes in the cluster: %v", err)
}
neighbors := getNodeNeighbors(nodeInfo, clusterNodes)
execer := exec.New()
dbus := utildbus.New()
iptInterface := utiliptables.New(execer, dbus, utiliptables.ProtocolIpv4)
ipvsc.keepalived = &keepalived{
iface: nodeInfo.iface,
ip: nodeInfo.ip,
netmask: nodeInfo.netmask,
nodes: clusterNodes,
neighbors: neighbors,
priority: getNodePriority(nodeInfo.ip, clusterNodes),
useUnicast: useUnicast,
ipt: iptInterface,
}
err = ipvsc.keepalived.loadTemplate()
if err != nil {
glog.Fatalf("Error loading keepalived template: %v", err)
}
eventHandlers := framework.ResourceEventHandlerFuncs{}
ipvsc.svcLister.Store, ipvsc.svcController = framework.NewInformer(
cache.NewListWatchFromClient(
ipvsc.client, "services", namespace, fields.Everything()),
&api.Service{}, resyncPeriod, eventHandlers)
ipvsc.epLister.Store, ipvsc.epController = framework.NewInformer(
cache.NewListWatchFromClient(
ipvsc.client, "endpoints", namespace, fields.Everything()),
&api.Endpoints{}, resyncPeriod, eventHandlers)
return &ipvsc
}
开发者ID:jojimt,项目名称:contrib,代码行数:52,代码来源:controller.go
示例7: newPodsApi
func newPodsApi(client *kclient.Client) podsApi {
// Extend the selector to include specific nodes to monitor
// or provide an API to update the nodes to monitor.
selector, err := kSelector.ParseSelector("spec.nodeName!=")
if err != nil {
panic(err)
}
lw := kcache.NewListWatchFromClient(client, "pods", kapi.NamespaceAll, selector)
podLister := &kcache.StoreToPodLister{Store: kcache.NewStore(kcache.MetaNamespaceKeyFunc)}
// Watch and cache all running pods.
reflector := kcache.NewReflector(lw, &kapi.Pod{}, podLister.Store, 0)
stopChan := make(chan struct{})
reflector.RunUntil(stopChan)
nStore, nController := kframework.NewInformer(
createNamespaceLW(client),
&kapi.Namespace{},
resyncPeriod,
kframework.ResourceEventHandlerFuncs{})
go nController.Run(util.NeverStop)
podsApi := &realPodsApi{
client: client,
podLister: podLister,
stopChan: stopChan,
reflector: reflector,
namespaceStore: nStore,
}
return podsApi
}
开发者ID:naxhh,项目名称:heapster,代码行数:31,代码来源:pods.go
示例8: NewKubeletProvider
func NewKubeletProvider(uri *url.URL) (MetricsSourceProvider, error) {
// create clients
kubeConfig, kubeletConfig, err := GetKubeConfigs(uri)
if err != nil {
return nil, err
}
kubeClient := kube_client.NewOrDie(kubeConfig)
kubeletClient, err := NewKubeletClient(kubeletConfig)
if err != nil {
return nil, err
}
// Get nodes to test if the client is configured well. Watch gives less error information.
if _, err := kubeClient.Nodes().List(kube_api.ListOptions{
LabelSelector: labels.Everything(),
FieldSelector: fields.Everything()}); err != nil {
glog.Errorf("Failed to load nodes: %v", err)
}
// watch nodes
lw := cache.NewListWatchFromClient(kubeClient, "nodes", kube_api.NamespaceAll, fields.Everything())
nodeLister := &cache.StoreToNodeLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}
reflector := cache.NewReflector(lw, &kube_api.Node{}, nodeLister.Store, time.Hour)
reflector.Run()
return &kubeletProvider{
nodeLister: nodeLister,
reflector: reflector,
kubeletClient: kubeletClient,
}, nil
}
开发者ID:caesarxuchao,项目名称:heapster,代码行数:31,代码来源:kubelet.go
示例9: RunEventQueue
// Run event queue for the given resource
func (registry *Registry) RunEventQueue(resourceName ResourceName) *oscache.EventQueue {
var client cache.Getter
var expectedType interface{}
switch resourceName {
case HostSubnets:
expectedType = &osapi.HostSubnet{}
client = registry.oClient
case NetNamespaces:
expectedType = &osapi.NetNamespace{}
client = registry.oClient
case Nodes:
expectedType = &kapi.Node{}
client = registry.kClient
case Namespaces:
expectedType = &kapi.Namespace{}
client = registry.kClient
case Services:
expectedType = &kapi.Service{}
client = registry.kClient
case Pods:
expectedType = &kapi.Pod{}
client = registry.kClient
default:
log.Fatalf("Unknown resource %s during initialization of event queue", resourceName)
}
lw := cache.NewListWatchFromClient(client, strings.ToLower(string(resourceName)), kapi.NamespaceAll, fields.Everything())
eventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
// Repopulate event queue every 30 mins
// Existing items in the event queue will have watch.Modified event type
cache.NewReflector(lw, expectedType, eventQueue, 30*time.Minute).Run()
return eventQueue
}
开发者ID:Xmagicer,项目名称:origin,代码行数:35,代码来源:registry.go
示例10: getNodeLister
func getNodeLister(kubeClient *kube_client.Client) (*cache.StoreToNodeLister, error) {
lw := cache.NewListWatchFromClient(kubeClient, "nodes", kube_api.NamespaceAll, fields.Everything())
nodeLister := &cache.StoreToNodeLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}
reflector := cache.NewReflector(lw, &kube_api.Node{}, nodeLister.Store, time.Hour)
reflector.Run()
return nodeLister, nil
}
开发者ID:kubernetes,项目名称:heapster,代码行数:7,代码来源:heapster.go
示例11: runEventQueue
// Run event queue for the given resource
func (registry *Registry) runEventQueue(resourceName string) *oscache.EventQueue {
var client cache.Getter
var expectedType interface{}
switch strings.ToLower(resourceName) {
case "hostsubnets":
expectedType = &osapi.HostSubnet{}
client = registry.oClient
case "netnamespaces":
expectedType = &osapi.NetNamespace{}
client = registry.oClient
case "nodes":
expectedType = &kapi.Node{}
client = registry.kClient
case "namespaces":
expectedType = &kapi.Namespace{}
client = registry.kClient
case "services":
expectedType = &kapi.Service{}
client = registry.kClient
case "pods":
expectedType = &kapi.Pod{}
client = registry.kClient
default:
log.Fatalf("Unknown resource %s during initialization of event queue", resourceName)
}
lw := cache.NewListWatchFromClient(client, strings.ToLower(resourceName), kapi.NamespaceAll, fields.Everything())
eventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
cache.NewReflector(lw, expectedType, eventQueue, 0).Run()
return eventQueue
}
开发者ID:iconoeugen,项目名称:origin,代码行数:33,代码来源:registry.go
示例12: getPodLister
func getPodLister(kubeClient *kube_client.Client) (*cache.StoreToPodLister, error) {
lw := cache.NewListWatchFromClient(kubeClient, "pods", kube_api.NamespaceAll, fields.Everything())
store := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
podLister := &cache.StoreToPodLister{Indexer: store}
reflector := cache.NewReflector(lw, &kube_api.Pod{}, store, time.Hour)
reflector.Run()
return podLister, nil
}
开发者ID:kubernetes,项目名称:heapster,代码行数:8,代码来源:heapster.go
示例13: NewNodeLister
// NewNodeLister builds a node lister.
func NewNodeLister(kubeClient client.Interface) *ReadyNodeLister {
listWatcher := cache.NewListWatchFromClient(kubeClient.Core().RESTClient(), "nodes", apiv1.NamespaceAll, fields.Everything())
nodeLister := &cache.StoreToNodeLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}
reflector := cache.NewReflector(listWatcher, &apiv1.Node{}, nodeLister.Store, time.Hour)
reflector.Run()
return &ReadyNodeLister{
nodeLister: nodeLister,
}
}
开发者ID:kubernetes,项目名称:contrib,代码行数:10,代码来源:listers.go
示例14: NewNodeLister
// NewNodeLister builds a node lister.
func NewNodeLister(kubeClient *kube_client.Client) *ReadyNodeLister {
listWatcher := cache.NewListWatchFromClient(kubeClient, "nodes", kube_api.NamespaceAll, fields.Everything())
nodeLister := &cache.StoreToNodeLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}
reflector := cache.NewReflector(listWatcher, &kube_api.Node{}, nodeLister.Store, time.Hour)
reflector.Run()
return &ReadyNodeLister{
nodeLister: nodeLister,
}
}
开发者ID:spxtr,项目名称:contrib,代码行数:10,代码来源:listers.go
示例15: newLoadBalancerController
// newLoadBalancerController creates a new controller from the given config.
func newLoadBalancerController(cfg *loadBalancerConfig, kubeClient *unversioned.Client, namespace string, tcpServices map[string]int) *loadBalancerController {
lbc := loadBalancerController{
cfg: cfg,
client: kubeClient,
queue: workqueue.New(),
reloadRateLimiter: util.NewTokenBucketRateLimiter(
reloadQPS, int(reloadQPS)),
targetService: *targetService,
forwardServices: *forwardServices,
httpPort: *httpPort,
tcpServices: tcpServices,
}
enqueue := func(obj interface{}) {
key, err := keyFunc(obj)
if err != nil {
glog.Infof("Couldn't get key for object %+v: %v", obj, err)
return
}
lbc.queue.Add(key)
}
eventHandlers := framework.ResourceEventHandlerFuncs{
AddFunc: enqueue,
DeleteFunc: enqueue,
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
enqueue(cur)
}
},
}
lbc.svcLister.Store, lbc.svcController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "services", namespace, fields.Everything()),
&api.Service{}, resyncPeriod, eventHandlers)
lbc.epLister.Store, lbc.epController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "endpoints", namespace, fields.Everything()),
&api.Endpoints{}, resyncPeriod, eventHandlers)
return &lbc
}
开发者ID:PDKK,项目名称:contrib,代码行数:44,代码来源:service_loadbalancer.go
示例16: Run
// Run starts a background goroutine that watches for changes to services that
// have (or had) LoadBalancers=true and ensures that they have
// load balancers created and deleted appropriately.
// serviceSyncPeriod controls how often we check the cluster's services to
// ensure that the correct load balancers exist.
// nodeSyncPeriod controls how often we check the cluster's nodes to determine
// if load balancers need to be updated to point to a new set.
//
// It's an error to call Run() more than once for a given ServiceController
// object.
func (s *ServiceController) Run(workers int) {
defer runtime.HandleCrash()
go s.serviceController.Run(wait.NeverStop)
for i := 0; i < workers; i++ {
go wait.Until(s.worker, time.Second, wait.NeverStop)
}
nodeLW := cache.NewListWatchFromClient(s.kubeClient.Core().RESTClient(), "nodes", v1.NamespaceAll, fields.Everything())
cache.NewReflector(nodeLW, &v1.Node{}, s.nodeLister.Store, 0).Run()
go wait.Until(s.nodeSyncLoop, nodeSyncPeriod, wait.NeverStop)
}
开发者ID:fejta,项目名称:kubernetes,代码行数:20,代码来源:servicecontroller.go
示例17: NewCachedServiceAccessor
// NewCachedServiceAccessor returns a service accessor that can answer queries about services.
// It uses a backing cache to make ClusterIP lookups efficient.
func NewCachedServiceAccessor(client cache.Getter, stopCh <-chan struct{}) ServiceAccessor {
accessor, store := NewCachedServiceAccessorAndStore()
lw := cache.NewListWatchFromClient(client, "services", api.NamespaceAll, fields.Everything())
reflector := cache.NewReflector(lw, &api.Service{}, store, 30*time.Minute)
if stopCh != nil {
reflector.RunUntil(stopCh)
} else {
reflector.Run()
}
return accessor
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:13,代码来源:serviceaccessor.go
示例18: NewClient
// NewClient returns a usable Client. Don't forget to Stop it.
func NewClient(addr string, resyncPeriod time.Duration) (Client, error) {
var config *unversioned.Config
if addr != "" {
config = &unversioned.Config{Host: addr}
} else {
// If no API server address was provided, assume we are running
// inside a pod. Try to connect to the API server through its
// Service environment variables, using the default Service
// Account Token.
var err error
if config, err = unversioned.InClusterConfig(); err != nil {
return nil, err
}
}
c, err := unversioned.New(config)
if err != nil {
return nil, err
}
podListWatch := cache.NewListWatchFromClient(c, "pods", api.NamespaceAll, fields.Everything())
podStore := cache.NewStore(cache.MetaNamespaceKeyFunc)
podReflector := cache.NewReflector(podListWatch, &api.Pod{}, podStore, resyncPeriod)
serviceListWatch := cache.NewListWatchFromClient(c, "services", api.NamespaceAll, fields.Everything())
serviceStore := cache.NewStore(cache.MetaNamespaceKeyFunc)
serviceReflector := cache.NewReflector(serviceListWatch, &api.Service{}, serviceStore, resyncPeriod)
quit := make(chan struct{})
runReflectorUntil(podReflector, resyncPeriod, quit)
runReflectorUntil(serviceReflector, resyncPeriod, quit)
return &client{
quit: quit,
client: c,
podReflector: podReflector,
podStore: &cache.StoreToPodLister{Store: podStore},
serviceReflector: serviceReflector,
serviceStore: &cache.StoreToServiceLister{Store: serviceStore},
}, nil
}
开发者ID:pauloheck,项目名称:scope,代码行数:42,代码来源:client.go
示例19: runEventQueueForResource
// Run event queue for the given resource. The 'process' function is called
// repeatedly with each available cache.Delta that describes state changes
// to an object. If the process function returns an error queued changes
// for that object are dropped but processing continues with the next available
// object's cache.Deltas. The error is logged with call stack information.
func runEventQueueForResource(client kcache.Getter, resourceName ResourceName, expectedType interface{}, selector fields.Selector, process ProcessEventFunc) {
rn := strings.ToLower(string(resourceName))
lw := kcache.NewListWatchFromClient(client, rn, kapi.NamespaceAll, selector)
eventQueue := NewEventQueue(kcache.MetaNamespaceKeyFunc)
// Repopulate event queue every 30 mins
// Existing items in the event queue will have watch.Modified event type
kcache.NewReflector(lw, expectedType, eventQueue, 30*time.Minute).Run()
// Run the queue
for {
eventQueue.Pop(process)
}
}
开发者ID:pweil-,项目名称:origin,代码行数:18,代码来源:common.go
示例20: NewUnscheduledPodLister
// NewUnscheduledPodLister returns a lister providing pods that failed to be scheduled.
func NewUnscheduledPodLister(kubeClient *kube_client.Client) *UnscheduledPodLister {
// watch unscheduled pods
selector := fields.ParseSelectorOrDie("spec.nodeName==" + "" + ",status.phase!=" +
string(kube_api.PodSucceeded) + ",status.phase!=" + string(kube_api.PodFailed))
podListWatch := cache.NewListWatchFromClient(kubeClient, "pods", kube_api.NamespaceAll, selector)
podLister := &cache.StoreToPodLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}
podReflector := cache.NewReflector(podListWatch, &kube_api.Pod{}, podLister.Store, time.Hour)
podReflector.Run()
return &UnscheduledPodLister{
podLister: podLister,
}
}
开发者ID:jojimt,项目名称:contrib,代码行数:14,代码来源:utils.go
注:本文中的k8s/io/kubernetes/pkg/client/cache.NewListWatchFromClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论