This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 445
/
controller.go
698 lines (607 loc) · 20.4 KB
/
controller.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/*
Copyright 2016 Skippbox, Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package controller
import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/bitnami-labs/kubewatch/config"
"github.com/bitnami-labs/kubewatch/pkg/event"
"github.com/bitnami-labs/kubewatch/pkg/handlers"
"github.com/bitnami-labs/kubewatch/pkg/utils"
"github.com/sirupsen/logrus"
apps_v1 "k8s.io/api/apps/v1"
batch_v1 "k8s.io/api/batch/v1"
api_v1 "k8s.io/api/core/v1"
ext_v1beta1 "k8s.io/api/extensions/v1beta1"
rbac_v1beta1 "k8s.io/api/rbac/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
)
const maxRetries = 5
var serverStartTime time.Time
// Event indicate the informerEvent
type Event struct {
key string
eventType string
namespace string
resourceType string
}
// Controller object
type Controller struct {
logger *logrus.Entry
clientset kubernetes.Interface
queue workqueue.RateLimitingInterface
informer cache.SharedIndexInformer
eventHandler handlers.Handler
}
// Start prepares watchers and run their controllers, then waits for process termination signals
func Start(conf *config.Config, eventHandler handlers.Handler) {
var kubeClient kubernetes.Interface
if _, err := rest.InClusterConfig(); err != nil {
kubeClient = utils.GetClientOutOfCluster()
} else {
kubeClient = utils.GetClient()
}
// Adding Default Critical Alerts
// For Capturing Critical Event NodeNotReady in Nodes
nodeNotReadyInformer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
options.FieldSelector = "involvedObject.kind=Node,type=Normal,reason=NodeNotReady"
return kubeClient.CoreV1().Events(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
options.FieldSelector = "involvedObject.kind=Node,type=Normal,reason=NodeNotReady"
return kubeClient.CoreV1().Events(conf.Namespace).Watch(options)
},
},
&api_v1.Event{},
0, //Skip resync
cache.Indexers{},
)
nodeNotReadyController := newResourceController(kubeClient, eventHandler, nodeNotReadyInformer, "NodeNotReady")
stopNodeNotReadyCh := make(chan struct{})
defer close(stopNodeNotReadyCh)
go nodeNotReadyController.Run(stopNodeNotReadyCh)
// For Capturing Critical Event NodeReady in Nodes
nodeReadyInformer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
options.FieldSelector = "involvedObject.kind=Node,type=Normal,reason=NodeReady"
return kubeClient.CoreV1().Events(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
options.FieldSelector = "involvedObject.kind=Node,type=Normal,reason=NodeReady"
return kubeClient.CoreV1().Events(conf.Namespace).Watch(options)
},
},
&api_v1.Event{},
0, //Skip resync
cache.Indexers{},
)
nodeReadyController := newResourceController(kubeClient, eventHandler, nodeReadyInformer, "NodeReady")
stopNodeReadyCh := make(chan struct{})
defer close(stopNodeReadyCh)
go nodeReadyController.Run(stopNodeReadyCh)
// For Capturing Critical Event NodeRebooted in Nodes
nodeRebootedInformer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
options.FieldSelector = "involvedObject.kind=Node,type=Warning,reason=Rebooted"
return kubeClient.CoreV1().Events(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
options.FieldSelector = "involvedObject.kind=Node,type=Warning,reason=Rebooted"
return kubeClient.CoreV1().Events(conf.Namespace).Watch(options)
},
},
&api_v1.Event{},
0, //Skip resync
cache.Indexers{},
)
nodeRebootedController := newResourceController(kubeClient, eventHandler, nodeRebootedInformer, "NodeRebooted")
stopNodeRebootedCh := make(chan struct{})
defer close(stopNodeRebootedCh)
go nodeRebootedController.Run(stopNodeRebootedCh)
// User Configured Events
if conf.Resource.Pod {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().Pods(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().Pods(conf.Namespace).Watch(options)
},
},
&api_v1.Pod{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "pod")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
// For Capturing CrashLoopBackOff Events in pods
backoffInformer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
options.FieldSelector = "involvedObject.kind=Pod,type=Warning,reason=BackOff"
return kubeClient.CoreV1().Events(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
options.FieldSelector = "involvedObject.kind=Pod,type=Warning,reason=BackOff"
return kubeClient.CoreV1().Events(conf.Namespace).Watch(options)
},
},
&api_v1.Event{},
0, //Skip resync
cache.Indexers{},
)
backoffcontroller := newResourceController(kubeClient, eventHandler, backoffInformer, "Backoff")
stopBackoffCh := make(chan struct{})
defer close(stopBackoffCh)
go backoffcontroller.Run(stopBackoffCh)
}
if conf.Resource.DaemonSet {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.AppsV1().DaemonSets(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.AppsV1().DaemonSets(conf.Namespace).Watch(options)
},
},
&apps_v1.DaemonSet{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "daemon set")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.ReplicaSet {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.AppsV1().ReplicaSets(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.AppsV1().ReplicaSets(conf.Namespace).Watch(options)
},
},
&apps_v1.ReplicaSet{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "replica set")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.Services {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().Services(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().Services(conf.Namespace).Watch(options)
},
},
&api_v1.Service{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "service")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.Deployment {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.AppsV1().Deployments(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.AppsV1().Deployments(conf.Namespace).Watch(options)
},
},
&apps_v1.Deployment{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "deployment")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.Namespace {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().Namespaces().List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().Namespaces().Watch(options)
},
},
&api_v1.Namespace{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "namespace")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.ReplicationController {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().ReplicationControllers(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().ReplicationControllers(conf.Namespace).Watch(options)
},
},
&api_v1.ReplicationController{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "replication controller")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.Job {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.BatchV1().Jobs(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.BatchV1().Jobs(conf.Namespace).Watch(options)
},
},
&batch_v1.Job{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "job")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.Node {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().Nodes().List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().Nodes().Watch(options)
},
},
&api_v1.Node{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "node")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.ServiceAccount {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().ServiceAccounts(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().ServiceAccounts(conf.Namespace).Watch(options)
},
},
&api_v1.ServiceAccount{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "service account")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.ClusterRole {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.RbacV1beta1().ClusterRoles().List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.RbacV1beta1().ClusterRoles().Watch(options)
},
},
&rbac_v1beta1.ClusterRole{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "cluster role")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.PersistentVolume {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().PersistentVolumes().List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().PersistentVolumes().Watch(options)
},
},
&api_v1.PersistentVolume{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "persistent volume")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.Secret {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().Secrets(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().Secrets(conf.Namespace).Watch(options)
},
},
&api_v1.Secret{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "secret")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.ConfigMap {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().ConfigMaps(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().ConfigMaps(conf.Namespace).Watch(options)
},
},
&api_v1.ConfigMap{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "configmap")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
if conf.Resource.Ingress {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.ExtensionsV1beta1().Ingresses(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.ExtensionsV1beta1().Ingresses(conf.Namespace).Watch(options)
},
},
&ext_v1beta1.Ingress{},
0, //Skip resync
cache.Indexers{},
)
c := newResourceController(kubeClient, eventHandler, informer, "ingress")
stopCh := make(chan struct{})
defer close(stopCh)
go c.Run(stopCh)
}
sigterm := make(chan os.Signal, 1)
signal.Notify(sigterm, syscall.SIGTERM)
signal.Notify(sigterm, syscall.SIGINT)
<-sigterm
}
func newResourceController(client kubernetes.Interface, eventHandler handlers.Handler, informer cache.SharedIndexInformer, resourceType string) *Controller {
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())
var newEvent Event
var err error
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
newEvent.key, err = cache.MetaNamespaceKeyFunc(obj)
newEvent.eventType = "create"
newEvent.resourceType = resourceType
logrus.WithField("pkg", "kubewatch-"+resourceType).Infof("Processing add to %v: %s", resourceType, newEvent.key)
if err == nil {
queue.Add(newEvent)
}
},
UpdateFunc: func(old, new interface{}) {
newEvent.key, err = cache.MetaNamespaceKeyFunc(old)
newEvent.eventType = "update"
newEvent.resourceType = resourceType
logrus.WithField("pkg", "kubewatch-"+resourceType).Infof("Processing update to %v: %s", resourceType, newEvent.key)
if err == nil {
queue.Add(newEvent)
}
},
DeleteFunc: func(obj interface{}) {
newEvent.key, err = cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
newEvent.eventType = "delete"
newEvent.resourceType = resourceType
newEvent.namespace = utils.GetObjectMetaData(obj).Namespace
logrus.WithField("pkg", "kubewatch-"+resourceType).Infof("Processing delete to %v: %s", resourceType, newEvent.key)
if err == nil {
queue.Add(newEvent)
}
},
})
return &Controller{
logger: logrus.WithField("pkg", "kubewatch-"+resourceType),
clientset: client,
informer: informer,
queue: queue,
eventHandler: eventHandler,
}
}
// Run starts the kubewatch controller
func (c *Controller) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
defer c.queue.ShutDown()
c.logger.Info("Starting kubewatch controller")
serverStartTime = time.Now().Local()
go c.informer.Run(stopCh)
if !cache.WaitForCacheSync(stopCh, c.HasSynced) {
utilruntime.HandleError(fmt.Errorf("Timed out waiting for caches to sync"))
return
}
c.logger.Info("Kubewatch controller synced and ready")
wait.Until(c.runWorker, time.Second, stopCh)
}
// HasSynced is required for the cache.Controller interface.
func (c *Controller) HasSynced() bool {
return c.informer.HasSynced()
}
// LastSyncResourceVersion is required for the cache.Controller interface.
func (c *Controller) LastSyncResourceVersion() string {
return c.informer.LastSyncResourceVersion()
}
func (c *Controller) runWorker() {
for c.processNextItem() {
// continue looping
}
}
func (c *Controller) processNextItem() bool {
newEvent, quit := c.queue.Get()
if quit {
return false
}
defer c.queue.Done(newEvent)
err := c.processItem(newEvent.(Event))
if err == nil {
// No error, reset the ratelimit counters
c.queue.Forget(newEvent)
} else if c.queue.NumRequeues(newEvent) < maxRetries {
c.logger.Errorf("Error processing %s (will retry): %v", newEvent.(Event).key, err)
c.queue.AddRateLimited(newEvent)
} else {
// err != nil and too many retries
c.logger.Errorf("Error processing %s (giving up): %v", newEvent.(Event).key, err)
c.queue.Forget(newEvent)
utilruntime.HandleError(err)
}
return true
}
/* TODOs
- Enhance event creation using client-side cacheing machanisms - pending
- Enhance the processItem to classify events - done
- Send alerts correspoding to events - done
*/
func (c *Controller) processItem(newEvent Event) error {
obj, _, err := c.informer.GetIndexer().GetByKey(newEvent.key)
if err != nil {
return fmt.Errorf("Error fetching object with key %s from store: %v", newEvent.key, err)
}
// get object's metedata
objectMeta := utils.GetObjectMetaData(obj)
// hold status type for default critical alerts
var status string
// namespace retrived from event key incase namespace value is empty
if newEvent.namespace == "" && strings.Contains(newEvent.key, "/") {
substring := strings.Split(newEvent.key, "/")
newEvent.namespace = substring[0]
newEvent.key = substring[1]
}
// process events based on its type
switch newEvent.eventType {
case "create":
// compare CreationTimestamp and serverStartTime and alert only on latest events
// Could be Replaced by using Delta or DeltaFIFO
if objectMeta.CreationTimestamp.Sub(serverStartTime).Seconds() > 0 {
switch newEvent.resourceType {
case "NodeNotReady":
status = "Danger"
case "NodeReady":
status = "Normal"
case "NodeRebooted":
status = "Danger"
case "Backoff":
status = "Danger"
default:
status = "Normal"
}
kbEvent := event.Event{
Name: objectMeta.Name,
Namespace: newEvent.namespace,
Kind: newEvent.resourceType,
Status: status,
Reason: "Created",
}
c.eventHandler.Handle(kbEvent)
return nil
}
case "update":
/* TODOs
- enahace update event processing in such a way that, it send alerts about what got changed.
*/
switch newEvent.resourceType {
case "Backoff":
status = "Danger"
default:
status = "Warning"
}
kbEvent := event.Event{
Name: newEvent.key,
Namespace: newEvent.namespace,
Kind: newEvent.resourceType,
Status: status,
Reason: "Updated",
}
c.eventHandler.Handle(kbEvent)
return nil
case "delete":
kbEvent := event.Event{
Name: newEvent.key,
Namespace: newEvent.namespace,
Kind: newEvent.resourceType,
Status: "Danger",
Reason: "Deleted",
}
c.eventHandler.Handle(kbEvent)
return nil
}
return nil
}