Skip to content
New issue

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

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

Already on GitHub? # to your account

added EXCLUDE_NAMESPACE functionality #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@ Configuration is done completely via environment variables.
| -- | -- |
| `SENTRY_DSN` | **Required** DSN for a Sentry project. |
| `SENTRY_ENVIRONMENT` | Environment for Sentry issues. If not set the namespace is used as environment. |
| `NAMESPACE` | Comma separated set of namespaces to minitor. If not set all namespaces are monitored (as far as permissions allow) |
| `NAMESPACE` | Comma separated set of namespaces to monitor. If not set all namespaces are monitored (as far as permissions allow) |
| `EXCLUDE_NAMESPACE` | Comma separated set of namespaces to not monitor. If `NAMESPACE` is also set, namespaces are excluded from that else from all namespaces|

## Issue grouping

44 changes: 39 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -67,11 +67,31 @@ func main() {
defaultEnvironment: os.Getenv("SENTRY_ENVIRONMENT"),
}

namespace := os.Getenv("NAMESPACE")
if namespace == "" {
app.namespaces = []string{v1.NamespaceAll}
} else {
app.namespaces = strings.Split(namespace, ",")
inNamespace := strings.Split(os.Getenv("NAMESPACE"), ",")
exNamespace := strings.Split(os.Getenv("EXCLUDE_NAMESPACE"), ",")
allNamespace := []string{v1.NamespaceAll}

switch len(inNamespace) {
// include all namespaces
case 0:
switch len(exNamespace) {
// exclude nothing
case 0:
app.namespaces = allNamespace
// exclude some
default:
app.namespaces = difference(allNamespace, exNamespace)
}
// include only some namespaces
default:
switch len(exNamespace) {
// include some, exclude nothing
case 0:
app.namespaces = inNamespace
// include some, exclude some from it
default:
app.namespaces = difference(inNamespace, exNamespace)
}
}

stopSignal, err := app.Run()
@@ -108,3 +128,17 @@ func createKubernetesClient(configFile string) (client *kubernetes.Clientset, er
}
return kubernetes.NewForConfig(config)
}

func difference(allNamespace, exNamespace []string) []string {
mapdiff := make(map[string]struct{}, len(exNamespace))
for _, ns := range exNamespace {
mapdiff[ns] = struct{}{}
}
var diff []string
for _, ns := range allNamespace {
if _, found := mapdiff[ns]; !found {
diff = append(diff, ns)
}
}
return diff
}