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

arm support #1

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/build-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
name: Build and publish Docker image

on:
pull_request:
branches:
- master
push:
branches:
- main
Expand All @@ -23,7 +26,7 @@ jobs:
matrix:
arch:
- linux/amd64
# - linux/arm64
- linux/arm64
permissions:
packages: write
contents: read
Expand Down Expand Up @@ -59,7 +62,8 @@ jobs:
with:
context: .
platforms: "${{ matrix.arch }}"
push: ${{ github.ref == 'refs/heads/master' }}
push: true
# push: ${{ github.ref == 'refs/heads/master' }}
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
Expand Down
111 changes: 59 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Kubernetes event reporter for Sentry.

> This fork also attempts to add ARM support.

---

**⚠️ Note: this is BETA software that is still in development and may contain bugs. Use it at your own risk in production environments.**
Expand Down Expand Up @@ -137,103 +139,108 @@ spec:
r=$((RANDOM%2))
if [ $r -eq 0 ]; then echo Hello!; else exit 1; fi
restartPolicy: Never
```
```

In the Sentry Crons tab of the corresponding project, we may see the following:

![ExampleCronsMonitor](./images/example_crons_monitor.png)
![ExampleCronsMonitor](./images/example_crons_monitor.png)

## Local Development (out of cluster configuration)

1. Install necessary dependencies to run Kubernetes locally
1. Install `docker` and start the docker daemon

[https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/)
1. Install `docker` and start the docker daemon

`docker` is a service that manages containers and is used by Kubernetes to create nodes (since `kind` actually create Kubernetes “nodes” as docker containers rather than VMs)
[https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/)

2. Install `kind` and add it to PATH
`docker` is a service that manages containers and is used by Kubernetes to create nodes (since `kind` actually create Kubernetes “nodes” as docker containers rather than VMs)

