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

Support include/exclude regexes for event and resource constraints #963

Merged
merged 8 commits into from
Feb 8, 2023

Conversation

pkosiec
Copy link
Member

@pkosiec pkosiec commented Feb 1, 2023

Description

Changes proposed in this pull request:

  • Support include/exclude regexes for event.reason, event.message and resources[].name.

Breaking changes

(To copy and paste in #972)

  • Kubernetes source constraints event.reason, event.message and resources[].name are now objects with two lists: include and exclude. Both take exact values or regex patterns. Exclude takes precedence over include.

    This allows you to set exclude patterns, and also unifies the configuration with namespaces constraints.

Notes - open question

I didn't rename namespaces to namespace or event.types to event.type as I weren't sure if that's a good change. However, if you have any ideas, then please let me know - we're already doing a breaking change here, so I can unify the config properties more 🙂

Maybe we should rename namespaces to namespace for consistency (as it is an object), and keep plural form for event.types as it is an array? Let me know 🙂

TODO

Testing

Check out the PR (gh pr checkout 963).

Use the configuration:

communications:
  "default-group":
    socketSlack:
      enabled: true
      appToken: "xapp-"
      botToken: "xoxb-"
      notification:
        type: "short"
      channels:
        "default":
          name: botkube-demo
          bindings:
            executors:
              - kubectl-read-only
              - helm
              - plugin-based
            sources:
              - k8s-all-events
              - k8s-recommendation-events
              - plugin-based
        "secondary":
          name: priv-channel
          bindings:
            executors: []
            sources:
              - k8s-all-events-except
sources:
  'k8s-all-events-except':
    displayName: "Kubernetes Info"
    kubernetes:
      namespaces:
        include:
          - ".*"
      event:
        types:
          - create
          - delete
          - error
        message:
          include: [".*"]
          exclude: ["^Readiness probe failed.*$"]
      resources:
        - type: v1/pods
        - type: v1/services
        - type: networking.k8s.io/v1/ingresses
        - type: v1/nodes
        - type: v1/namespaces
        - type: v1/persistentvolumes
        - type: v1/persistentvolumeclaims
        - type: v1/configmaps
        - type: rbac.authorization.k8s.io/v1/roles
        - type: rbac.authorization.k8s.io/v1/rolebindings
        - type: rbac.authorization.k8s.io/v1/clusterrolebindings
        - type: rbac.authorization.k8s.io/v1/clusterroles
        - type: apps/v1/daemonsets
          event:
            types:
              - create
              - update
              - delete
              - error
          updateSetting:
            includeDiff: true
            fields:
              - spec.template.spec.containers[*].image
              - status.numberReady
        - type: batch/v1/jobs
          event:
            types:
              - create
              - update
              - delete
              - error
          updateSetting:
            includeDiff: true
            fields:
              - spec.template.spec.containers[*].image
              - status.conditions[*].type
        - type: apps/v1/deployments
          event:
            types:
              - create
              - update
              - delete
              - error
          updateSetting:
            includeDiff: true
            fields:
              - spec.template.spec.containers[*].image
              - status.availableReplicas
        - type: apps/v1/statefulsets
          event:
            types:
              - create
              - update
              - delete
              - error
          updateSetting:
            includeDiff: true
            fields:
              - spec.template.spec.containers[*].image
              - status.readyReplicas

settings:
  clusterName: "dev"
  upgradeNotifier: false

Run Botkube:

export BOTKUBE_SETTINGS_LOG_LEVEL=info
export BOTKUBE_PLUGINS_CACHE__DIR="/tmp/plugins"
export BOTKUBE_SETTINGS_KUBECONFIG=$KUBECONFIG # optional
export BOTKUBE_CONFIG_PATHS="$(pwd)/helm/botkube/values.yaml,$(pwd)/comm_config.yaml"
go run cmd/botkube/main.go

Run the command to trigger events:

k delete po -n kube-system -l k8s-app=metrics-server

See events with Readiness probe failed message:
image

On priv-channel, they will be filtered out nicely:

image

Related issue(s)

#954

@pkosiec pkosiec added the enhancement New feature or request label Feb 1, 2023
@pkosiec pkosiec marked this pull request as ready for review February 1, 2023 16:18
@pkosiec pkosiec requested review from a team and PrasadG193 as code owners February 1, 2023 16:18
@pkosiec pkosiec marked this pull request as draft February 2, 2023 09:09
@pkosiec
Copy link
Member Author

pkosiec commented Feb 2, 2023

Converting to draft after internal conversation about our preferred approach. The agreement is to rework the PR to:

  • remove the advanced regex engine,
  • introduce include/exclude lists in all of the source filters and use Go regexes there.

Converting this PR to draft then 🙂

@pkosiec pkosiec changed the title Support complex regexes for event constraints Support include/exclude regexes for event and resource constraints Feb 2, 2023
@pkosiec pkosiec added the breaking Contains breaking change label Feb 2, 2023
@pkosiec pkosiec force-pushed the complex-regexes branch 2 times, most recently from 478ed3c to a65089d Compare February 3, 2023 12:52
Copy link

@josefkarasek josefkarasek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍

internal/source/registration.go Outdated Show resolved Hide resolved
@pkosiec pkosiec enabled auto-merge (squash) February 8, 2023 07:10
@pkosiec pkosiec merged commit 3ee7ef0 into kubeshop:main Feb 8, 2023
@pkosiec pkosiec deleted the complex-regexes branch February 8, 2023 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Contains breaking change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants