Skip to content
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 39 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}