[https://kind.sigs.k8s.io/docs/user/quick-start/](https://kind.sigs.k8s.io/docs/user/quick-start/)
2. Install `kind` and add it to PATH

`kind` is a tool for running local Kubernetes clusters and we use it here for testing. The container runtime used by it is `containerd`, which is the same runtime used now by Docker.
[https://kind.sigs.k8s.io/docs/user/quick-start/](https://kind.sigs.k8s.io/docs/user/quick-start/)

3. Install `kubectl`, which is the command line tool we use to interact with Kubernetes clusters ran locally by `kind`
`kind` is a tool for running local Kubernetes clusters and we use it here for testing. The container runtime used by it is `containerd`, which is the same runtime used now by Docker.

[https://kubernetes.io/docs/tasks/tools/](https://kubernetes.io/docs/tasks/tools/)
3. Install `kubectl`, which is the command line tool we use to interact with Kubernetes clusters ran locally by `kind`

[https://kubernetes.io/docs/tasks/tools/](https://kubernetes.io/docs/tasks/tools/)

2. Run Kubernetes cluster locally for development purposes
1. Create a Kubernetes cluster with `kind` using the command (the cluster name is “kind” by default)

`kind create cluster`
1. Create a Kubernetes cluster with `kind` using the command (the cluster name is “kind” by default)

`kind create cluster`

b. Output information about the created cluster named “kind” or some cluster name you have chosen using the following command (replacing `<cluster name>` with `kind` if default used)
b. Output information about the created cluster named “kind” or some cluster name you have chosen using the following command (replacing `<cluster name>` with `kind` if default used)

`kubectl cluster-info --context kind-<cluster name>`
`kubectl cluster-info --context kind-<cluster name>`

You should see an output similar to the following:
You should see an output similar to the following:

```bash
Kubernetes control plane is running at https://127.0.0.1:61502
CoreDNS is running at https://127.0.0.1:61502/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
```
```bash
Kubernetes control plane is running at https://127.0.0.1:61502
CoreDNS is running at https://127.0.0.1:61502/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
```

3. Run the `sentry-kubernetes` Go module (which must be performed after the Kubernetes cluster is already running because the module requires the `kubeconfig` file)
1. Clone the `sentry-kubernetes` repository

`git clone https://github.com/getsentry/sentry-kubernetes.git`
1. Clone the `sentry-kubernetes` repository

b. Pass a valid Sentry DSN to the an environment variable named `SENTRY_DSN` ([https://docs.sentry.io/product/sentry-basics/concepts/dsn-explainer/](https://docs.sentry.io/product/sentry-basics/concepts/dsn-explainer/))
`git clone https://github.com/getsentry/sentry-kubernetes.git`

c. At the root of the repository directory, build the Go module with the command
b. Pass a valid Sentry DSN to the an environment variable named `SENTRY_DSN` ([https://docs.sentry.io/product/sentry-basics/concepts/dsn-explainer/](https://docs.sentry.io/product/sentry-basics/concepts/dsn-explainer/))

`make build`
c. At the root of the repository directory, build the Go module with the command

d. Run the module outside of the k8s cluster by executing the command
`make build`

`go run .`
d. Run the module outside of the k8s cluster by executing the command

which now starts up the process that automatically detects the cluster configuration in order to detect events
`go run .`

which now starts up the process that automatically detects the cluster configuration in order to detect events

4. Add error-producing pods to test event capturing
1. Create resources (e.g. pods or deployments) using existing manifests meant to produce errors to be captured by `sentry-kubernetes`. For example, we can apply the manifest for a pod that exhibits crash loop behavior with the command

`kubectl apply -f ./k8s/errors/pod-crashloop.yaml`
1. Create resources (e.g. pods or deployments) using existing manifests meant to produce errors to be captured by `sentry-kubernetes`. For example, we can apply the manifest for a pod that exhibits crash loop behavior with the command

`kubectl apply -f ./k8s/errors/pod-crashloop.yaml`

b. Check that the pod is created using the command

b. Check that the pod is created using the command
`kubectl get pods`

`kubectl get pods`
which should produce an output similar to the following:

which should produce an output similar to the following:
```bash
NAME READY STATUS RESTARTS AGE
pod-crashloop 0/1 CrashLoopBackOff 32 (33s ago) 3h10m
```

```bash
NAME READY STATUS RESTARTS AGE
pod-crashloop 0/1 CrashLoopBackOff 32 (33s ago) 3h10m
```
Notice that the Status is `CrashLoopBackOff`, which is the intended state for our purpose

Notice that the Status is `CrashLoopBackOff`, which is the intended state for our purpose
c. Check that the `sentry-kubernetes` process capture this crash loop error by checking for the an output similar to the following:

c. Check that the `sentry-kubernetes` process capture this crash loop error by checking for the an output similar to the following:
```bash
[Sentry] 2023/11/08 12:07:53 Using release from Git: abc123
12:07PM INF Auto-detecting cluster configuration...
12:07PM WRN Could not initialize in-cluster config
12:07PM INF Detected out-of-cluster configuration
12:07PM INF Running integrations...
12:07PM INF Watching events starting from: Wed, 08 Nov 2023 12:07:53 -0800 namespace=default watcher=events
12:07PM INF CronJob monitoring is disabled namespace=default watcher=events
[Sentry] 2023/11/08 12:09:27 Sending error event [w0dc9c22094d7rg9b27afabc868e32] to o4506191942320128.ingest.sentry.io project: 4506191948087296
[Sentry] 2023/11/08 12:10:57 Sending error event [4808b623f0eb446eac0eb6c5f0a43681] to o4506191942320128.ingest.sentry.io project: 4506191948087296
```

```bash
[Sentry] 2023/11/08 12:07:53 Using release from Git: abc123
12:07PM INF Auto-detecting cluster configuration...
12:07PM WRN Could not initialize in-cluster config
12:07PM INF Detected out-of-cluster configuration
12:07PM INF Running integrations...
12:07PM INF Watching events starting from: Wed, 08 Nov 2023 12:07:53 -0800 namespace=default watcher=events
12:07PM INF CronJob monitoring is disabled namespace=default watcher=events
[Sentry] 2023/11/08 12:09:27 Sending error event [w0dc9c22094d7rg9b27afabc868e32] to o4506191942320128.ingest.sentry.io project: 4506191948087296
[Sentry] 2023/11/08 12:10:57 Sending error event [4808b623f0eb446eac0eb6c5f0a43681] to o4506191942320128.ingest.sentry.io project: 4506191948087296
```
d. Check the `Issues` tab of the corresponding Sentry project to ensure the events captured are shown similar to below:
d. Check the `Issues` tab of the corresponding Sentry project to ensure the events captured are shown similar to below:

![ExampleEvent](./images/example_event.png)
![ExampleEvent](./images/example_event.png)

## Caveats

- When the same event (for example, a failed readiness check) happens multiple times, Kubernetes might not report each of them individually, and instead combine them, and send with some backoff. The event message in that case will be prefixed with "(combined from similar events)" string, that we currently strip. AFAIK, there's no way to disable this batching behaviour.

## Potential Improvements

- For pod-related events: fetch last log lines and displaying them as breadcrumbs or stacktrace.
- For pod-related events: fetch last log lines and displaying them as breadcrumbs or stacktrace.
Loading