Skip to content

Commit ea212f1

Browse files
author
Matt Morrison
authored
Merge pull request #8 from zapier/feat/docs
Add documentation
2 parents 12dbaea + f1c33dc commit ea212f1

File tree

15 files changed

+262
-10
lines changed

15 files changed

+262
-10
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
GITLAB_TOKEN=xyz
22
KUBECHECKS_LOG_LEVEL=debug
33
OPENAI_API_TOKEN=xyz
4+
GITHUB_TOKEN=xyz
5+
KUBECHECKS_WEBHOOK_SECRET=xyz

.github/helm-unittest.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,5 @@ echo " helm-unittest.sh ${DIR}"
66
echo "#######################"
77

88
###############################################################################
9-
# NAME: Detect Helm Version
10-
if [[ `grep -R "apiVersion: v2" "$1/Chart.yaml" > /dev/null; echo $?` -eq 0 ]]
11-
then
12-
HELM_VER="--helm3"
13-
else
14-
HELM_VER=""
15-
fi
16-
17-
helm unittest ${HELM_VER} "${1}"
9+
# We always use Helm 3 as Helm 2 is now deprecated
10+
helm unittest "${1}"

charts/kubechecks/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ deployment:
5050
# ARGOCD_EXEC_TIMEOUT: 600s
5151
# KUBECHECKS_OTEL_COLLECTOR_PORT: "4317"
5252
# KUBECHECKS_OTEL_ENABLED: "true"
53+
# KUBECHECKS_VCS_TYPE: "github"
5354

5455
startupProbe:
5556
failureThreshold: 30
@@ -76,7 +77,7 @@ secrets:
7677
# to the secret resource. These should be passed into the
7778
# deployment as arguments.
7879
env: {}
79-
# GITLAB_TOKEN: <token>
80+
# KUBECHECKS_VCS_TOKEN: <token>
8081

8182

8283
serviceAccount:

docs/architecture.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Architecture
2+
3+
`kubechecks` is driven by webhook events from remote VCS providers (Github, Gitlab, etc), describing new commits/sets of changes (in the form of Pull/Merge Requests). These events are parsed by VCS specific `Client`s and cloned to a local `Repo`, which has all
4+
the checks `kubechecks` runs made against it.
5+
6+
## Overview
7+
8+
![Overall flow of how Kubechecks works, showing the process from PR, to server, to repo creation, to checks running, to output being posted back to Kubechecks](./img/flow.png)
9+
10+
Once `kubechecks` starts, it will listen on the configured webhook address for payload events. **You must register your remote repository (Github etc) to send PullRequest/MergeRequest events to this address**. Once this is configured, `kubechecks` will respond to new Pull/Merge (PR/MR) requests and begin generating various reports based on the requested changes to be merged into your main branch.
11+
12+
As each application is checked, a comment left on your PR/MR dynamically updates with the latest information; letting you see as soon as possible if something isn't quite right with your new code. Take a look below!
13+
14+
![Kubechecks in practice gif](./img/kubechecks.gif)
15+
16+
## Components
17+
18+
`kubechecks` at it's core is built upon three core ideas; a `Client`, representing the remote VCS provider (i.e. Github or Gitlab) which parses webhook events and interacts with remote Pull/Merge requests; a `CheckEvent`, representing a single run of `kubechecks` in it's entirety; and a `Repo`, representing a local git repository with the changes contained within the webhook event.
19+
20+
### Client
21+
22+
![Diagram of Client, showing the concrete VCS implementation and the Message type](./img/client.png){: style="height:350px;display:block;margin:0 auto;"}
23+
24+
`Client`'s are the entrypoint for kickstarting the whole `kubechecks` process; a `Client` implements functions to enable communication to a remote VCS provider (through posting comments), validate webhooks and their payloads, and convert webhook payloads to the internal representation of a Git Repo. Currently, `kubechecks` has clients written and maintained for both Github and Gitlab; if you'd like to see a new platform supported, make a PR!
25+
26+
### Repo
27+
28+
![Check Event and Repo type diagrams](./img/repo.png){: style="height:350px;display:block;margin:0 auto;"}
29+
30+
`Repo`'s are an internal representation of a Pull/Merge Request, containing information such as the `HEAD` of the PR/MR branch, the base/target branch attempting to be merged into, and git specific metadata such as username/email. This information is then used to locally clone the repository at the specified SHA.
31+
32+
By abstracting the PR/MR in this way, `kubechecks` remains VCS provider agnostic, as the concrete `Client`'s are responsible for producing the `Repo` from their specific implementation. This design ensures that as long as a `Client` is configured to create a `Repo`, `kubechecks` will continue to work without concern.
33+
34+
### CheckEvent
35+
36+
![Check Event and Repo type diagrams](./img/checkevent.png){: style="height:350px;display:block;margin:0 auto;"}
37+
38+
The final piece of the puzzle is the `CheckEvent`; an internal structure that takes a `Client` and a `Repo` and begins running all configured checks. A `CheckEvent` first determines what applications within the repository have been affected by the PR/MR, and begins concurrently running the check suite against each affected application to generate a report for that app. As each application updates its report, the `CheckEvent` compiles all reports together and instructs the `Client` to update the PR/MR with a comment detailing the current progress; resulting in one comment per run of `kubechecks` with the latest information about that particular run. Whenever a new run of `kubechecks` is initiated, all previous comments are deleted to reduce clutter.

