Skip to content

Commit f63c0a8

Browse files
committed
docs: Add common dev workflows
1 parent 5676486 commit f63c0a8

File tree

1 file changed

+169
-12
lines changed

1 file changed

+169
-12
lines changed

CONTRIBUTING.md

Lines changed: 169 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,52 @@
22

33
A guide to making it easier to develop `weave-gitops-enterprise`. If you came here expecting but not finding an answer please make an issue to help improve these docs!
44

5+
## Tooling
6+
You will need the following tools installed on your local workstation:
7+
- Go 1.17
8+
9+
`brew install [email protected]`
10+
- Kubectl 1.23
11+
12+
`brew install [email protected]`
13+
- Helm 3.8.2
14+
15+
`brew install helm`
16+
- Kind 0.12.0 for creating a local Kubernetes cluster
17+
18+
`brew install kind`
19+
- Flux 0.29.5 for setting up Flux on a cluster
20+
21+
`brew install fluxcd/tap/flux`
22+
- Buf 1.4.0 for generating code from protobuf definitions
23+
24+
`brew install bufbuild/buf/buf`
25+
- clusterctl 1.1.3 for installing CAPI components on the cluster
26+
27+
`brew install clusterctl`
28+
29+
## The big picture
30+
Weave GitOps Enterprise (WGE) currently consists of the following components:
31+
- clusters-service
32+
The API of WGE. This is the component that backend engineers will be changing most often. Uses the [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) to convert our gRPC service definitions to HTTP endpoints.
33+
- ui-server
34+
The UI of WGE. This is the component that frontend engineers will be changing most often. Built in React and uses yarn as the package manager.
35+
- [cluster-bootstrap-controller](https://github.com/weaveworks/cluster-bootstrap-controller)
36+
Allows for custom Jobs to be executed on newly provisioned CAPI clusters. Most often, this will be used to install CNI which CAPI does not install. Without this controller, newly provisioned clusters would not be ready to be used by end users. Because it also references the CAPI CRD, it requires CAPI tooling to be installed first.
37+
- [cluster-controller](https://github.com/weaveworks/cluster-controller)
38+
Defines the CRD for declaring leaf clusters. A leaf cluster is a cluster that the management cluster can query via a kubeconfig. This controller ensures that kubeconfig secrets have been supplied for leaf clusters. Because it also references the CAPI CRD, it requires CAPI tooling to be installed first.
39+
- event-writer **Soon to be deprecated**
40+
41+
Subscribes to a NATS queue and listens for messages sent by the wkp-agent. These messages carry cluster information about leaf clusters which is then written to a file-based SQLite db.
42+
- wkp-agent **Soon to be deprecated**
43+
44+
Agent installed by end users to management cluster and leaf clusters with the purpose of reporting back cluster information to management cluster.
45+
46+
As part of the chart, other dependencies also get installed:
47+
- NATS **Soon to be deprecated**
48+
49+
Agents running on the management cluster or on leaf clusters send events to a NATS queue. event-writer receives these events from the queue and does its thing.
50+
551
## One-time setup
652
You need a github Personal Access Token to build the service. This
753
token needs at least the `repo` and `read:packages`
@@ -21,18 +67,129 @@ Finally, make sure you can access https://github.com/weaveworks/weave-gitops-ent
2167

2268
## Building the project
2369

24-
25-
To build all binaries and containers use the following command:
70+
To build all containers use the following command:
2671

2772
```bash
2873
# Builds everything - make sure you exported GITHUB_TOKEN as shown in
2974
# the one-time setup
3075
make GITHUB_BUILD_TOKEN=${GITHUB_TOKEN}
76+
```
77+
78+
79+
## Common dev workflows
80+
The following sections suggest some common dev workflows.
81+
82+
### How to do local dev on the API
83+
84+
Most of the code for the API is under `./cmd/clusters-service`. There's a Makefile in that directory with some helpful targets so when working on the API make sure to run these from that location instead of root. The following commands assume execution from `./cmd/clusters-service`.
85+
86+
To install gRPC tooling run:
87+
```sh
88+
make install
89+
```
90+
91+
The API endpoints are defined as gRPC definitions in `./cmd/clusters-service/api/capi_server.proto`. Therefore if you need to add or update an endpoint you need to first define it in there. For example the following endpoint is used to return the version of WGE.
3192

32-
# Builds just the binaries
33-
make binaries
93+
```proto
94+
// GetEnterpriseVersion returns the WeGO Enterprise version
95+
rpc GetEnterpriseVersion(GetEnterpriseVersionRequest)
96+
returns (GetEnterpriseVersionResponse){
97+
option (google.api.http) = {
98+
get: "/v1/enterprise/version"
99+
};
100+
}
101+
```
102+
103+
After making a change in the protobuf definition, you will need to run `make generate` to regenerate the code.
104+
105+
To run the service locally, run:
106+
```sh
107+
export CAPI_CLUSTERS_NAMESPACE=default
108+
go run main.go
109+
```
110+
111+
You can execute HTTP requests to the API by pointing to an endpoint, for example:
112+
```sh
113+
curl --insecure https://localhost:8000/v1/enterprise/version
114+
```
115+
The --insecure flag is needed because the service will generate self-signed untrusted certificates by default.
116+
117+
To run all unit tests before pushing run:
118+
```sh
119+
make unit-tests
34120
```
35121

122+
To run all tests, including integration tests run:
123+
```sh
124+
make test
125+
```
126+
127+
### How to do local dev on the controllers
128+
When working on controllers it's often easier to run them locally against kind clusters to avoid causing issues on shared clusters (i.e. demo-01) that may be used by other engineers. To install the CRDs on your local kind cluster run:
129+
130+
```sh
131+
make install
132+
```
133+
134+
To run the controller locally run:
135+
```sh
136+
make run
137+
```
138+
139+
To run all tests before pushing run:
140+
```sh
141+
make test
142+
```
143+
144+
### How to install everything from your working branch on a cluster
145+
When you push your changes to a remote branch (even before creating a PR for it), CI will kick off a build that runs a quick suite of tests and then builds your containers and creates a new Helm chart tagged with the most recent commit. This Helm chart includes all the changes from your branch and can be used to deploy WGE as a whole to a cluster.
146+
147+
1. Find the version of the Helm chart you need to deploy:
148+
```sh
149+
# Add the Helm repo locally (needs to happen only once)
150+
helm repo add weave-gitops-enterprise-charts https://charts.dev.wkp.weave.works/charts-v3 --username wge --password gitops
151+
_"weave-gitops-enterprise-charts" has been added to your repositories_
152+
# Search the Helm repo for the commit SHA that corresponds to your most recent commit
153+
helm repo update > /dev/null 2>&1 && helm search repo weave-gitops-enterprise-charts --devel --versions | grep <commit-SHA>
154+
weave-gitops-enterprise-charts/mccp <chart-version-with-commit-SHA> 1.16.0 A Helm chart for Kubernetes
155+
```
156+
157+
2. Create a new kind cluster and install flux
158+
```sh
159+
cat > kind-cluster-with-extramounts.yaml <<EOF
160+
kind: Cluster
161+
apiVersion: kind.x-k8s.io/v1alpha4
162+
nodes:
163+
- role: control-plane
164+
extraMounts:
165+
- hostPath: /var/run/docker.sock
166+
containerPath: /var/run/docker.sock
167+
EOF
168+
169+
kind create cluster --name kind --config=kind-cluster-with-extramounts.yaml
170+
export GITHUB_TOKEN=<your-GH-token>
171+
flux bootstrap github --owner=<your-GH-username> --repository=config --personal=true --path=clusters/kind
172+
```
173+
174+
3. Install CAPI
175+
```sh
176+
clusterctl init --infrastructure docker
177+
```
178+
179+
4. Install WGE
180+
```sh
181+
cat > values.yaml <<EOF
182+
tls:
183+
enabled: true
184+
config:
185+
capi:
186+
repositoryURL: <your config repo URL>
187+
EOF
188+
189+
kubectl apply -f ./test/utils/scripts/entitlement-secret.yaml
190+
flux create source helm weave-gitops-enterprise-charts --url=https://charts.dev.wkp.weave.works/charts-v3 --namespace=flux-system --secret-ref=weave-gitops-enterprise-credentials
191+
flux create hr weave-gitops-enterprise --namespace=flux-system --interval=10m --source=HelmRepository/weave-gitops-enterprise-charts --chart=mccp --chart-version=<chart-version-with-commit-SHA> --values values.yaml
192+
36193
## Thing to explore in the future
37194
38195
- **tilt files** for faster feedback loops when interactively developing kubernetes services.
@@ -144,20 +301,20 @@ yarn start
144301
145302
Open up http://localhost:3000. Changes to code will be hot-reloaded.
146303
147-
### UI against a local clusters-service
304+
### How to do local dev on the UI
148305
149-
When you need to develop the UI against new features that haven't made to the test cluster yet you can run your own clusters-service locally and point the UI dev server at it with:
306+
The easiest way to dev on the UI is to use an existing cluster. [demo-01](https://demo-01.wge.dev.weave.works/) is kept automatically up to date with every change that lands on main. To use it run the following command:
150307
151-
```bash
152-
CAPI_SERVER_HOST=http://localhost:8000 yarn start
308+
```sh
309+
PROXY_HOST=https://demo-01.wge.dev.weave.works/ yarn start
153310
```
154311
155-
### UI against a remote server
312+
The username/password used to login are stored in [1Password](https://start.1password.com/open/i?a=ALD7KP6DEJGYREYHXRNYI3F7KY&v=xdzphlycic6bzwggrot2y73jaa&i=jz6ytgxay7ktq5vg6w2wlu3m2i&h=weaveworks.1password.com).
156313
157-
If you need to use a remote server, set the `CAPI_SERVER_HOST` env var to the server's address before running `yarn start`:
314+
If you need to develop the UI against new features that haven't made to the test cluster yet, you can run your own clusters-service locally and point the UI dev server at it with:
158315
159-
```bash
160-
CAPI_SERVER_HOST=http://34.67.250.163:30080 yarn start
316+
```sh
317+
PROXY_HOST=http://localhost:8000 yarn start
161318
```
162319
163320
### Testing changes to an unreleased weave-gitops locally

0 commit comments

Comments
 (0)