Skip to content
Open
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
7 changes: 7 additions & 0 deletions developing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin/*
305 changes: 305 additions & 0 deletions developing/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
# Development Guide with Tilt

This directory contains the Tilt configuration for local development of the Kubeflow Notebooks workspace components (controller, backend, and frontend).

## Table of Contents

- [Prerequisites](#prerequisites)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Development Workflow](#development-workflow)
- [Frontend Development](#frontend-development)
- [Troubleshooting](#troubleshooting)
- [Best Practices](#best-practices)

## Prerequisites

Before using Tilt, ensure you have the following installed:

- [Tilt](https://docs.tilt.dev/install.html) - v0.30.0 or later
- [Docker](https://docs.docker.com/get-docker/) - for building and running containers
- [Kubernetes cluster](https://kubernetes.io/docs/setup/) - a local cluster (e.g., [Kind](https://kind.sigs.k8s.io/))
- [kubectl](https://kubernetes.io/docs/tasks/tools/) - configured to connect to your cluster
- [Go](https://golang.org/doc/install) - v1.21.0 or later (for controller and backend)
- [Node.js](https://nodejs.org/) - v20.0.0 or later (for frontend)

### Verify Prerequisites

```bash
# Check Tilt
tilt version

# Check Docker
docker --version

# Check kubectl
kubectl version --client

# Check Go (for controller/backend)
go version

# Check Node.js (for frontend, if enabled)
node --version
npm --version
```

### Install Kind

**Note**: The Makefile will automatically create a Kind cluster named `tilt` if it doesn't exist. However, you still need to have `kind` installed.

```bash
# macOS
brew install kind

# Or follow instructions at: https://kind.sigs.k8s.io/docs/user/quick-start/#installation
```


### Using Kind Provider (Optional)

You can choose to set the `KIND_EXPERIMENTAL_PROVIDER` environment variable in your shell session:

```bash
export KIND_EXPERIMENTAL_PROVIDER=podman
```

The Makefile will honor this environment variable when creating the Kind cluster.

## Quick Start

1. **Navigate to the developing directory**:
```bash
cd developing
```

2. **Start Tilt using the Makefile**:
```bash
make tilt
```

**Important**: Always use `make tilt` instead of running `tilt up` directly. The Makefile ensures:
- The Kind cluster exists and is properly configured
- The Kubernetes context is switched to `kind-tilt`
- Cert-manager is installed (required for webhooks)
- All prerequisites are met before Tilt starts

This will:
- Set up the Kind cluster (if it doesn't exist)
- Install cert-manager
- Open the Tilt UI in your browser (usually http://localhost:10350)
- Build the controller and backend Docker images
- Deploy them to your Kubernetes cluster
- Run the frontend locally with webpack dev server (if enabled)
- Set up port forwards for easy access
- Enable live updates when you make code changes

3. **Monitor the Build**:

Watch the Tilt UI in your browser. You should see:

1. **Local Resources**:
- `controller-generate` - Generating manifests and code
- `install-crds` - Installing CRDs
- `workspaces-frontend` - Running webpack dev server (if enabled)

2. **Docker Resources** (building images):
- `workspaces-controller`
- `workspaces-backend`

3. **Kubernetes Resources** (deploying):
- Deployments, Services, etc.

**Note**: The Kind cluster and cert-manager setup are handled by the Makefile before Tilt starts, so you won't see those as Tilt resources.

Wait until all resources show green/healthy status.

5. **Access the componenets**:
- Controller health: `http://localhost:8081/healthz`
- Backend API: [Swagger UI](http://localhost:4000/api/v1/swagger/)
- Frontend UI: `http://localhost:9000` (if enabled)

6. **Stop Tilt**:
```bash
# In the terminal where Tilt is running, press Ctrl+C
# Or in another terminal:
make tilt-down
# Or:
tilt down
```

This will:
- Stop all Tilt-managed resources
- Clean up deployments (but not the namespace)

### Optional: Clean up namespace

```bash
kubectl delete namespace kubeflow-workspaces
```

### Optional: Delete Kind cluster

```bash
kind delete cluster --name tilt
```

## Configuration

### Makefile Targets

The Makefile provides several targets for managing your development environment:

- `make tilt` or `make` - Set up Kind cluster, install cert-manager, and start Tilt
- `make tilt-up` - Alias for `make tilt`
- `make tilt-down` - Stop Tilt
- `make setup-kind` - Set up the Kind cluster only (without starting Tilt)
- `make setup-cert-manager` - Install cert-manager only (requires Kind cluster)

### Skipping Frontend

To run Tilt without the frontend (useful for backend/controller-only development):

```bash
ENABLE_FRONTEND=false make tilt
```

### Custom Ports

Port forwards are configured in the Tiltfile. To change them, edit the `port_forwards` parameter in the `k8s_resource()` calls.

## Development Workflow

1. **Make code changes** in any of the workspace components
- Keep changes focused and small
2. **Tilt automatically detects changes**:
- Controller/Backend: Rebuilds Docker images and redeploys
- Frontend: Webpack dev server hot-reloads changes automatically
3. **View logs** in the Tilt UI or via `tilt logs <resource-name>`
4. **Add tests** for any new features
5. **Run linting checks** to ensure code style consistency
5. **Ensure tests pass** before opening a PR
6. **Write meaningful commit messages** highlighting what your code contribution is doing
7. **Be responsive** to feedback on the PR

## Frontend Development

The frontend runs as a local resource using webpack dev server instead of being built into a Docker image. This provides:

1. **Fast Hot Reloading**: Changes appear instantly in the browser without rebuilding Docker images
2. **Better Developer Experience**: Full webpack dev server features (source maps, hot module replacement, etc.)
3. **Faster Iteration**: No Docker build step needed for frontend changes
4. **Proxy Configuration**: Webpack dev server proxies API requests to the backend running in Kubernetes

The frontend uses the `.env.tilt` file for configuration when running with Tilt, which sets it up for standalone mode with proper proxy settings to connect to the backend.

## Troubleshooting

### Build Failures

If builds fail, check:

```bash
# Controller build issues
cd workspaces/controller && make build

# Backend build issues
cd workspaces/backend && make build

# Frontend dev server issues (for Tilt development)
cd workspaces/frontend && npm ci && npm run start:tilt

# Frontend production build issues (for testing production builds)
cd workspaces/frontend && npm ci && npm run build:prod
```

Also verify:
- All prerequisites are installed
- Makefiles can find their dependencies
- Go modules are downloaded (`go mod download` in controller/backend)
- Node modules are installed (`npm ci` in frontend)

#### BuildKit

If you see the following error while `Tilt` is trying to build an image:
```
Build Failed: failed to dial gRPC: unable to upgrade to h2c, received 404
```

Try disabling Docker BuildKit support in the terminal where you are running `tilt up`:
```bash
export DOCKER_BUILDKIT=0
```


### Kubernetes Connection Issues

The Makefile automatically handles context switching to `kind-tilt`. If you encounter issues:

1. **Verify the Kind cluster exists**:
```bash
kind get clusters
```

2. **Check the current context**:
```bash
kubectl config current-context
# Should be: kind-tilt
```

3. **If context is wrong, manually switch**:
```bash
kubectl config use-context kind-tilt
```

4. **Verify cluster is accessible**:
```bash
kubectl cluster-info
```

5. **Ensure you have permissions** to create resources in the `kubeflow-workspaces` namespace

**Note**: If you're running `tilt up` directly (not via `make tilt`), you may be on the wrong Kubernetes context. Always use `make tilt` to ensure the correct context is set.

### Port Already in Use

If ports are already in use, you can:

1. Stop the conflicting service
2. Or modify port forwards in the Tiltfile

### CRD Installation Fails

If CRDs fail to install:

```bash
# Check if you have permissions
kubectl auth can-i create crds

# Try installing manually
cd workspaces/controller && make install
```

Also check that you have cluster-admin permissions or appropriate RBAC.

## Best Practices

1. **Run tests before committing**:
```bash
# Controller
cd workspaces/controller && make lint && make test

# Backend
cd workspaces/backend && make lint && make test

# Frontend
cd workspaces/frontend && npm run test
```

2. **Keep dependencies up to date**:
- Go modules: `go mod tidy` in controller/backend
- Node modules: `npm ci` in frontend

3. **Clean up resources**:
- Always run `make tilt-down` (or `tilt down`) when done
- Optionally: `kubectl delete namespace kubeflow-workspaces`
- Optionally: `kind delete cluster --name tilt` to remove the Kind cluster
77 changes: 77 additions & 0 deletions developing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.PHONY: check-tilt tilt-up tilt-down setup-kind setup-cert-manager kustomize

# Variables
CLUSTER_NAME := tilt
KIND_CONTEXT := kind-$(CLUSTER_NAME)

# Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

# Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize

# Tool Versions
KUSTOMIZE_VERSION ?= v5.5.0

# Export KIND_EXPERIMENTAL_PROVIDER to honor it if set in user's environment
# (e.g., KIND_EXPERIMENTAL_PROVIDER=podman for podman support)
export KIND_EXPERIMENTAL_PROVIDER

# Check if tilt is installed
.PHONY: check-tilt
check-tilt:
@if ! command -v tilt >/dev/null 2>&1; then \
echo "ERROR: tilt is not installed. Please install tilt first:"; \
echo " curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash"; \
echo " or visit: https://docs.tilt.dev/install.html"; \
exit 1; \
fi

# Ensure kind cluster exists and context is set before running tilt
setup-kind:
@echo "Setting up Kind cluster..."
@if [ -n "$$KIND_EXPERIMENTAL_PROVIDER" ]; then \
echo "Using KIND_EXPERIMENTAL_PROVIDER=$$KIND_EXPERIMENTAL_PROVIDER"; \
fi
@./scripts/setup-kind.sh

# Install cert-manager (depends on kind cluster being set up)
setup-cert-manager: setup-kind
@echo "Setting up cert-manager..."
@./scripts/setup-cert-manager.sh


# Run tilt up with kind cluster and cert-manager setup
tilt-up: check-tilt setup-cert-manager kustomize
@echo "Starting Tilt..."
@tilt up


# Stop Tilt
tilt-down: check-tilt kustomize
@echo "Stopping Tilt..."
@tilt down

# Install kustomize
kustomize: $(KUSTOMIZE)
$(KUSTOMIZE): $(LOCALBIN)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef

5 changes: 5 additions & 0 deletions developing/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
labels:
- area/ci
- area/v2
approvers:
- andyatmiami
Loading