github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/metrics/util/util.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package util 16 17 import ( 18 "time" 19 20 kube_api "k8s.io/api/core/v1" 21 "k8s.io/apimachinery/pkg/fields" 22 "k8s.io/apimachinery/pkg/util/wait" 23 kube_client "k8s.io/client-go/kubernetes" 24 v1listers "k8s.io/client-go/listers/core/v1" 25 "k8s.io/client-go/tools/cache" 26 ) 27 28 func GetNodeLister(kubeClient *kube_client.Clientset) (v1listers.NodeLister, *cache.Reflector, error) { 29 lw := cache.NewListWatchFromClient(kubeClient.CoreV1().RESTClient(), "nodes", kube_api.NamespaceAll, fields.Everything()) 30 store := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) 31 nodeLister := v1listers.NewNodeLister(store) 32 reflector := cache.NewReflector(lw, &kube_api.Node{}, store, time.Hour) 33 go reflector.Run(wait.NeverStop) 34 35 return nodeLister, reflector, nil 36 }