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

Fix event update logic for Kubernetes source #1122

Merged
merged 8 commits into from
Jul 6, 2023

Conversation

pkosiec
Copy link
Member

@pkosiec pkosiec commented Jul 5, 2023

Description

Changes proposed in this pull request:

  • Fix event update logic for Kubernetes source
    • when updateSetting.fields are provided, ensure there's a diff between these fields.
    • when there's no updateSetting.fields config, route all update events.
    • if includeDiff is true, print diff as a part of the message.
  • Fix diff:
    • ensure it doesn't stop on first error
    • ensure we diff between empty property values (as something might be added/removed)
  • Revert breaking changes in messages API extracted to Revert API changes for api.Message #1124

This bug was related to changes in our event dispatching system when extracting Kubernetes events to a separate plugin. An event was qualified to dispatch even if it didn't contain changes for the updateSetting.Fields.

This regression was introduced in 1.0.0.

Testing

Run Botkube from this PR with the following config:

communications:
  "default-group":
    socketSlack:
      enabled: true
      appToken: "xapp-"
      botToken: "xoxb-"
      channels:
        "default":
          name: botkube-demo
          bindings:
            executors:
              - k8s-default-tools
            sources:
              - k8s-all-events
plugins:
  cacheDir: /tmp
  repositories:
    botkube:
      url: http://localhost:3000/botkube.yaml
go run test/helpers/plugin_server.go
make build-plugins-single
export KUBECONFIG="..."
export BOTKUBE_SETTINGS_LOG_LEVEL=debug                     
export BOTKUBE_PLUGINS_CACHE__DIR="/tmp/plugins"
export BOTKUBE_SETTINGS_KUBECONFIG=$KUBECONFIG
export BOTKUBE_CONFIG_PATHS="$(pwd)/helm/botkube/values.yaml,$(pwd)/comm_config.yaml"
export LOG_LEVEL_SOURCE_BOTKUBE_KUBERNETES="debug"
go run ./cmd/botkube/main.go

Apply sample resource, e.g. STS:
k apply sts.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 3 # by default is 1
  minReadySeconds: 10 # by default is 0
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "my-storage-class"
      resources:
        requests:
          storage: 1Gi

Edit the resource:

k edit sts web

The following fields will trigger an update event:

                - spec.template.spec.containers[*].image
                - status.readyReplicas

So you can try multiple different edits to see if they trigger the updates.

For previous Botkube, any update of such STS would trigger an event.

Related issue(s)

Resolves #1081

@pkosiec pkosiec added the bug Something isn't working label Jul 5, 2023
@pkosiec pkosiec force-pushed the fix-update-event-logic branch 2 times, most recently from 78e3427 to d9d9acf Compare July 5, 2023 10:58
@pkosiec pkosiec marked this pull request as ready for review July 5, 2023 16:11
@pkosiec pkosiec requested review from a team and PrasadG193 as code owners July 5, 2023 16:11
@pkosiec pkosiec requested a review from huseyinbabal July 5, 2023 16:11
Copy link
Contributor

@huseyinbabal huseyinbabal left a comment

Choose a reason for hiding this comment

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

Works as expected 👍

@pkosiec pkosiec merged commit 84adc72 into kubeshop:main Jul 6, 2023
13 checks passed
@pkosiec pkosiec deleted the fix-update-event-logic branch July 6, 2023 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update events every 30 minutes
2 participants