8000 🎉 feature: select namespaces you want to hear from by Andrew44Ashraf · Pull Request #17 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.0.7/deploy/

#### General

| Parameter | Description |
|:-------------------------------------|:------------------------------------------- |
| `maxRecentLogLines` | optional Max tail log lines in messages |
| Parameter | Description |
|:-------------------------------------|:-----------------------------------------------------------------------------------------------------|
| `maxRecentLogLines` | Optional Max tail log lines in messages, if it's not provided it will get all log lines |
| `namespaces` | Optional list of namespaces that you want to watch, if it's not provided it will watch all namespaces|


#### Slack

Expand Down
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ alert:
integrationKey: ""
discord:
webhook: ""
namespaces:
- default

8 changes: 7 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"errors"
"fmt"
"github.com/spf13/viper"
"time"

"github.com/abahmed/kwatch/constant"
Expand Down Expand Up @@ -114,7 +115,12 @@ func (c *Controller) processItem(key string) error {
// to avoid re-queuing it
return nil
}

// filer by namespaces in config
namespaces := viper.GetStringSlice("namespaces")
if len(namespaces) != 0 && !util.IsStrInSlice(pod.Namespace, namespaces) {
logrus.Info(pod.Namespace, "skip namespace %s as not selected in configuration")
return nil
}
for _, container := range pod.Status.ContainerStatuses {
// filter running containers
if container.Ready ||
Expand Down
6 changes: 5 additions & 1 deletion deploy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ data:
pagerduty:
integrationKey: <integration_key>
discord:
webhook: <webhook_url>
webhook: <webhook_url>
namespaces:
- <optional_namespace>

:
15 changes: 15 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,18 @@ func SendProvidersEvent(p []provider.Provider, event event.Event) {
}
}
}

// IsStrInSlice checks if string is existing in a slice of string
func IsStrInSlice(str string, strList []string) bool {
if len(strList) == 0 {
return false
}

for _, s := range strList {
if s == str {
return true
}
}

return false
}
0