docs/contributing.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Contributing to kubechecks
2+
3+
We're always looking for community contributions to `kubechecks`. The best way to get started is to create an issue. This can be for a bug, or for a new feature. This helps us gauge how many other users are impacted, or would benefit from a new feature.
4+
5+
## Issues
6+
7+
We use [Github Issues](https://github.com/zapier/kubechecks/issues) to track issues and features for this project.
8+
9+
## Contributor Agreement
10+
11+
We have decided to use [DCO](https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin) to reduce the friction of contributing to `kubechecks`. To sign off on a commit you can use `-s` or `--signoff` when committing to append a [trailer](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--s).
12+
13+
If you forget to sign off on your last commit you can amend it using `git commit --amend --signoff`, or if there are multiple commits that need to be amended `git rebase --signoff HEAD~2` can be used replacing `HEAD~2` with the number of commits to go back. More information can be found in this [Stack Overflow](https://stackoverflow.com/questions/13043357/git-sign-off-previous-commits) post.
14+
15+
Other notable projects that use DCO:
16+
17+
* [Linux Kernel](https://developercertificate.org/)
18+
* [Gitlab](https://about.gitlab.com/community/contribute/dco-cla/)
19+
* [GCC](https://gcc.gnu.org/dco.html)
20+
21+
-------------
22+
23+
## Pull Request Process
24+
25+
1. You are welcome to submit a draft pull request for commentary or review before it is fully completed. Feel free to provide more information on the issue you're addressing or a link to a specific one to add more context.
26+
2. When time permits `kubechecks`'s core team members will look over your contribution and either merge, or provide comments. It may take some time for us to respond. We kindly ask that you do not target specific team members. We may also reject a PR at this time with comments around why, and if we would reconsider it.
27+
3. If we have requested changes, you can either make those changes or, if you disagree with the suggested changes, we can discuss it further in the pull request. This may be a multi-step process. It is the contributor's responsibility to address any changes requested. While reviewers are happy to give guidance, it is unsustainable for us to perform the coding work necessary to get a PR into a mergeable state.
28+
4. Once all outstanding comments and checklist items have been addressed, your contribution will be merged! The core team takes care of updating the change log as required. It may be a bit before we cut a new release so your changes may not be available immediately.
29+
30+
### PR Checks
31+
32+
The following checks run when a PR is opened:
33+
34+
* Developer Certificate of Origin (DCO): This check is applied against every **commit**. If a single commit is not signed the check will fail. Please checkout our [Contributor Agreement](#contributor-agreement) for more details.
35+
* Tests / Build: unit tests, go vet and docker build are executed on each PR. These must all pass for a PR to be considered mergeable.
36+
37+
-----------
38+
39+
## Developer Environment
40+
41+
### Tools / Accounts
42+
43+
* [Go 1.19](https://go.dev/)
44+
* [Earthly](https://earthly.dev/)
45+
* [Ngrok](https://ngrok.com/)
46+
* [Tilt](https://tilt.dev/)
47+
* [Gitlab](https://gitlab.com) / [Github](https://github.com) token
48+
* [OpenAI](https://openai.com) token (Optional)
49+
* [Kubernetes](https://kubernetes.io/)
50+
* [minikube](https://minikube.sigs.k8s.io/docs/)
51+
* [kind](https://kind.sigs.k8s.io/)
52+
* [Docker Desktop](https://docs.docker.com/desktop/kubernetes/)
53+
54+
Some of the above tools are not necessary if you're developing against an externally accessible kubernetes cluster. We leverage Ngrok for local testing in order to accept webhooks from Gitlab/Github.
55+
56+
### Tilt
57+
58+
[Tilt.dev](https://tilt.dev) is used to power the local development environment.
59+
The `Tiltfile` defines all the resources required to build, run and test `kubechecks`.
60+
It creates:
61+
62+
* Gitlab / Github repository with test files.
63+
* Deploys ArgoCD and some demo applications to your kubernetes cluster.
64+
* Deploys ngrok to provide an external accessible URL for Github/Gitlab to send webhooks to your local dev environment.
65+
* Builds, tests and runs (with watch and hot restart) the `kubechecks` server in the local Kubernetes cluster.
66+
* Delve live debugger is available for `kubechecks`.
67+
68+
To get started do the following:
69+
70+
* Copy the `.env.example` and set required values.
71+
72+
```console
73+
cp .env.example .env
74+
```
75+
76+
* From the root directory of this repo:
77+
78+
```console
79+
tilt up
80+
```
81+
82+
You should see output like:
83+
84+
```
85+
Tilt started on http://localhost:10350/
86+
v0.30.13, built 2022-12-05
87+
88+
(space) to open the browser
89+
(s) to stream logs (--stream=true)
90+
(t) to open legacy terminal mode (--legacy=true)
91+
(ctrl-c) to exit
92+
93+
```
94+
95+
In the background Tilt has started building and deploying resources.
96+
97+
You should go ahead and press the space bar to open the Tilt web UI.
98+
99+
There are currently some circular dependencies in the local dev resources, so all resources may not come up cleanly on the first launch.
100+
101+
![tilt-1](img/tilt-1.png)
102+
103+
Click the Detailed view button at the top, and click the refresh button next to the `Tiltfile` resource to run another cycle.
104+
105+
![tilt-2](img/tilt-2.png)
106+
107+
#### Minikube
108+
109+
If you're using minikube with Tilt we recommend following this [guide](https://github.com/tilt-dev/minikube-local) to setup a local registry that Tilt can push to automatically. Without this Tilt will attempt to push up to Docker Hub by default.
110+
111+
### Code Changes
112+
113+
We use Earthly to simplify our CI/CD process with `kubechecks`. This also simplifies testing changes locally before pushing them up to ensure your PR will pass all required checks. The best command to run is `earthly +unit-test` this will pull all the required dependencies (including any new ones that you have added). It will then run [go vet](https://pkg.go.dev/cmd/vet), and if those pass it will run `go test` with race detection enabled. You can also always run these commands directly `go test -race ./...` will run all tests in the repo with race detection enabled. Please ensure that `earthly +unit-test` is passing before opening a PR.
114+
115+
### Documentation Changes
116+
117+
We use [mkdocs](https://www.mkdocs.org/) to build our docs locally. You can build these docs by running `mkdocs serve` from the root of the repository. It will also auto reload when any file is changed in that directory. By default you can view the docs under `http://localhost:8000`. Please confirm that any changes to documentation render correctly and that your changes display as expected.

docs/img/checkevent.png

36.9 KB
Loading

docs/img/client.png

48.3 KB
Loading

docs/img/flow.png

152 KB
Loading

docs/img/kubechecks.gif

2.77 MB
Loading

docs/img/repo.png

28.2 KB
Loading

0 commit comments

Comments
 (0)