mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
k8s: Log errors when contacting the API server
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
// These constants are keys used in node metadata
|
||||
@@ -31,6 +33,17 @@ type client struct {
|
||||
serviceStore *cache.StoreToServiceLister
|
||||
}
|
||||
|
||||
// runReflectorUntil is equivalent to cache.Reflector.RunUntil, but it also logs
|
||||
// errors, which cache.Reflector.RunUntil simply ignores
|
||||
func runReflectorUntil(r *cache.Reflector, resyncPeriod time.Duration, stopCh <-chan struct{}) {
|
||||
loggingListAndWatch := func() {
|
||||
if err := r.ListAndWatch(stopCh); err != nil {
|
||||
log.Printf("Kubernetes reflector error: %v", err)
|
||||
}
|
||||
}
|
||||
go util.Until(loggingListAndWatch, resyncPeriod, stopCh)
|
||||
}
|
||||
|
||||
// NewClient returns a usable Client. Don't forget to Stop it.
|
||||
func NewClient(addr string, resyncPeriod time.Duration) (Client, error) {
|
||||
var config *unversioned.Config
|
||||
@@ -61,8 +74,8 @@ func NewClient(addr string, resyncPeriod time.Duration) (Client, error) {
|
||||
serviceReflector := cache.NewReflector(serviceListWatch, &api.Service{}, serviceStore, resyncPeriod)
|
||||
|
||||
quit := make(chan struct{})
|
||||
podReflector.RunUntil(quit)
|
||||
serviceReflector.RunUntil(quit)
|
||||
runReflectorUntil(podReflector, resyncPeriod, quit)
|
||||
runReflectorUntil(serviceReflector, resyncPeriod, quit)
|
||||
|
||||
return &client{
|
||||
quit: quit,
|
||||
|
||||
Reference in New Issue
Block a user