Skip to content

Commit 167caa3

Browse files
authored
Merge pull request #1415 from ArthurSens/as/codespace-workspaces
Better ephemeral workspace support with Codespaces
2 parents 16e3663 + 4fe501d commit 167caa3

File tree

11 files changed

+69
-5
lines changed

11 files changed

+69
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ vendor/
55
.swp
66
crdschemas/
77

8-
.gitpod/_output/
8+
developer-workspace/gitpod/_output
9+
kind

.gitpod.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ tasks:
2424
chmod +x ${PWD}/.git/hooks/pre-commit
2525
- name: run kube-prometheus
2626
command: |
27-
.gitpod/prepare-k3s.sh
28-
.gitpod/deploy-kube-prometheus.sh
27+
developer-workspace/gitpod/prepare-k3s.sh
28+
developer-workspace/common/deploy-kube-prometheus.sh
2929
- name: kernel dev environment
3030
init: |
3131
sudo apt update -y
3232
sudo apt install qemu qemu-system-x86 linux-image-$(uname -r) libguestfs-tools sshpass netcat -y
3333
sudo curl -o /usr/bin/kubectl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
3434
sudo chmod +x /usr/bin/kubectl
35-
.gitpod/prepare-rootfs.sh
35+
developer-workspace/gitpod/prepare-rootfs.sh
3636
command: |
37-
.gitpod/qemu.sh
37+
developer-workspace/gitpod/qemu.sh
3838
ports:
3939
- port: 3000
4040
onOpen: open-browser

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ $(BIN_DIR):
7878
$(TOOLING): $(BIN_DIR)
7979
@echo Installing tools from scripts/tools.go
8080
@cd scripts && cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go build -modfile=go.mod -o $(BIN_DIR) %
81+
82+
.PHONY: deploy
83+
deploy:
84+
./developer-workspace/codespaces/prepare-kind.sh
85+
./developer-workspace/common/deploy-kube-prometheus.sh

developer-workspace/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Ephemeral developer workspaces
2+
3+
Aiming to provide better developer experience when making contributions to kube-prometheus, whether by actively developing new features/bug fixes or by reviewing pull requests, we want to provide ephemeral developer workspaces with everything already configured (as far as tooling makes it possible).
4+
5+
Those developer workspaces should provide a brand new kubernetes cluster, where kube-prometheus can be easily deployed and the contributor can easily see the impact that a pull request is proposing.
6+
7+
Today there is 2 providers in the market:
8+
* [Github Codespaces](https://github.com/features/codespaces)
9+
* [Gitpod](https://www.gitpod.io/)
10+
11+
## Codespaces
12+
13+
Unfortunately, Codespaces is not available for everyone. If you are fortunate to have access to it, you can open a new workspace from a specific branch, or even from Pull Requests.
14+
15+
![image](https://user-images.githubusercontent.com/24193764/135522435-44b177b4-00d4-4863-b45b-2db47c8c70d0.png)
16+
17+
![image](https://user-images.githubusercontent.com/24193764/135522560-c64968ab-3b4e-4639-893a-c4d0a14421aa.png)
18+
19+
After your workspace start, you can deploy a kube-prometheus inside a Kind cluster inside by running `make deploy`.
20+
21+
If you are reviewing a PR, you'll have a fully-functional kubernetes cluster, generating real monitoring data that can be used to review if the proposed changes works as described.
22+
23+
If you are working on new features/bug fixes, you can regenerate kube-prometheus's YAML manifests with `make generate` and deploy it again with `make deploy`.
24+
25+
## Gitpod
26+
27+
Gitpod is already available to everyone to use for free. It can also run commands that we speficy in the `.gitpod.yml` file located in the root directory of the git repository, so even the cluster creation can be fully automated.
28+
29+
You can use the same workflow as mentioned in the [Codespaces](#Codespaces) section, however Gitpod doesn't have native support for any kubernetes distribution. The workaround is to create a full QEMU Virtual Machine and deploy [k3s](https://github.com/k3s-io/k3s) inside this VM. Don't worry, this whole process is already fully automated, but due to the workaround the whole workspace may be very slow.
30+
31+
To open up a workspace with Gitpod, you can install the [Google Chrome extension](https://www.gitpod.io/docs/browser-extension/) to add a new button to Github UI and use it on PRs or from the main page. Or by directly typing in the browser `http://gitpod.io/#https://github.com/prometheus-operator/kube-prometheus/pull/<Pull Request Number>` or just `http://gitpod.io/#https://github.com/prometheus-operator/kube-prometheus`
32+
33+
![image](https://user-images.githubusercontent.com/24193764/135534546-4f6bf0e5-57cd-4e35-ad80-88bd47d64276.png)
34+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
which kind
4+
if [[ $? != 0 ]]; then
5+
echo 'kind not available in $PATH, installing latest kind'
6+
# Install latest kind
7+
curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest \
8+
| grep "browser_download_url.*kind-linux-amd64" \
9+
| cut -d : -f 2,3 \
10+
| tr -d \" \
11+
| wget -qi -
12+
mv kind-linux-amd64 kind && chmod +x kind
13+
fi
14+
15+
cluster_created=$($PWD/kind get clusters 2>&1)
16+
if [[ "$cluster_created" == "No kind clusters found." ]]; then
17+
$PWD/kind create cluster
18+
else
19+
echo "Cluster '$cluster_created' already present"
20+
fi

.gitpod/deploy-kube-prometheus.sh renamed to developer-workspace/common/deploy-kube-prometheus.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
#!/bin/bash
2+
13
kubectl apply -f manifests/setup
24

35
# Safety wait for CRDs to be working
46
sleep 30
57

68
kubectl apply -f manifests/
9+
sleep 30
10+
# Safety wait for resources to be created
711

812
kubectl rollout status -n monitoring daemonset node-exporter
913
kubectl rollout status -n monitoring statefulset alertmanager-main
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)