|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Telepresence is a Kubernetes development tool that enables fast local development by connecting your local workstation to a Kubernetes cluster. It allows developers to run services locally while accessing cluster resources and intercepting traffic from the cluster to their local machine. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Set required environment variables |
| 13 | +export TELEPRESENCE_VERSION=v2.x.x-alpha.0 # or use auto-generated version |
| 14 | +export TELEPRESENCE_REGISTRY=local # 'local' for Docker Desktop, or 'ghcr.io/telepresenceio' |
| 15 | + |
| 16 | +# Build the telepresence binary |
| 17 | +make build |
| 18 | + |
| 19 | +# Build Docker images (for local Kubernetes development) |
| 20 | +make client-image # Client container image |
| 21 | +make tel2-image # Traffic-manager/traffic-agent image |
| 22 | + |
| 23 | +# Build everything for local development |
| 24 | +make build client-image tel2-image |
| 25 | + |
| 26 | +# Install to system |
| 27 | +make install |
| 28 | + |
| 29 | +# Clean build artifacts |
| 30 | +make clean |
| 31 | +make clobber # Also removes tools |
| 32 | +``` |
| 33 | + |
| 34 | +## Testing |
| 35 | + |
| 36 | +```bash |
| 37 | +# Run unit tests |
| 38 | +make check-unit |
| 39 | + |
| 40 | +# Run all integration tests (requires Kubernetes cluster) |
| 41 | +make check-integration |
| 42 | + |
| 43 | +# Run a single integration test |
| 44 | +go test ./integration_test/... -v -testify.m=Test_InterceptDetailedOutput |
| 45 | + |
| 46 | +# Run an integration test suite |
| 47 | +TEST_SUITE='^WorkloadConfiguration$' go test ./integration_test/... -v |
| 48 | + |
| 49 | +# Build tests without running (useful for caching) |
| 50 | +make build-tests |
| 51 | +``` |
| 52 | + |
| 53 | +Integration tests use testify suites. The test harness is in `integration_test/itest/`. Use `-testify.m=<pattern>` to filter tests by name. |
| 54 | + |
| 55 | +## Linting |
| 56 | + |
| 57 | +```bash |
| 58 | +# Run all linters |
| 59 | +make lint |
| 60 | + |
| 61 | +# Run Go linter only |
| 62 | +make lint-go |
| 63 | + |
| 64 | +# Run protobuf linter only |
| 65 | +make lint-rpc |
| 66 | + |
| 67 | +# Auto-fix lint issues |
| 68 | +make format |
| 69 | +``` |
| 70 | + |
| 71 | +Linting uses golangci-lint v2 running in Docker. Configuration is in `.golangci.yml`. |
| 72 | + |
| 73 | +## Code Generation |
| 74 | + |
| 75 | +```bash |
| 76 | +# Regenerate protobuf and license files |
| 77 | +make generate |
| 78 | + |
| 79 | +# Regenerate protobuf files only |
| 80 | +make protoc |
| 81 | +``` |
| 82 | + |
| 83 | +## Architecture |
| 84 | + |
| 85 | +### Main Components |
| 86 | + |
| 87 | +1. **CLI/Client** (`cmd/telepresence/`, `pkg/client/cli/`) |
| 88 | + - Single binary serving as CLI, user daemon, and root daemon |
| 89 | + - Commands are in `pkg/client/cli/cmd/` |
| 90 | + |
| 91 | +2. **User Daemon (userd)** (`pkg/client/userd/`) |
| 92 | + - Runs as the user, manages connection to traffic-manager |
| 93 | + - Handles intercepts, port forwards, cluster communication |
| 94 | + |
| 95 | +3. **Root Daemon (rootd)** (`pkg/client/rootd/`) |
| 96 | + - Runs with elevated privileges |
| 97 | + - Manages virtual network interface (VIF) and DNS |
| 98 | + |
| 99 | +4. **Traffic Manager** (`cmd/traffic/cmd/manager/`) |
| 100 | + - Runs in the Kubernetes cluster (ambassador namespace by default) |
| 101 | + - Coordinates intercepts between clients and traffic-agents |
| 102 | + |
| 103 | +5. **Traffic Agent** (`cmd/traffic/cmd/agent/`) |
| 104 | + - Injected as sidecar into intercepted pods |
| 105 | + - Routes traffic between the pod and the local machine |
| 106 | + |
| 107 | +6. **Agent Init** (`cmd/traffic/cmd/agentinit/`) |
| 108 | + - Init container for setting up iptables rules in pods |
| 109 | + |
| 110 | +### Key Packages |
| 111 | + |
| 112 | +- `pkg/vif/` - Virtual network interface implementation |
| 113 | +- `pkg/tunnel/` - gRPC-based tunneling for network traffic |
| 114 | +- `pkg/dnsproxy/` - DNS resolution and proxying |
| 115 | +- `pkg/agentconfig/` - Traffic-agent configuration |
| 116 | +- `pkg/client/k8s/` - Kubernetes client interactions |
| 117 | +- `pkg/routing/` - Network routing logic |
| 118 | + |
| 119 | +### RPC Definitions |
| 120 | + |
| 121 | +Protocol buffers are in `rpc/` with separate packages: |
| 122 | +- `rpc/connector/` - Client-to-userd communication |
| 123 | +- `rpc/daemon/` - Client-to-rootd communication |
| 124 | +- `rpc/manager/` - Client/userd-to-traffic-manager communication |
| 125 | +- `rpc/agent/` - Traffic-manager-to-traffic-agent communication |
| 126 | + |
| 127 | +### Helm Chart |
| 128 | + |
| 129 | +The traffic-manager Helm chart is in `charts/telepresence-oss/`. |
| 130 | + |
| 131 | +## Local Development with Docker Desktop |
| 132 | + |
| 133 | +For fastest iteration when using Docker Desktop with Kubernetes: |
| 134 | + |
| 135 | +```bash |
| 136 | +export TELEPRESENCE_VERSION=v2.x.x-alpha.0 |
| 137 | +export TELEPRESENCE_REGISTRY=local |
| 138 | +make build client-image tel2-image |
| 139 | + |
| 140 | +# Install traffic-manager with debug logging |
| 141 | +./build-output/bin/telepresence helm install --set logLevel=debug,image.pullPolicy=Never,agent.image.pullPolicy=Never |
| 142 | + |
| 143 | +# Connect to cluster |
| 144 | +./build-output/bin/telepresence connect |
| 145 | +``` |
| 146 | + |
| 147 | +## Integration Test Configuration |
| 148 | + |
| 149 | +Tests can be configured via environment variables or `itest.yml` file placed next to `config.yml`: |
| 150 | + |
| 151 | +```yaml |
| 152 | +Env: |
| 153 | + DEV_CLIENT_VERSION: v2.x.x-alpha.0 |
| 154 | + DEV_KUBECONFIG: /path/to/kubeconfig |
| 155 | +Config: |
| 156 | + docker: |
| 157 | + addHostGateway: false |
| 158 | +``` |
| 159 | +
|
| 160 | +Key environment variables: |
| 161 | +- `DEV_KUBECONFIG` - Kubernetes config for tests |
| 162 | +- `DEV_CLIENT_REGISTRY`, `DEV_MANAGER_REGISTRY`, `DEV_AGENT_REGISTRY` - Image registries |
| 163 | +- `TEST_SUITE` - Regexp to filter test suites |
| 164 | + |
| 165 | +## Log Files |
| 166 | + |
| 167 | +- macOS: `~/Library/Logs/telepresence/` |
| 168 | +- Linux: `~/.cache/telepresence/logs/` |
| 169 | +- Windows: `%USERPROFILE%\AppData\Local\logs` |
| 170 | + |
| 171 | +Files: `daemon.log` (rootd), `connector.log` (userd), `cli.log` (CLI) |
| 172 | + |
| 173 | +## Debugging Daemons |
| 174 | + |
| 175 | +```bash |
| 176 | +# Run daemon with stderr logging |
| 177 | +telepresence userd --logfile - |
| 178 | +telepresence rootd --logfile - |
| 179 | +
|
| 180 | +# Enable pprof profiling |
| 181 | +telepresence connect --userd-profiling-port 6060 --rootd-profiling-port 6061 |
| 182 | +# Then browse http://localhost:6060/debug/pprof/ |
| 183 | +``` |
0 commit comments