forked from agentgateway/agentgateway
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTiltfile
More file actions
177 lines (159 loc) · 5.89 KB
/
Tiltfile
File metadata and controls
177 lines (159 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Tiltfile for AgentGateway development
# This deploys both control plane (Go) and data plane (Rust) to Kind with live updates
load('ext://restart_process', 'docker_build_with_restart')
load('ext://helm_resource', 'helm_resource', 'helm_repo')
# Configuration
version = 'v1.0.1-dev'
cluster_name = 'kind'
install_namespace = k8s_namespace()
image_registry = 'localhost:5000'
# Ensure Kind cluster exists
allow_k8s_contexts('kind-' + cluster_name)
# Helper to run Make targets
def run_make(target, cwd='.'):
return local('make -C ' + cwd + ' ' + target)
def run_controller_make(target):
return run_make(target, cwd='./controller')
# =============================================================================
# Setup: Ensure cluster is ready
# =============================================================================
# Check if kind cluster exists, create if not
if str(local('kind get clusters 2>/dev/null | grep -c "^' + cluster_name + '$" || true')).strip() == '0':
print('No kind cluster! create one and restart tilt after doing so. You can use this command:')
print('ctlptl create cluster kind --name kind-' + cluster_name + ' --registry=ctlptl-registry')
fail("started kind cluster. Create one and run tilt again")
print('Installing Gateway API CRDs...')
run_controller_make('gw-api-crds')
run_controller_make('gie-crds')
# Install CRDs
print('Installing AgentGateway CRDs...')
helm_resource(
'agentgateway-crds',
'controller/install/helm/agentgateway-crds',
namespace=install_namespace,
flags=['--set=version=' + version],
)
# =============================================================================
# Control Plane (Go-based controller)
# =============================================================================
local_resource(
'go-compile-controller',
'make -C ./controller VERSION=' + version + ' GCFLAGS=all="-N -l" agentgateway-controller && mv ./controller/_output/pkg/agentgateway/agentgateway-linux-$(go env GOARCH) ./tools/tilt/agentgateway-controller',
deps=['./controller/'],
ignore=['./controller/_output/'],
)
# Build control plane Docker image
docker_build_with_restart(
image_registry + '/agentgateway-controller',
context='./tools/tilt/',
entrypoint='/usr/local/bin/agentgateway-controller',
dockerfile_contents="""
FROM ubuntu:24.04
COPY agentgateway-controller /usr/local/bin/agentgateway-controller
ENTRYPOINT /usr/local/bin/agentgateway-controller
""",
# Live update: sync Go binaries
live_update=[
# Sync Go code changes
sync('./tools/tilt/agentgateway-controller', '/usr/local/bin/agentgateway-controller'),
],
only=[
'./agentgateway-controller',
],
)
# =============================================================================
# Deploy via Helm
# =============================================================================
# Deploy AgentGateway via Helm
k8s_yaml(helm(
'controller/install/helm/agentgateway',
name='agentgateway',
namespace=install_namespace,
set=[
'image.registry=' + image_registry,
'image.tag=' + version,
'image.pullPolicy=IfNotPresent',
'controller.image.repository=agentgateway-controller',
'controller.image.tag=' + version,
'controller.replicaCount=1',
'controller.logLevel=debug',
'proxy.image.repository=agentgateway',
'proxy.image.tag=' + version,
],
values=[config.main_dir + '/controller/hack/helm/dev.yaml'] if os.path.exists(config.main_dir + '/controller/hack/helm/dev.yaml') else [],
))
k8s_resource('agentgateway',
resource_deps=['go-compile-controller'])
# =============================================================================
# Data Plane (Rust-based proxy)
# =============================================================================
local_resource(
'rust-compile-dataplane',
'cargo build && if [ -f "./tools/tilt/agentgateway" ]; then rm "./tools/tilt/agentgateway"; fi && mv ./target/debug/agentgateway ./tools/tilt/agentgateway',
deps=['./crates',
'./Cargo.toml',
'./Cargo.lock',
'./.cargo'])
#
# Build data plane Docker image
docker_build(
'agentgateway',
context='./tools/tilt/',
dockerfile_contents="""
FROM ubuntu:24.04
COPY start.sh /scripts/start.sh
COPY restart.sh /scripts/restart.sh
COPY agentgateway /usr/local/bin/
ENTRYPOINT ["/scripts/start.sh", "/usr/local/bin/agentgateway"]
""",
live_update=[
sync('./tools/tilt/agentgateway', '/usr/local/bin/agentgateway'),
run('/scripts/restart.sh'),
],
only=[
'./agentgateway',
'./start.sh',
'./restart.sh',
],
)
k8s_kind('AgentgatewayParameters', image_object={'json_path': '{.spec.image}', 'repo_field': 'repository', 'tag_field': 'tag'})
k8s_kind('Gateway', pod_readiness='wait')
k8s_yaml(blob("""
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayParameters
metadata:
name: dataplane-dev-gwparams
spec:
image:
registry: "" # tilt will fill in the registry in the repository field, so leave it blank here (othewise it will be duplicated)
repository: agentgateway
tag: """ + version + """
deployment:
spec:
template:
spec:
containers:
# Delete container-level securityContext so that Tilt can apply live updates
# (need root user, and file system to be writable for live updates)
- name: agentgateway
securityContext:
$patch: delete
---
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1
metadata:
name: tilt-gw
spec:
gatewayClassName: agentgateway
infrastructure:
parametersRef:
group: agentgateway.dev
kind: AgentgatewayParameters
name: dataplane-dev-gwparams
listeners:
- name: http
protocol: HTTP
port: 8080
"""))
k8s_resource(workload='dataplane-dev-gwparams', extra_pod_selectors={"gateway.networking.k8s.io/gateway-name":"tilt-gw"},
resource_deps=['rust-compile-dataplane'])