Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Multiple namespaces feature #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ resource:
secret: false
configmap: false
ingress: false
namespace: ""
namespace: []

```

Expand Down Expand Up @@ -418,6 +418,12 @@ $ kubewatch resource add --rc --po --svc
$ kubewatch resource remove --rc --po --svc
```

## Namespaces

If a specific set of namespaces need to be applied to the filter, that can be done with the namepace configuration as shown in the [example config ](examples/conf/kubewatch.conf.multiple.namespaces.yaml).

This functionality can be useful for clusters where one is not admin and is merely a tennant.

# Build

### Using go
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Config struct {

// For watching specific namespace, leave it empty for watching all.
// this config is ignored when watching namespaces
Namespace string `json:"namespace,omitempty"`
Namespace []string `json:"namespace,omitempty"`
}

// Slack contains slack configuration
Expand Down
4 changes: 2 additions & 2 deletions config/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ resource:
secret: false
configmap: false
ing: false
# For watching specific namespace, leave it empty for watching all.
# For watching specific array of namespaces, leave it empty for watching all.
# this config is ignored when watching namespaces
namespace: ""
namespace: []
`
2 changes: 1 addition & 1 deletion examples/conf/kubewatch.conf.msteams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: kubewatch
data:
.kubewatch.yaml: |
namespace:
namespace: []
handler:
msteams:
webhookurl: https://outlook.office.com/webhook/...
Expand Down
23 changes: 23 additions & 0 deletions examples/conf/kubewatch.conf.multiple.namespaces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kubewatch
data:
.kubewatch.yaml: |
namespace:
- namespaceOne
- namespaceTwo
handler:
slack:
token: xxx
channel: xxx
resource:
namespace: false
deployment: false
replicationcontroller: false
replicaset: false
daemonset: false
services: false
pod: true
secret: false
configmap: false
2 changes: 1 addition & 1 deletion kubewatch-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: kubewatch
data:
.kubewatch.yaml: |
namespace: ""
namespace: []
handler:
slack:
token: <token>
Expand Down
19 changes: 18 additions & 1 deletion pkg/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package client

import (
"log"
"os"
"os/signal"
"syscall"

"github.com/bitnami-labs/kubewatch/config"
"github.com/bitnami-labs/kubewatch/pkg/controller"
Expand All @@ -35,7 +38,21 @@ import (
func Run(conf *config.Config) {

var eventHandler = ParseEventHandler(conf)
controller.Start(conf, eventHandler)
// Setting an empty namespace value in case config is empty
// If no specific namespace is defined cluster scope is taken
if len(conf.Namespace) == 0 {
conf.Namespace = append(conf.Namespace, "")
}
// Create a controler
go controller.StartClusterScope(conf, eventHandler)
// For each namespace in array create a controller
for _, ns := range conf.Namespace {
go controller.StartNamespaceScope(conf, eventHandler, ns)
}
sigterm := make(chan os.Signal, 1)
signal.Notify(sigterm, syscall.SIGTERM)
signal.Notify(sigterm, syscall.SIGINT)
<-sigterm
}

// ParseEventHandler returns the respective handler object specified in the config file.
Expand Down
Loading