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

Add filter commands related documentation #22

Merged
merged 1 commit into from May 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 17 additions & 20 deletions content/filters/_index.md
Expand Up @@ -24,16 +24,17 @@ Create a new file (e.g image_tag_checker.go) in **botkube/pkg/filterengine/filte

Set package name as "filters" and import required packages

```
```go
package filters

import (
"strings"
"strings"

"github.com/infracloudio/botkube/pkg/events"
log "github.com/infracloudio/botkube/pkg/logging"
"github.com/infracloudio/botkube/pkg/events"
"github.com/infracloudio/botkube/pkg/filterengine"
log "github.com/infracloudio/botkube/pkg/logging"

apiV1 "k8s.io/api/core/v1"
apiV1 "k8s.io/api/core/v1"
)
```

Expand All @@ -54,11 +55,6 @@ So, the Run function should have **func(interface{}, *events.Event)** signature
type ImageTagChecker struct {
}

// NewImageTagChecker creates new ImageTagChecker object
func NewImageTagChecker() *ImageTagChecker {
return &ImageTagChecker{}
}

// Run filer and modifies event struct
func (f *ImageTagChecker) Run(object interface{}, event *events.Event) {

Expand All @@ -69,6 +65,7 @@ func (f *ImageTagChecker) Run(object interface{}, event *events.Event) {

#### 3. Add your logic in the Run() function
Now, put your logic in the **Run()** function to parse resource object, run validation and modify Event struct. The fields in the Event struct can be found [here](https://github.com/infracloudio/botkube/blob/master/pkg/events/events.go#L31).

```
// Run filers and modifies event struct
func (f *ImageTagChecker) Run(object interface{}, event *events.Event) {
Expand Down Expand Up @@ -107,18 +104,18 @@ func (f *ImageTagChecker) Run(object interface{}, event *events.Event) {
log.Logger.Info("Image tag filter successful!")
}
```
### B. Register your filter to filterengine

- Once your Run() function is completed, you can run go build to check for any compilation error.
- After that, open **botkube/pkg/filterengine/filterengine.go** and register your filter by adding the struct to **Filters** list
// Filters contains the lists of available filters
// TODO: load this dynamically
Filters = []Filter{
filters.NewIngressValidator(),
filters.NewImageTagChecker(), // Register image tag filter
#### 4. Register your filter to filterengine
You can call **Register()** method implemented by filterengine to register the filter in at startup

```
// Register the filter
func init() {
filterengine.DefaultFilterEngine.Register(ImageTagChecker{})
}

### C. Rebuild and deploy the BotKube backend
```

### B. Rebuild and deploy the BotKube backend

- Build the BotKube backend docker image with `make`.
- Push the image to Dockerhub registry.
Expand Down
21 changes: 20 additions & 1 deletion content/usage/_index.md
Expand Up @@ -8,6 +8,8 @@ weight: 40
<h3 class="section-head" id="h-show-help"><a href="#h-show-help">Debugging deployments using BotKube</a></h3>
@BotKube allows you to execute kubectl commands on your Kubernetes cluster.
Run **/botkubehelp** to find more information about the supported commands.

TODO: update help
![help](/images/help.png)
As suggested in help message, to execute kubectl commands, send message in following format in the channel where BotKube is already added or as a direct message to BotKube.
```
Expand All @@ -19,6 +21,7 @@ See [Examples](/examples/#h-examples) for the use cases.
Depending upon your configuration, you will receive notifications about Kubernetes resources lifecycle events and their health.
BotKube bot allows you to enable/disable notifications only from the configured channel. Run **/botkubehelp**, the bot will reply with the help message about the supported message formats.

TODO: update help
![BotKube_help](/images/mm_help.png)

<h3 class="section-head" id="h-view-config"><a href="#h-view-config">View BotKube configuration</a></h3>
Expand Down Expand Up @@ -70,6 +73,22 @@ Run **@BotKube notifier status** to check status of notifier if running or stopp
![notifier_status](/images/notifier_status.png)
![notifier_status](/images/mm_notifier_status.png)

<h3 class="section-head" id="h-manage-filters"><a href="#h-manage-filters">Manage filters</a></h3>
BotKube allows you to manage filters using @BotKube commands
<h4>List available filters</h4>
Run **@BotKube filters list** to get list of available filters and their running status
![](/images/filters_list.png)

<h4>Disable filter</h4>
Run **@BotKube filters disable {filter-name}** to disable perticular filter to skip checks on resource specs
![](/images/filters_disable.png)

<h4>Enable filter</h4>
Run **@BotKube filters enable {filter-name}** to enable perticular filter to run checks on resource specs
![](/images/filters_enable.png)



<h3 class="section-head" id="h-kubectl-pods"><a href="#h-kubectl-pods">Run Kubectl commands</a></h3>
Run **@BotKube < kubectl command without kubectl prefix >** to get kubectl response from the cluster configured with the channel.
This command needs to be executed from configured channel else use `--cluster-name` flag described below.
Expand All @@ -90,4 +109,4 @@ The flag is ignored in notifier commands as they can be executed from the config
![flag_clustername_ping](/images/flag_clustername_ping.png)
![flag_clustername_ping](/images/mm_flag_clustername_ping.png)
![flag_clustername_kubectl](/images/flag_clustername_kubectl.png)
![flag_clustername_kubectl](/images/mm_flag_clustername_kubectl.png)
![flag_clustername_kubectl](/images/mm_flag_clustername_kubectl.png)
Binary file added static/images/filters_disable.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/filters_enable.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/filters_list.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.