Skip to content

Commit a265878

Browse files
docs: add development guide and tilt support (#744)
* chore: add tilt-based development environment closes: #41 closes: #135 Introduce a comprehensive Tilt setup for streamlined local development of the Kubeflow Notebooks workspace components (controller, backend, and frontend). Key features: * Orchestrated development workflow: Tiltfile manages the entire development lifecycle including cluster setup, dependency installation, Docker builds, and Kubernetes deployments * Automated infrastructure setup: - Kind cluster creation and verification via setup-kind.sh - Cert-manager installation via setup-cert-manager.sh - CRD installation with proper dependency ordering * Component integration: - Controller: Docker builds with code generation, CRD installation, and Kubernetes deployment with dev-specific overrides (USE_ISTIO=false) - Backend: Docker builds and Kubernetes deployment with port forwarding - Frontend: Docker builds with webpack dev server supporting hot reloading and Kubernetes deployment with dev-specific overrides - more memory/cpu to handle webpack compilation - startup probe to allow for webpack compilation * Frontend Tilt support: - New start:tilt npm script for Tilt-specific development - Enables standalone frontend mode with proper backend proxy configuration * Developer experience improvements: - File watching with intelligent exclusions to prevent rebuild loops - Resource dependency management ensuring proper startup order - Optional frontend via ENABLE_FRONTEND environment variable - Comprehensive documentation in DEVELOPMENT.md * Hot reloading and live updates: - Controller/backend/frontend changes trigger automatic Docker rebuilds and redeployments - Port forwards configured for easy local access This setup enables developers to iterate quickly on all components with minimal manual setup and configuration. Note: Paulo provided change to frontend logic to ensure paths are normalized to avoid routing issues when navigating in the browser. Signed-off-by: Andy Stoneberg <[email protected]> Signed-off-by: Paulo Rego <[email protected]> * chore: move frontend dockerfile Signed-off-by: Andy Stoneberg <[email protected]> * mathew: 1 Signed-off-by: Mathew Wicks <[email protected]> --------- Signed-off-by: Andy Stoneberg <[email protected]> Signed-off-by: Paulo Rego <[email protected]> Signed-off-by: Mathew Wicks <[email protected]> Co-authored-by: Mathew Wicks <[email protected]>
1 parent eac6059 commit a265878

File tree

13 files changed

+687
-3
lines changed

13 files changed

+687
-3
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Contributing Guide - Kubeflow Notebooks v2
2+
3+
Please see [`CONTRIBUTING.md`](https://github.com/kubeflow/notebooks/blob/main/CONTRIBUTING.md) in the `main` branch for the current contributing guidelines.
4+
5+
For information on developing Kubeflow Notebooks v2, please see [`DEVELOPMENT_GUIDE.md`](DEVELOPMENT_GUIDE.md).

DEVELOPMENT_GUIDE.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# Development Guide - Kubeflow Notebooks v2
2+
3+
Thanks for your interest in developing Kubeflow Notebooks v2!
4+
5+
This document provides instructions to help you set up your development environment and get started with contributing to the project.
6+
7+
Please refer to the [`CONTRIBUTING.md`](CONTRIBUTING.md) for general guidelines on contributing to the project.
8+
9+
## Project Structure
10+
11+
Kubeflow Notebooks v2 is organized into several key components:
12+
13+
- [`workspaces/controller`](workspaces/controller): A Kubernetes controller and webook written in Go.
14+
- [`workspaces/backend`](workspaces/backend): A backend API server written in Go _(note: also uses controller-runtime)_
15+
- [`workspaces/frontend`](workspaces/frontend): A React-based frontend application.
16+
17+
## Development Workflow
18+
19+
### STEP 1 - Find areas to contribute
20+
21+
- Check the [issue tracker](https://github.com/kubeflow/notebooks/issues?q=is%3Aissue%20state%3Aopen%20label%3Aarea%2Fv2) for open issues
22+
- __NOTE:__ please make a comment if you intend to work on an issue to avoid duplication of effort.
23+
- Introduce yourself on [`#kubeflow-notebooks` channel](https://www.kubeflow.org/docs/about/community/#kubeflow-slack-channels) and share your background/interests
24+
- Attend the [Kubeflow Notebooks WG Calls](https://www.kubeflow.org/docs/about/community/#kubeflow-community-meetings) and ask for guidance
25+
26+
### STEP 2 - Make code changes
27+
28+
- Keep changes focused and small
29+
- This guide covers two common approaches to set up your development environment:
30+
- [Developing with Tilt (Recommended)](#developing-with-tilt-recommended)
31+
- [Developing Locally](#developing-locally)
32+
- Ensure you add appropriate tests (unit and e2e) for new features or bug fixes
33+
- You may want to use interactive tools like [`k9s`](https://k9scli.io/) to help inspect your Kubernetes cluster during development
34+
35+
### STEP 3 - Run tests and linting
36+
37+
- Overall e2e Tests:
38+
- __TBA:__ instructions for running e2e tests will be added here once available.
39+
- Controller:
40+
- Unit Tests: `make test`
41+
- Integration Tests: `make test-e2e`
42+
- Linting: `make lint`
43+
- Backend:
44+
- Unit Tests: `make test`
45+
- Linting: `make lint`
46+
- Frontend:
47+
- Unit Tests + Linting: `npm run test`
48+
49+
### STEP 4 - Submit a pull request
50+
51+
- Follow the [contributing guidelines](CONTRIBUTING.md)
52+
- Remember to raise your PR against the `notebooks-v2` branch
53+
- Ensure your PR includes:
54+
- A clear description of the changes
55+
- Relevant issue references
56+
- Tests for new features or bug fixes
57+
- Passing tests and linting checks
58+
- Git Tips:
59+
- If you are brand new to git, see GitHub's [Git Guide](https://github.com/git-guides)
60+
- For more advanced git usage, see the [Git Book](https://git-scm.com/book/en/v2)
61+
- Unless you are confident it's not appropriate, please [__SQUASH__ your commits](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History) to a __single commit__ before requesting a PR review.
62+
- `git rebase -i HEAD~n` where `n` is the number of commits to squash.
63+
- Mark all but the first commit as `squash` or `s`.
64+
- Edit the commit message as needed.
65+
66+
## Developing with Tilt (recommended)
67+
68+
[Tilt](https://github.com/tilt-dev/tilt) makes it much easier to develop Kubernetes controllers (especially with webhooks) locally by providing a live-reload development environment.
69+
70+
### Tilt - Prerequisites
71+
72+
Before using Tilt, ensure you have the following installed:
73+
74+
- [Tilt](https://docs.tilt.dev/install.html) - v0.33.0 or later
75+
- [Docker](https://docs.docker.com/get-docker/) - for building and running containers
76+
- [Kubernetes cluster](https://kubernetes.io/docs/setup/) - a local cluster (e.g., [Kind](https://kind.sigs.k8s.io/))
77+
- [kubectl](https://kubernetes.io/docs/tasks/tools/) - configured to connect to your cluster
78+
79+
### Tilt - Quick Start
80+
81+
First, verify that you have the required tools installed and check their versions:
82+
83+
```bash
84+
tilt version
85+
docker --version
86+
kubectl version --client
87+
```
88+
89+
You can now start developing with Tilt by following these steps:
90+
91+
```bash
92+
# (from the root of the repository)
93+
cd developing
94+
make tilt-up
95+
```
96+
97+
What this does:
98+
99+
- Set up the Kind cluster (if it doesn't exist)
100+
- Install cert-manager
101+
- Open the Tilt UI in your browser (usually http://localhost:10350)
102+
- Build and deploy the controller, backend, and frontend (if enabled) to your Kubernetes cluster
103+
- Set up port forwards for easy access
104+
- Enable live updates when you make code changes
105+
106+
> [!IMPORTANT]
107+
>
108+
> Always use `make tilt-up` instead of running `tilt up` directly.
109+
>
110+
> The Makefile ensures:
111+
> - The Kind cluster exists and is properly configured
112+
> - The Kubernetes context is switched to `kind-tilt`
113+
> - Cert-manager is installed (required for webhooks)
114+
> - All prerequisites are met before Tilt starts
115+
116+
> [!TIP]
117+
>
118+
> To run Tilt without the frontend (useful for backend/controller-only development):
119+
>
120+
> ```bash
121+
> ENABLE_FRONTEND=false make tilt-up
122+
> ```
123+
124+
Wait until all resources show green/healthy status.
125+
The frontend may take a couple of minutes on first start as webpack compiles the bundle.
126+
127+
Access the components:
128+
129+
- Controller health: `http://localhost:8081/healthz`
130+
- Backend API: [Swagger UI](http://localhost:4000/api/v1/swagger/)
131+
- Frontend UI: `http://localhost:9000` (if enabled)
132+
133+
You can now make changes to the codebase, and Tilt will automatically rebuild and redeploy the affected components.
134+
135+
### Tilt - Clean Up
136+
137+
When you are done developing with Tilt, you can stop it and clean up the resources.
138+
139+
```bash
140+
# In the terminal where Tilt is running, press Ctrl+C
141+
142+
# or in another terminal
143+
# (from the root of the repository)
144+
cd developing
145+
make tilt-down
146+
```
147+
148+
What this does:
149+
150+
- Stop all Tilt-managed resources
151+
- Clean up deployments (but not the namespace)
152+
153+
If you want to completely remove the Kind cluster, you can do so with:
154+
155+
```bash
156+
kind delete cluster --name tilt
157+
```
158+
159+
## Tilt - Troubleshooting
160+
161+
It tilt fails to start, check the logs in the Tilt UI for specific error messages.
162+
163+
Alternatively, you can try building the components manually to identify issues:
164+
165+
```bash
166+
# test controller build
167+
# (from the root of the repository)
168+
cd workspaces/controller
169+
make build
170+
171+
# test backend build
172+
# (from the root of the repository)
173+
cd workspaces/backend
174+
make build
175+
176+
# test frontend build
177+
# (from the root of the repository)
178+
cd workspaces/frontend
179+
npm ci
180+
npm run build:prod
181+
```
182+
183+
> [!TIP]
184+
>
185+
> If you see the following error while `Tilt` is trying to build an image:
186+
>
187+
> ```text
188+
> Build Failed: failed to dial gRPC: unable to upgrade to h2c, received 404
189+
> ```
190+
>
191+
> Try disabling Docker BuildKit support in the terminal where you are running `make tilt-up`:
192+
> ```bash
193+
> export DOCKER_BUILDKIT=0
194+
> ```
195+
196+
> [!TIP]
197+
>
198+
> If you encounter other strange issues.
199+
>
200+
> Try deleting the Kind cluster and starting fresh:
201+
>
202+
> ```bash
203+
> kind delete cluster --name tilt
204+
> ```
205+
206+
## Developing Locally
207+
208+
If you prefer to develop without Tilt, you can set up your environment to build and run the Kubeflow Notebooks v2 controller locally.
209+
210+
> [!WARNING]
211+
>
212+
> When developing locally, it can be challenging to configure the webhooks correctly as they will be running on your local machine rather than inside the cluster.
213+
> As webhooks are critical to the behavior of Kubeflow Notebooks v2, make sure you are aware of this limitation.
214+
215+
### Local - Prerequisites
216+
217+
Before developing locally, ensure you have the following installed:
218+
219+
- [Go](https://golang.org/doc/install) - v1.21.0 or later (for controller and backend)
220+
- [Node.js](https://nodejs.org/) - v20.0.0 or later (for frontend)
221+
222+
### Local - Quick Start
223+
224+
Each component has a `Makefile` or `package.json` to help with building, testing, and running the component locally.
225+
You should start by reviewing the these files in each component directory.
226+
227+
We welcome contributions to improve the local development experience, please open an issue or PR!

developing/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin/*

developing/Makefile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
.PHONY: check-tilt tilt-up tilt-down setup-kind setup-cert-manager kustomize
2+
3+
# Variables
4+
CLUSTER_NAME := tilt
5+
KIND_CONTEXT := kind-$(CLUSTER_NAME)
6+
7+
# Location to install dependencies to
8+
LOCALBIN ?= $(shell pwd)/bin
9+
$(LOCALBIN):
10+
mkdir -p $(LOCALBIN)
11+
12+
# Tool Binaries
13+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
14+
15+
# Tool Versions
16+
KUSTOMIZE_VERSION ?= v5.5.0
17+
18+
# Export KIND_EXPERIMENTAL_PROVIDER to honor it if set in user's environment
19+
# (e.g., KIND_EXPERIMENTAL_PROVIDER=podman for podman support)
20+
export KIND_EXPERIMENTAL_PROVIDER
21+
22+
# Check if tilt is installed
23+
.PHONY: check-tilt
24+
check-tilt:
25+
@if ! command -v tilt >/dev/null 2>&1; then \
26+
echo "ERROR: tilt is not installed. Please install tilt first:"; \
27+
echo " curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash"; \
28+
echo " or visit: https://docs.tilt.dev/install.html"; \
29+
exit 1; \
30+
fi
31+
32+
# Ensure kind cluster exists and context is set before running tilt
33+
setup-kind:
34+
@echo "Setting up Kind cluster..."
35+
@if [ -n "$$KIND_EXPERIMENTAL_PROVIDER" ]; then \
36+
echo "Using KIND_EXPERIMENTAL_PROVIDER=$$KIND_EXPERIMENTAL_PROVIDER"; \
37+
fi
38+
@./scripts/setup-kind.sh
39+
40+
# Install cert-manager (depends on kind cluster being set up)
41+
setup-cert-manager: setup-kind
42+
@echo "Setting up cert-manager..."
43+
@./scripts/setup-cert-manager.sh
44+
45+
46+
# Run tilt up with kind cluster and cert-manager setup
47+
tilt-up: check-tilt setup-cert-manager kustomize
48+
@echo "Starting Tilt..."
49+
@tilt up
50+
51+
52+
# Stop Tilt
53+
tilt-down: check-tilt kustomize
54+
@echo "Stopping Tilt..."
55+
@tilt down
56+
57+
# Install kustomize
58+
kustomize: $(KUSTOMIZE)
59+
$(KUSTOMIZE): $(LOCALBIN)
60+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
61+
62+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
63+
# $1 - target path with name of binary
64+
# $2 - package url which can be installed
65+
# $3 - specific version of package
66+
define go-install-tool
67+
@[ -f "$(1)-$(3)" ] || { \
68+
set -e; \
69+
package=$(2)@$(3) ;\
70+
echo "Downloading $${package}" ;\
71+
rm -f $(1) || true ;\
72+
GOBIN=$(LOCALBIN) go install $${package} ;\
73+
mv $(1) $(1)-$(3) ;\
74+
} ;\
75+
ln -sf $(1)-$(3) $(1)
76+
endef
77+

developing/OWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
labels:
2+
- area/ci
3+
- area/v2
4+
approvers:
5+
- andyatmiami

0 commit comments

Comments
 (0)