File tree 9 files changed +112
-13
lines changed
9 files changed +112
-13
lines changed Original file line number Diff line number Diff line change 6
6
which glide || go get -u github.com/Masterminds/glide
7
7
8
8
lint :
9
- gometalinter -j 1 --vendor --disable-all \
10
- --enable=errcheck \
9
+ gometalinter --concurrency=1 --deadline=120s --vendor --disable-all \
11
10
--enable=vet \
12
11
--enable=vetshadow \
12
+ --enable=errcheck \
13
13
--enable=structcheck \
14
14
--enable=aligncheck \
15
15
--enable=deadcode \
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ kube-alert monitors:
6
6
* Pod failures (unschedulables, error pulling images, crashloop backoff, etc.)
7
7
* Pods restarts
8
8
* Cluster's components status (issues with etcd, scheduler, or controller-manager daemons)
9
+ * Nodes status (out-of-disk, memory pressure, network unavailable, ...)
9
10
10
11
Support alerting to Datadog and to logs (ie. syslog).
11
12
Original file line number Diff line number Diff line change @@ -22,12 +22,13 @@ func (c *CsController) HandlerName() string {
22
22
}
23
23
24
24
func (c * CsController ) Init (conf * config.AlertConfig , handler handlers.Handler ) controllers.Controller {
25
- c .CommonController = controllers.CommonController {}
26
- c .Conf = conf
27
- c .Handler = handler
25
+ c .CommonController = controllers.CommonController {
26
+ Conf : conf ,
27
+ Handler : handler ,
28
+ Name : "componentstatus" ,
29
+ }
28
30
29
31
client := c .Conf .ClientSet
30
- c .Name = "componentstatus"
31
32
c .ObjType = & v1.ComponentStatus {}
32
33
c .ListWatch = & cache.ListWatch {
33
34
ListFunc : func (options meta_v1.ListOptions ) (runtime.Object , error ) {
Original file line number Diff line number Diff line change
1
+ package node
2
+
3
+ import (
4
+ "github.com/bpineau/kube-alert/config"
5
+ "github.com/bpineau/kube-alert/pkg/controllers"
6
+ "github.com/bpineau/kube-alert/pkg/handlers"
7
+
8
+ meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
+ "k8s.io/apimachinery/pkg/runtime"
10
+ "k8s.io/apimachinery/pkg/watch"
11
+ "k8s.io/client-go/pkg/api/v1"
12
+ "k8s.io/client-go/tools/cache"
13
+ )
14
+
15
+ type NodeController struct {
16
+ // https://golang.org/doc/effective_go.html#embedding
17
+ controllers.CommonController
18
+ }
19
+
20
+ func (c * NodeController ) HandlerName () string {
21
+ return "node"
22
+ }
23
+
24
+ func (c * NodeController ) Init (conf * config.AlertConfig , handler handlers.Handler ) controllers.Controller {
25
+ c .CommonController = controllers.CommonController {
26
+ Conf : conf ,
27
+ Handler : handler ,
28
+ Name : "node" ,
29
+ }
30
+
31
+ client := c .Conf .ClientSet
32
+ c .ObjType = & v1.Node {}
33
+ c .ListWatch = & cache.ListWatch {
34
+ ListFunc : func (options meta_v1.ListOptions ) (runtime.Object , error ) {
35
+ return client .CoreV1 ().Nodes ().List (options )
36
+ },
37
+ WatchFunc : func (options meta_v1.ListOptions ) (watch.Interface , error ) {
38
+ return client .CoreV1 ().Nodes ().Watch (options )
39
+ },
40
+ }
41
+
42
+ return c
43
+ }
Original file line number Diff line number Diff line change @@ -22,12 +22,13 @@ func (c *PodController) HandlerName() string {
22
22
}
23
23
24
24
func (c * PodController ) Init (conf * config.AlertConfig , handler handlers.Handler ) controllers.Controller {
25
- c .CommonController = controllers.CommonController {}
26
- c .Conf = conf
27
- c .Handler = handler
25
+ c .CommonController = controllers.CommonController {
26
+ Conf : conf ,
27
+ Handler : handler ,
28
+ Name : "pod" ,
29
+ }
28
30
29
31
client := c .Conf .ClientSet
30
- c .Name = "pod"
31
32
c .ObjType = & v1.Pod {}
32
33
c .ListWatch = & cache.ListWatch {
33
34
ListFunc : func (options meta_v1.ListOptions ) (runtime.Object , error ) {
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ func (h *CsHandler) Init(c *config.AlertConfig) error {
20
20
func (h * CsHandler ) ObjectCreated (obj interface {}) (bool , string ) {
21
21
cs , _ := obj .(* v1.ComponentStatus )
22
22
23
+ if cs == nil || cs .Conditions == nil {
24
+ return true , ""
25
+ }
26
+
23
27
for _ , c := range cs .Conditions {
24
28
if c .Type != "Healthy" {
25
29
continue
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package handlers
3
3
import (
4
4
"github.com/bpineau/kube-alert/config"
5
5
"github.com/bpineau/kube-alert/pkg/handlers/cs"
6
+ "github.com/bpineau/kube-alert/pkg/handlers/node"
6
7
"github.com/bpineau/kube-alert/pkg/handlers/pod"
7
8
)
8
9
@@ -13,6 +14,7 @@ type Handler interface {
13
14
}
14
15
15
16
var Handlers = map [string ]Handler {
16
- "pod" : & pod.PodHandler {},
17
- "cs" : & cs.CsHandler {},
17
+ "cs" : & cs.CsHandler {},
18
+ "pod" : & pod.PodHandler {},
19
+ "node" : & node.NodeHandler {},
18
20
}
Original file line number Diff line number Diff line change
1
+ package node
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "github.com/bpineau/kube-alert/config"
7
+ "k8s.io/client-go/pkg/api/v1"
8
+ )
9
+
10
+ type NodeHandler struct {
11
+ conf * config.AlertConfig
12
+ }
13
+
14
+ var knownBadConditions = map [string ]bool {
15
+ "OutOfDisk" : true ,
16
+ "MemoryPressure" : true ,
17
+ "DiskPressure" : true ,
18
+ "NetworkUnavailable" : true ,
19
+ }
20
+
21
+ func (n * NodeHandler ) Init (c * config.AlertConfig ) error {
22
+ c .Logger .Info ("node handler initialized" )
23
+ n .conf = c
24
+ return nil
25
+ }
26
+
27
+ func (n * NodeHandler ) ObjectCreated (obj interface {}) (bool , string ) {
28
+ node , _ := obj .(* v1.Node )
29
+
30
+ for _ , c := range node .Status .Conditions {
31
+ if c .Status == "False" {
32
+ continue
33
+ }
34
+
35
+ if knownBadConditions [string (c .Type )] {
36
+ return false , fmt .Sprintf ("Node %s is unhealthy: %s" , node .Name , c .Message )
37
+ }
38
+ }
39
+
40
+ return true , ""
41
+ }
42
+
43
+ func (n * NodeHandler ) ObjectDeleted (obj interface {}) (bool , string ) {
44
+ return true , ""
45
+ }
Original file line number Diff line number Diff line change @@ -8,14 +8,16 @@ import (
8
8
"github.com/bpineau/kube-alert/config"
9
9
"github.com/bpineau/kube-alert/pkg/controllers"
10
10
"github.com/bpineau/kube-alert/pkg/controllers/cs"
11
+ "github.com/bpineau/kube-alert/pkg/controllers/node"
11
12
"github.com/bpineau/kube-alert/pkg/controllers/pod"
12
13
"github.com/bpineau/kube-alert/pkg/handlers"
13
14
"github.com/bpineau/kube-alert/pkg/health"
14
15
)
15
16
16
17
var Controllers = []controllers.Controller {
17
- & pod.PodController {},
18
18
& cs.CsController {},
19
+ & pod.PodController {},
20
+ & node.NodeController {},
19
21
}
20
22
21
23
func Run (config * config.AlertConfig ) {
You can’t perform that action at this time.
0 commit comments