Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #27: Added filter to add warning if pod created without label #48

Merged
merged 1 commit into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/filterengine/filterengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
Filters = []Filter{
filters.NewImageTagChecker(),
filters.NewIngressValidator(),
filters.NewPodLabelChecker(),
}
)

Expand Down
34 changes: 34 additions & 0 deletions pkg/filterengine/filters/pod_label_checker.go
Original file line number Diff line number Diff line change
@@ -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!")
}