Skip to content

Commit 07e4d4f

Browse files
authored
Merge pull request #30 from brancz/clientgo15
use kubernetes informer framework
2 parents 6c0afa1 + 9bbd1af commit 07e4d4f

948 files changed

Lines changed: 201364 additions & 14429 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Godeps/Godeps.json

Lines changed: 409 additions & 192 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package main
1919
import (
2020
"github.com/golang/glog"
2121
"github.com/prometheus/client_golang/prometheus"
22-
"k8s.io/client-go/1.4/pkg/apis/extensions/v1beta1"
22+
"k8s.io/client-go/1.5/pkg/apis/extensions/v1beta1"
2323
)
2424

2525
var (

deployment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
dto "github.com/prometheus/client_model/go"
2929
"github.com/prometheus/common/expfmt"
3030

31-
"k8s.io/client-go/1.4/pkg/api/v1"
32-
"k8s.io/client-go/1.4/pkg/apis/extensions/v1beta1"
31+
"k8s.io/client-go/1.5/pkg/api/v1"
32+
"k8s.io/client-go/1.5/pkg/apis/extensions/v1beta1"
3333
)
3434

3535
var (

main.go

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ import (
2626
"github.com/golang/glog"
2727
"github.com/openshift/origin/pkg/util/proc"
2828
flag "github.com/spf13/pflag"
29-
clientset "k8s.io/client-go/1.4/kubernetes"
30-
"k8s.io/client-go/1.4/pkg/api"
31-
"k8s.io/client-go/1.4/pkg/api/v1"
32-
"k8s.io/client-go/1.4/pkg/apis/extensions/v1beta1"
33-
"k8s.io/client-go/1.4/pkg/runtime"
34-
"k8s.io/client-go/1.4/pkg/watch"
35-
restclient "k8s.io/client-go/1.4/rest"
36-
"k8s.io/client-go/1.4/tools/cache"
37-
"k8s.io/client-go/1.4/tools/clientcmd"
29+
"golang.org/x/net/context"
30+
clientset "k8s.io/client-go/1.5/kubernetes"
31+
"k8s.io/client-go/1.5/pkg/api"
32+
"k8s.io/client-go/1.5/pkg/api/v1"
33+
"k8s.io/client-go/1.5/pkg/apis/extensions/v1beta1"
34+
restclient "k8s.io/client-go/1.5/rest"
35+
"k8s.io/client-go/1.5/tools/cache"
36+
"k8s.io/client-go/1.5/tools/clientcmd"
3837

3938
"github.com/prometheus/client_golang/prometheus"
4039
)
@@ -87,7 +86,7 @@ func main() {
8786
glog.Fatalf("Failed to create client: %v", err)
8887
}
8988

90-
initializeMetrics(kubeClient)
89+
initializeMetricCollection(kubeClient)
9190
metricsServer()
9291
}
9392

@@ -188,54 +187,36 @@ func (l NodeLister) List() (v1.NodeList, error) {
188187
return l()
189188
}
190189

