mirror of
https://github.com/valitydev/botkube.git
synced 2024-11-06 16:35:22 +00:00
Issue #27: Added filter to add warning if pod is created without any labels
This commit is contained in:
parent
22883ef37b
commit
e518cb538c
@ -15,6 +15,7 @@ var (
|
||||
Filters = []Filter{
|
||||
filters.NewImageTagChecker(),
|
||||
filters.NewIngressValidator(),
|
||||
filters.NewPodLabelChecker(),
|
||||
}
|
||||
)
|
||||
|
||||
|
34
pkg/filterengine/filters/pod_label_checker.go
Normal file
34
pkg/filterengine/filters/pod_label_checker.go
Normal file
@ -0,0 +1,34 @@
|
||||
package filters
|
||||
|
||||
import (
|
||||
"github.com/infracloudio/botkube/pkg/events"
|
||||
log "github.com/infracloudio/botkube/pkg/logging"
|
||||
|
||||
apiV1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
// PodLabelChecker add recommendations to the event object if pod created without any labels
|
||||
type PodLabelChecker struct {
|
||||
}
|
||||
|
||||
// NewPodLabelChecker creates new PodLabelChecker object
|
||||
func NewPodLabelChecker() *PodLabelChecker {
|
||||
return &PodLabelChecker{}
|
||||
}
|
||||
|
||||
// Run filters and modifies event struct
|
||||
func (f *PodLabelChecker) Run(object interface{}, event *events.Event) {
|
||||
if event.Kind != "Pod" && event.Type != "create" {
|
||||
return
|
||||
}
|
||||
podObj, ok := object.(*apiV1.Pod)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// Check labels in pod
|
||||
if len(podObj.ObjectMeta.Labels) == 0 {
|
||||
event.Recommendations = append(event.Recommendations, "pod '"+podObj.ObjectMeta.Name+"' creation without labels should be avoided.\n")
|
||||
}
|
||||
log.Logger.Debug("Pod label filter successful!")
|
||||
}
|
Loading…
Reference in New Issue
Block a user