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

Persist filters, notifications and source bindings state from commands #746

Merged
merged 2 commits into from
Sep 26, 2022

Conversation

pkosiec
Copy link
Collaborator

@pkosiec pkosiec commented Sep 21, 2022

Description

Changes proposed in this pull request:

  • Persist filters, notifications and source bindings state from commands

Limitations

  1. Notifications state for MS Teams is not preserved due to the limitation of the MS Teams integration.
  2. Runtime state reload may take a few or more (even 30+) seconds, as stated here. To avoid this issue, we could use ConfigMap informers for Config Watcher.

To do

Testing

export WS_SLACK_BOT_TOKEN=""
export WS_SLACK_APP_TOKEN=""
export DISCORD_TOKEN=""
cat > /tmp/values.yaml << ENDOFFILE
communications:
  'default-group':
    socketSlack:
      enabled: true
      botToken: "${WS_SLACK_BOT_TOKEN}"
      appToken: "${WS_SLACK_APP_TOKEN}"
      token: ""
      channels:
        'default':
          name: botkube-test
          notification:
            disabled: true
          bindings:
            executors:
              - kubectl-read-only
            sources:
              - k8s-events
        'second':
          name: botkube-demo
          bindings:
            executors:
              - kubectl-read-only
            sources:
              - k8s-events

    discord:
      enabled: true
      botID: "976786722706821120"
      token: "${DISCORD_TOKEN}"
      channels:
        'default':
          id: "{id1}"
          notification:
              disabled: true
          bindings:
            executors:
              - kubectl-read-only
            sources:
              - k8s-events
        'test':
          id: "{id2}"
          bindings:
            executors:
              - kubectl-read-only
            sources:
              - k8s-events
        'test2':
          id: "{id3}"
          bindings:
            executors:
              - kubectl-read-only
            sources:
              - k8s-events
      notification:
        type: short

settings:
  clusterName: dev
executors:
  'kubectl-read-only':
    kubectl:
      enabled: true
analytics:
  disable: true
image:
  #registry: docker.io
  #repository: pkosiec/botkube
  #tag: '746-PR'
  repository: kubeshop/pr/botkube
  tag: '746-PR'
  pullPolicy: Always  
ENDOFFILE
helm install botkube ./helm/botkube -n botkube --create-namespace  -f /tmp/values.yaml

Get ConfigMaps:

kubectl get cm -n botkube botkube-runtime-config -oyaml
kubectl get cm -n botkube botkube-startup-config -oyaml

Run command on any configured channel:

@BotKube filters disable NodeEventsChecker

Get ConfigMap:

kubectl get cm -n botkube botkube-startup-config -oyaml

Notice that the Pod doesn't restart.

Run command on botkube-test channel on Slack:

@BotKube notifier start

And e.g. on test channel on Discord:

@BotKube notifier stop

See the ConfigMaps again:

kubectl get cm -n botkube botkube-runtime-config -oyaml
kubectl get cm -n botkube botkube-startup-config -oyaml

You can trigger some notifications:

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

Also, edit the runtime ConfigMap and e.g. change sources for a given channel:

k edit cm -n botkube botkube-runtime-config

Wait until Pod restarts.

Related issue(s)

#704

@pkosiec pkosiec added enhancement New feature or request wip labels Sep 21, 2022
@pkosiec pkosiec added this to the v0.14.0 milestone Sep 21, 2022
@pkosiec pkosiec force-pushed the state-cfg branch 2 times, most recently from a39b156 to 989ae26 Compare September 22, 2022 09:07
@pkosiec pkosiec removed the wip label Sep 22, 2022
@pkosiec pkosiec force-pushed the state-cfg branch 4 times, most recently from 80d0c7d to 590a2bb Compare September 22, 2022 15:47
@pkosiec pkosiec marked this pull request as ready for review September 22, 2022 15:48
@pkosiec pkosiec requested a review from a team September 22, 2022 15:48
@pkosiec pkosiec requested a review from PrasadG193 as a code owner September 22, 2022 15:48
@pkosiec pkosiec requested a review from ezodude September 22, 2022 15:48
Copy link
Contributor

@ezodude ezodude left a comment

Choose a reason for hiding this comment

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

Left a comment - otherwise the code looks fine.

}

// PersistSourceBindings persists source bindings configuration for a given channel in a given platform.
func (m *PersistenceManager) PersistSourceBindings(commGroupName string, platform CommPlatformIntegration, channelName string, sourceBindings []string) error {
// TODO: Implement this as a part of https://github.com/kubeshop/botkube/issues/704
func (m *PersistenceManager) PersistSourceBindings(ctx context.Context, commGroupName string, platform CommPlatformIntegration, channelAlias string, sourceBindings []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick question:

Other than the tests and theConfigPersistenceManager interface, is there anywhere else in the code that uses this method?

Maybe I missed it.

Copy link
Collaborator Author

@pkosiec pkosiec Sep 23, 2022

Choose a reason for hiding this comment

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

Very good question - I'm sorry I forgot to describe it: this will be used by @mszostok here: #747
(Not sure which PR comes first, but we agreed together on the interface and the actual persistency is implemented in my PR). So it's actually a part of the "source bindings edit" feature 🙂

Copy link
Collaborator Author

@pkosiec pkosiec Sep 23, 2022

Choose a reason for hiding this comment

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

Update: looks as Mateusz merged his PR, so after I rebase this PR this part will persist source bindings from the edit command 👍

@ezodude
Copy link
Contributor

ezodude commented Sep 23, 2022

About to test locally.

@ezodude
Copy link
Contributor

ezodude commented Sep 23, 2022

In the PR testing section:

@botkube NextGen filters disable NodeEventsChecker

What does "NextGen" refer to here?

The command: @BotKube filters disable NodeEventsChecker runs fine without it.

@pkosiec
Copy link
Collaborator Author

pkosiec commented Sep 23, 2022

@ezodude
I have BotKube NextGen app inside my workspace, and yeah, it's my custom name 😄 So please use @BotKube or whatever name you have for your Slack app 👍 thanks!

@ezodude
Copy link
Contributor

ezodude commented Sep 23, 2022

Ran the code locally, all works.

Copy link
Contributor

@ezodude ezodude left a comment

Choose a reason for hiding this comment

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

👍

@pkosiec
Copy link
Collaborator Author

pkosiec commented Sep 26, 2022

Thanks @ezodude for review. I rebased the PR and tested all the communication platforms:

  • Discord
  • Slack
  • Teams
  • Mattermost

Both Source Bindings + notifications are properly persisted after small changes b8130d2 👍

@pkosiec pkosiec merged commit 27bebad into kubeshop:main Sep 26, 2022
@pkosiec pkosiec deleted the state-cfg branch September 26, 2022 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants