Skip to content

Commit

Permalink
add dry_run option
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Labarussias <issif+github@gadz.org>
  • Loading branch information
Issif committed Oct 15, 2023
1 parent e10100c commit 8f9c87c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Actions to trigger for events are set with rules with this syntax:
<string>: <string>
continue: <bool>
before: <bool>
dry_run: <bool>
notifiers:
- <string>
- <string>
Expand All @@ -219,6 +220,8 @@ With:
* `parameters`: key:value map of parameters for the action. value can be a string, an int or a map.
* `continue`: if `true`, no more action are applied after the rule has been triggerd (default is `true`).
* `before`: if `true`, no more action are applied after the rule has been triggerd (default is `true`).
* `dry_run`: if `true`; the action is not applied (default: `false`).
* `notifiers`: list of notifiers to enabled for the action, in addition with the defaults.

Examples:

Expand Down
8 changes: 7 additions & 1 deletion actionners/actionners.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ func Trigger(rule *rules.Rule, event *events.Event) {
}
}
}
result, err := i.Action(rule, event)
result := utils.LogLine{
Output: "no action, dry-run is enabled",
}
var err error
if !rule.DryRun {
result, err = i.Action(rule, event)
}
result.Rule = ruleName
result.Action = action
result.TraceID = event.TraceID
Expand Down
20 changes: 11 additions & 9 deletions actionners/kubernetes/terminate/terminate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package terminate

import (
"context"
"fmt"
"regexp"
"strconv"
Expand All @@ -10,6 +11,7 @@ import (
kubernetes "github.com/Issif/falco-talon/internal/kubernetes/client"
"github.com/Issif/falco-talon/internal/rules"
"github.com/Issif/falco-talon/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var Terminate = func(rule *rules.Rule, event *events.Event) (utils.LogLine, error) {
Expand Down Expand Up @@ -105,15 +107,15 @@ var Terminate = func(rule *rules.Rule, event *events.Event) (utils.LogLine, erro
}
}

// err := client.Clientset.CoreV1().Pods(namespace).Delete(context.Background(), podName, metav1.DeleteOptions{GracePeriodSeconds: gracePeriodSeconds})
// if err != nil {
// return utils.LogLine{
// Objects: objects,
// Status: "failure",
// Error: err.Error(),
// },
// err
// }
err := client.Clientset.CoreV1().Pods(namespace).Delete(context.Background(), podName, metav1.DeleteOptions{GracePeriodSeconds: gracePeriodSeconds})
if err != nil {
return utils.LogLine{
Objects: objects,
Status: "failure",
Error: err.Error(),
},
err
}
return utils.LogLine{
Objects: objects,
Status: "success",
Expand Down
1 change: 1 addition & 0 deletions internal/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Rule struct {
Continue string `yaml:"continue"`
Before string `yaml:"before"`
Match Match `yaml:"match"`
DryRun bool `yaml:"dry_run"`
}

type Action struct {
Expand Down

0 comments on commit 8f9c87c

Please sign in to comment.