191-
// initializeMetrics creates a new controller from the given config.
192-
func initializeMetrics(kubeClient clientset.Interface) {
193-
dplStore, dplController := cache.NewNamespaceKeyedIndexerAndReflector(
194-
&cache.ListWatch{
195-
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
196-
return kubeClient.Extensions().Deployments(api.NamespaceAll).List(options)
197-
},
198-
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
199-
return kubeClient.Extensions().Deployments(api.NamespaceAll).Watch(options)
200-
},
201-
}, &v1beta1.Deployment{}, resyncPeriod)
202-
203-
podStore, podController := cache.NewNamespaceKeyedIndexerAndReflector(
204-
cache.NewListWatchFromClient(
205-
kubeClient.Core().GetRESTClient(),
206-
"pods",
207-
api.NamespaceAll,
208-
nil,
209-
), &v1.Pod{}, resyncPeriod)
210-
211-
nodeStore, nodeController := cache.NewNamespaceKeyedIndexerAndReflector(
212-
cache.NewListWatchFromClient(
213-
kubeClient.Core().GetRESTClient(),
214-
"nodes",
215-
api.NamespaceAll,
216-
nil,
217-
), &v1.Node{}, resyncPeriod)
218-
219-
go dplController.Run()
220-
go podController.Run()
221-
go nodeController.Run()
190+
// initializeMetricCollection creates and starts informers and initializes and
191+
// registers metrics for collection.
192+
func initializeMetricCollection(kubeClient clientset.Interface) {
193+
cclient := kubeClient.Core().GetRESTClient()
194+
eclient := kubeClient.Extensions().GetRESTClient()
195+
196+
dlw := cache.NewListWatchFromClient(eclient, "deployments", api.NamespaceAll, nil)
197+
plw := cache.NewListWatchFromClient(cclient, "pods", api.NamespaceAll, nil)
198+
nlw := cache.NewListWatchFromClient(cclient, "nodes", api.NamespaceAll, nil)
199+
200+
dinf := cache.NewSharedInformer(dlw, &v1beta1.Deployment{}, resyncPeriod)
201+
pinf := cache.NewSharedInformer(plw, &v1.Pod{}, resyncPeriod)
202+
ninf := cache.NewSharedInformer(nlw, &v1.Node{}, resyncPeriod)
222203

223204
dplLister := DeploymentLister(func() (deployments []v1beta1.Deployment, err error) {
224-
for _, c := range dplStore.List() {
205+
for _, c := range dinf.GetStore().List() {
225206
deployments = append(deployments, *(c.(*v1beta1.Deployment)))
226207
}
227208
return deployments, nil
228209
})
229210

230211
podLister := PodLister(func() (pods []v1.Pod, err error) {
231-
for _, m := range podStore.List() {
212+
for _, m := range pinf.GetStore().List() {
232213
pods = append(pods, *m.(*v1.Pod))
233214
}
234215
return pods, nil
235216
})
236217

237218
nodeLister := NodeLister(func() (machines v1.NodeList, err error) {
238-
for _, m := range nodeStore.List() {
219+
for _, m := range ninf.GetStore().List() {
239220
machines.Items = append(machines.Items, *(m.(*v1.Node)))
240221
}
241222
return machines, nil
@@ -244,4 +225,8 @@ func initializeMetrics(kubeClient clientset.Interface) {
244225
prometheus.MustRegister(&deploymentCollector{store: dplLister})
245226
prometheus.MustRegister(&podCollector{store: podLister})
246227
prometheus.MustRegister(&nodeCollector{store: nodeLister})
228+
229+
go dinf.Run(context.Background().Done())
230+
go pinf.Run(context.Background().Done())
231+
go ninf.Run(context.Background().Done())
247232
}

node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package main
1919
import (
2020
"github.com/golang/glog"
2121
"github.com/prometheus/client_golang/prometheus"
22-
"k8s.io/client-go/1.4/pkg/api/v1"
22+
"k8s.io/client-go/1.5/pkg/api/v1"
2323
)
2424

2525
var (

node_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package main
1919
import (
2020
"testing"
2121

22-
"k8s.io/client-go/1.4/pkg/api/resource"
23-
"k8s.io/client-go/1.4/pkg/api/v1"
22+
"k8s.io/client-go/1.5/pkg/api/resource"
23+
"k8s.io/client-go/1.5/pkg/api/v1"
2424
)
2525

2626
type mockNodeStore struct {

pod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package main
1919
import (
2020
"github.com/golang/glog"
2121
"github.com/prometheus/client_golang/prometheus"
22-
"k8s.io/client-go/1.4/pkg/api/v1"
22+
"k8s.io/client-go/1.5/pkg/api/v1"
2323
)
2424

2525
var (

pod_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package main
1919
import (
2020
"testing"
2121

22-
"k8s.io/client-go/1.4/pkg/api/resource"
23-
"k8s.io/client-go/1.4/pkg/api/v1"
22+
"k8s.io/client-go/1.5/pkg/api/resource"
23+
"k8s.io/client-go/1.5/pkg/api/v1"
2424
)
2525

2626
type mockPodStore struct {

vendor/cloud.google.com/go/LICENSE

Lines changed: 202 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/PuerkitoBio/purell/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)