/
cs.go
49 lines (42 loc) · 1.39 KB
/
cs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cs
import (
"github.com/bpineau/kube-alert/config"
"github.com/bpineau/kube-alert/pkg/controllers"
"github.com/bpineau/kube-alert/pkg/handlers"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/tools/cache"
)
type CsController struct {
// https://golang.org/doc/effective_go.html#embedding
controllers.CommonController
}
func (c *CsController) HandlerName() string {
return "cs"
}
func (c *CsController) Init(conf *config.AlertConfig, handler handlers.Handler) controllers.Controller {
c.CommonController = controllers.CommonController{
Conf: conf,
Handler: handler,
Name: "componentstatus",
}
client := c.Conf.ClientSet
c.ObjType = &v1.ComponentStatus{}
c.ListWatch = &cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return client.CoreV1().ComponentStatuses().List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
//Apparently this resource does not support watch :
// "Failed to watch *v1.ComponentStatus: the server does not allow
// this method on the requested resource (get componentstatuses)"
//So we'll only see errors at resync intervals.
//return client.CoreV1().ComponentStatuses().Watch(options)
fw := watch.NewFake()
return fw, nil
},
}
return c
}