-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
1890 lines (1691 loc) · 102 KB
/
Copy pathMakefile
File metadata and controls
1890 lines (1691 loc) · 102 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.PHONY: dev-edge-create dev-run-edge build test lint fix-lint codegen crds clean certs dev-setup run-dex run-hub run-hub-static run-hub-embedded run-hub-embedded-static run-hub-standalone run-hub-embedded-graphql run-kcp dev-login dev-login-static dev-create-workload dev dev-infra dev-run-kcp path boilerplate verify-boilerplate verify-codegen ldflags tools docker-build docker-build-hub docker-build-agent docker-build-dex docker-build-dev-agent load-dev-agent-image docker-push-dex verify help-dev dev-status dev-clean-hooks helm-build-local helm-push-local helm-clean build-quickstart-provider build-quickstart-provider-portal build-kuery-provider build-kuery-provider-portal run-provider-kuery kuery-db-up kuery-db-down install-provider-kuery init-provider-kuery uninstall-provider-kuery run-provider-quickstart install-provider-quickstart init-provider-quickstart uninstall-provider-quickstart build-infrastructure-provider build-infrastructure-provider-portal codegen-infrastructure-provider run-provider-infrastructure install-provider-infrastructure init-provider-infrastructure uninstall-provider-infrastructure build-app-studio-provider build-app-studio-provider-portal codegen-app-studio-provider app-studio-db-up app-studio-db-down run-provider-app-studio install-provider-app-studio init-provider-app-studio uninstall-provider-app-studio build-agents-provider build-agents-provider-portal codegen-agents-provider agents-db-up agents-db-down run-provider-agents install-provider-agents init-provider-agents uninstall-provider-agents build-code-provider build-code-provider-portal codegen-code-provider run-provider-code install-provider-code init-provider-code uninstall-provider-code build-databricks-provider build-databricks-provider-portal codegen-databricks-provider run-provider-databricks install-provider-databricks init-provider-databricks uninstall-provider-databricks dev-kro-up dev-kro-down dev-kro-seed dev-kro-register-self e2e-infrastructure portal-provider-symlinks build-mcp-provider-portal build-kubernetes-edges-provider-portal build-server-edges-provider-portal e2e-provider e2e-provider-flags e2e-provider-all
BINDIR ?= bin
GOFLAGS ?=
TOOLSDIR := hack/tools
TOOLS_GOBIN_DIR := $(abspath $(TOOLSDIR))
GO_INSTALL := ./hack/go-install.sh
# --- Tool versions ---
DEX_VER := v2.41.1
DEX := $(TOOLSDIR)/dex-$(DEX_VER)
KCP_VER := v0.30.0
KCP := $(TOOLSDIR)/kcp-$(KCP_VER)
KCP_DATA_DIR := .kcp
CONTROLLER_GEN_VER := v0.16.5
CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(TOOLSDIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)
export CONTROLLER_GEN
KCP_APIGEN_VER := v0.30.0
KCP_APIGEN_BIN := apigen
KCP_APIGEN_GEN := $(TOOLSDIR)/$(KCP_APIGEN_BIN)-$(KCP_APIGEN_VER)
export KCP_APIGEN_GEN
GOLANGCI_LINT_VER := v2.11.4
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(TOOLSDIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
ARCH := amd64
endif
ifeq ($(ARCH),aarch64)
ARCH := arm64
endif
# --- Version info ---
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
BUILD_DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS_PKG := github.com/faroshq/faros-kedge/pkg/version
LDFLAGS := -s -w -X $(LDFLAGS_PKG).Version=$(VERSION) -X $(LDFLAGS_PKG).GitCommit=$(GIT_COMMIT) -X $(LDFLAGS_PKG).BuildDate=$(BUILD_DATE)
ldflags: ## Print ldflags for goreleaser
@echo "$(LDFLAGS)"
all: build
build: build-kedge build-hub build-graphql
build-kedge:
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BINDIR)/kedge ./cmd/kedge/
build-kedge-release: ## Build the release-tagging helper (kedge-release <component|all>)
go build $(GOFLAGS) -o $(BINDIR)/kedge-release ./cmd/kedge-release/
build-hub: build-mcp-provider-portal build-kubernetes-edges-provider-portal build-server-edges-provider-portal
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BINDIR)/kedge-hub ./cmd/kedge-hub/
build-hub-portal: build-portal ## Build hub with embedded portal
mkdir -p pkg/hub/portal
rm -rf pkg/hub/portal/dist
cp -r portal/dist pkg/hub/portal/dist
go build $(GOFLAGS) -tags portal_embed -ldflags "$(LDFLAGS)" -o $(BINDIR)/kedge-hub ./cmd/kedge-hub/
build-portal: portal-provider-symlinks build-mcp-provider-portal build-kubernetes-edges-provider-portal build-server-edges-provider-portal ## Build the portal Vue.js SPA (and built-in provider micro-frontends it depends on)
cd portal && npm ci && npm run build
dev-portal: portal-provider-symlinks ## Run the portal dev server
cd portal && npm run dev
# Built-in providers ship their UI as separate Vite bundles under
# providers/{name}/portal/. The hub binary embeds those dist/ outputs via
# //go:embed and serves them under /ui/providers/{name}/* from memory
# (see pkg/hub/providers/proxy.go LocalUIAssets branch). The build chain
# below is per-provider so a portal-only rebuild doesn't trigger every
# provider's bundle, but build-hub depends on each one to keep the
# embedded FS in sync with the binary.
build-mcp-provider-portal: portal-provider-symlinks ## Build the mcp provider's micro-frontend (Vite → providers/mcp/portal/dist)
cd providers/mcp/portal && npx vite build
build-kubernetes-edges-provider-portal: portal-provider-symlinks ## Build the kubernetes-edges provider's micro-frontend
cd providers/kubernetesedges/portal && npx vite build
build-server-edges-provider-portal: portal-provider-symlinks build-kubernetes-edges-provider-portal ## Build the server-edges provider's micro-frontend (depends on kubernetes-edges sources via Vite alias)
cd providers/serveredges/portal && npx vite build
# portal-provider-symlinks creates the local node_modules symlink each
# provider portal needs to resolve shared deps (vue, vue-router, pinia,
# urql, tailwind, …) from the main portal's installation. The .vue
# files in providers/{name}/portal/src/ live outside portal/node_modules'
# default Node lookup path, so without the symlink Vite/Rollup fail to
# resolve `vue-router` etc. Symlinks are gitignored and idempotent.
# Installs portal/node_modules first if missing — fresh CI checkouts
# otherwise symlink into a nonexistent dir and `npx vite build` fails.
portal-provider-symlinks:
@if [ ! -d portal/node_modules ]; then \
echo " → installing portal dependencies"; \
(cd portal && npm ci); \
fi
@for d in providers/mcp/portal providers/kubernetesedges/portal providers/serveredges/portal; do \
if [ ! -L "$$d/node_modules" ]; then \
ln -sfn ../../../portal/node_modules "$$d/node_modules" && \
echo " → symlinked $$d/node_modules"; \
fi; \
done
build-graphql: ## Build the GraphQL gateway binary (listener + gateway subcommands)
go build $(GOFLAGS) -o $(BINDIR)/kedge-graphql ./cmd/graphql/
# build-agent is an alias for build-kedge: the agent container image now ships
# the kedge CLI binary (cmd/kedge/) with ENTRYPOINT [/kedge, agent, run].
build-agent: build-kedge
build-quickstart-provider-portal: ## Build the quickstart provider's micro-frontend (Vite + TS → portal/dist)
cd providers/quickstart/portal && npm install --no-audit --no-fund && npm run build
build-quickstart-provider: build-quickstart-provider-portal ## Build the quickstart reference provider binary (portal embedded)
cd providers/quickstart && go build $(GOFLAGS) -o $(CURDIR)/$(BINDIR)/quickstart-provider .
build-kuery-provider-portal: ## Build the kuery provider's micro-frontend (Vite + TS → portal/dist)
cd providers/kuery/portal && npm install --no-audit --no-fund && npm run build
build-kuery-provider: build-kuery-provider-portal ## Build the kuery provider binary (portal embedded)
cd providers/kuery && go build $(GOFLAGS) -o $(CURDIR)/$(BINDIR)/kuery-provider .
build-infrastructure-provider-portal: ## Build the infrastructure provider's micro-frontend (Vite + Vue → portal/dist)
cd providers/infrastructure/portal && npm install --no-audit --no-fund && npm run build
build-infrastructure-provider: build-infrastructure-provider-portal ## Build the infrastructure provider binary (portal embedded)
cd providers/infrastructure && go build $(GOFLAGS) -o $(CURDIR)/$(BINDIR)/infrastructure-provider .
build-app-studio-provider-portal: ## Build the App Studio provider's micro-frontend (Vite + TS → portal/dist)
cd providers/app-studio/portal && npm install --no-audit --no-fund && npm run build
build-app-studio-provider: build-app-studio-provider-portal ## Build the App Studio provider binary (portal embedded)
cd providers/app-studio && go build $(GOFLAGS) -o $(CURDIR)/$(BINDIR)/app-studio-provider .
build-agents-provider-portal: ## Build the agents provider's micro-frontend (Vite + TS → portal/dist)
cd providers/agents/portal && npm install --no-audit --no-fund && npm run build
build-agents-provider: build-agents-provider-portal ## Build the agents provider binary (portal embedded)
cd providers/agents && go build $(GOFLAGS) -o $(CURDIR)/$(BINDIR)/agents-provider .
build-code-provider-portal: ## Build the code provider's micro-frontend (Vite + Vue → portal/dist)
cd providers/code/portal && npm install --no-audit --no-fund && npm run build
build-code-provider: build-code-provider-portal ## Build the code provider binary (portal embedded)
cd providers/code && go build $(GOFLAGS) -o $(CURDIR)/$(BINDIR)/code-provider .
build-databricks-provider-portal: ## Build the Databricks provider's micro-frontend (Vite + TS → portal/dist)
cd providers/databricks/portal && npm install --no-audit --no-fund && npm run test:tableRefs && npm run typecheck && npm run build
build-databricks-provider: build-databricks-provider-portal ## Build the Databricks provider binary (portal embedded)
cd providers/databricks && go build $(GOFLAGS) -o $(CURDIR)/$(BINDIR)/databricks-provider .
## Generate deepcopy methods + CRD YAML for the infrastructure provider's
## own API types (providers/infrastructure/apis/v1alpha1/...). The CRDs land
## under providers/infrastructure/config/crds/ and are embedded into the
## binary via go:embed — the hub does not install them, the provider does
## (one of the deliberate self-contained-system properties).
codegen-infrastructure-provider: $(CONTROLLER_GEN) ## Codegen for the infrastructure provider's local API
@mkdir -p providers/infrastructure/config/crds
cd providers/infrastructure && \
$(CURDIR)/$(CONTROLLER_GEN) object paths="./apis/..." && \
$(CURDIR)/$(CONTROLLER_GEN) crd paths="./apis/..." \
output:crd:artifacts:config=$(CURDIR)/providers/infrastructure/config/crds
# The provider embeds the Template CRD from install/crds/ (//go:embed in
# install/crds.go) and applies it into the kcp provider workspace at init.
# Keep that embed copy in lockstep with the generated schema — otherwise the
# operator installs a stale Template CRD and kcp silently prunes new fields
# (e.g. spec.sampleValues). The InfrastructureProvider CRD is NOT embedded
# (it's applied to the host cluster by the chart), so it stays in config/ only.
cp providers/infrastructure/config/crds/infrastructure.kedge.faros.sh_templates.yaml \
providers/infrastructure/install/crds/infrastructure.kedge.faros.sh_templates.yaml
./hack/ensure-boilerplate.sh
## Generate deepcopy + CRD YAML + kcp APIResourceSchemas for the code
## provider's own API types, then sync the schema bodies into the Helm chart's
## files/schemas/ directory. Provider init applies these schemas at runtime.
codegen-code-provider: $(CONTROLLER_GEN) $(KCP_APIGEN_GEN) ## Codegen for the code provider's local API (+ manifest + chart schemas)
@mkdir -p providers/code/config/crds providers/code/config/kcp providers/code/deploy/chart/files/schemas
cd providers/code && \
$(CURDIR)/$(CONTROLLER_GEN) object paths="./apis/..." && \
$(CURDIR)/$(CONTROLLER_GEN) crd paths="./apis/..." \
output:crd:artifacts:config=$(CURDIR)/providers/code/config/crds
./$(KCP_APIGEN_GEN) --input-dir providers/code/config/crds --output-dir providers/code/config/kcp
@for r in connections repositories repositorycommits repositorycheckouts repositorybuildstatuses deploykeys collaborators packages; do \
cp providers/code/config/kcp/apiresourceschema-$$r.code.kedge.faros.sh.yaml \
providers/code/deploy/chart/files/schemas/$$r.code.kedge.faros.sh.yaml; \
done
./hack/ensure-boilerplate.sh
codegen-agents-provider: $(CONTROLLER_GEN) $(KCP_APIGEN_GEN) ## Codegen for the agents provider's local API (+ chart schemas)
@mkdir -p providers/agents/config/crds providers/agents/config/kcp providers/agents/deploy/chart/files/schemas
cd providers/agents && \
$(CURDIR)/$(CONTROLLER_GEN) object paths="./apis/..." && \
$(CURDIR)/$(CONTROLLER_GEN) crd paths="./apis/..." \
output:crd:artifacts:config=$(CURDIR)/providers/agents/config/crds
./$(KCP_APIGEN_GEN) --input-dir providers/agents/config/crds --output-dir providers/agents/config/kcp
@for r in agents connections agentschedules agenttriggers agentruns; do \
cp providers/agents/config/kcp/apiresourceschema-$$r.agents.kedge.faros.sh.yaml \
providers/agents/deploy/chart/files/schemas/$$r.agents.kedge.faros.sh.yaml; \
done
./hack/ensure-boilerplate.sh
codegen-app-studio-provider: $(CONTROLLER_GEN) $(KCP_APIGEN_GEN) ## Codegen for the App Studio provider's local API (+ manifest + chart schema)
@mkdir -p providers/app-studio/config/crds providers/app-studio/config/kcp providers/app-studio/deploy/chart/files/schemas
cd providers/app-studio && \
$(CURDIR)/$(CONTROLLER_GEN) object paths="./apis/..." && \
$(CURDIR)/$(CONTROLLER_GEN) crd paths="./apis/..." \
output:crd:artifacts:config=$(CURDIR)/providers/app-studio/config/crds
./$(KCP_APIGEN_GEN) --input-dir providers/app-studio/config/crds --output-dir providers/app-studio/config/kcp
cp providers/app-studio/config/kcp/apiresourceschema-projects.ai.kedge.faros.sh.yaml \
providers/app-studio/deploy/chart/files/schemas/projects.ai.kedge.faros.sh.yaml
./hack/ensure-boilerplate.sh
codegen-databricks-provider: $(CONTROLLER_GEN) $(KCP_APIGEN_GEN) ## Codegen for the Databricks provider's local API (+ manifest + chart schemas)
@mkdir -p providers/databricks/config/crds providers/databricks/config/kcp providers/databricks/deploy/chart/files/schemas
cd providers/databricks && \
$(CURDIR)/$(CONTROLLER_GEN) object paths="./apis/..." && \
$(CURDIR)/$(CONTROLLER_GEN) crd paths="./apis/..." \
output:crd:artifacts:config=$(CURDIR)/providers/databricks/config/crds
./$(KCP_APIGEN_GEN) --input-dir providers/databricks/config/crds --output-dir providers/databricks/config/kcp
@for r in connections warehouses tables; do \
cp providers/databricks/config/kcp/apiresourceschema-$$r.databricks.kedge.faros.sh.yaml \
providers/databricks/deploy/chart/files/schemas/$$r.databricks.kedge.faros.sh.yaml; \
done
./hack/ensure-boilerplate.sh
test:
go test $(shell go list ./... | grep -v '/test/e2e')
test-util:
go test ./pkg/util/...
lint: $(GOLANGCI_LINT) ## Run golangci-lint
$(GOLANGCI_LINT) run ./...
fix-lint: $(GOLANGCI_LINT) ## Run golangci-lint with auto-fix
$(GOLANGCI_LINT) run --fix ./...
vet:
go vet ./...
# --- Code generation ---
boilerplate: ## Ensure license boilerplate on all Go files
./hack/ensure-boilerplate.sh
verify-boilerplate: ## Verify license boilerplate on all Go files
./hack/ensure-boilerplate.sh --verify
crds: $(CONTROLLER_GEN) $(KCP_APIGEN_GEN) ## Generate CRDs and kcp APIResourceSchemas
./hack/update-codegen-crds.sh
codegen: crds codegen-code-provider codegen-app-studio-provider codegen-databricks-provider boilerplate ## Generate all (CRDs + kcp resources + provider schemas + boilerplate)
verify-codegen: codegen ## Verify codegen is up to date
@if ! git diff --quiet HEAD; then \
echo "ERROR: codegen produced a diff. Please run 'make codegen' and commit the result."; \
git diff --stat; \
exit 1; \
fi
# --- Tool installation ---
tools: $(CONTROLLER_GEN) $(KCP_APIGEN_GEN) $(GOLANGCI_LINT) ## Install all dev tools
$(CONTROLLER_GEN):
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/controller-gen $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
$(KCP_APIGEN_GEN):
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/kcp-dev/sdk/cmd/apigen $(KCP_APIGEN_BIN) $(KCP_APIGEN_VER)
$(GOLANGCI_LINT):
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/v2/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
# --- Dev environment ---
certs: certs/apiserver.crt
certs/apiserver.crt:
@mkdir -p certs
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout certs/apiserver.key -out certs/apiserver.crt \
-days 365 -subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
dev-setup: certs
$(DEX):
@mkdir -p $(TOOLSDIR)
@echo "Building Dex $(DEX_VER)..."
@rm -rf $(TOOLSDIR)/dex-src
git clone --depth 1 --branch $(DEX_VER) https://github.com/dexidp/dex.git $(TOOLSDIR)/dex-src
cd $(TOOLSDIR)/dex-src && go build -o ../dex-$(DEX_VER) ./cmd/dex
@rm -rf $(TOOLSDIR)/dex-src
ln -sf $(notdir $(DEX)) $(TOOLSDIR)/dex
@echo "Dex binary: $(DEX)"
$(KCP):
@mkdir -p $(TOOLSDIR)
@echo "Downloading kcp $(KCP_VER) for $(OS)/$(ARCH)..."
curl -sL "https://github.com/kcp-dev/kcp/releases/download/$(KCP_VER)/kcp_$(subst v,,$(KCP_VER))_$(OS)_$(ARCH).tar.gz" | \
tar xz -C $(TOOLSDIR) bin/kcp
mv $(TOOLSDIR)/bin/kcp $(KCP)
rmdir $(TOOLSDIR)/bin 2>/dev/null || true
chmod +x $(KCP)
ln -sf $(notdir $(KCP)) $(TOOLSDIR)/kcp
@echo "kcp binary: $(KCP)"
dev-login: build-kedge
PATH=$(CURDIR)/$(BINDIR):$$PATH $(BINDIR)/kedge login --hub-url https://localhost:9443 --insecure-skip-tls-verify
dev-login-static: build-kedge ## Login using static token auth (for use with run-hub-static)
PATH=$(CURDIR)/$(BINDIR):$$PATH $(BINDIR)/kedge login --hub-url https://localhost:9443 --insecure-skip-tls-verify --token=$(STATIC_AUTH_TOKEN)
# TYPE selects the Edge type for dev-edge-create and dev-run-edge.
# Values: kubernetes (default) | server
TYPE ?= kubernetes
# Default DEV_EDGE_NAME is per-type so kubernetes and server edges can coexist.
DEV_EDGE_NAME ?= $(if $(filter server,$(TYPE)),dev-edge-server-1,dev-edge-kube-1)
dev-edge-create: build-kedge ## Create an Edge resource: TYPE=kubernetes (default) or TYPE=server
PATH=$(CURDIR)/$(BINDIR):$$PATH BINDIR=$(CURDIR)/$(BINDIR) hack/scripts/dev-edge-setup.sh $(DEV_EDGE_NAME) $(TYPE) "env=dev,provider=local"
dev-run-edge: build-kedge ## Run the edge agent: TYPE=kubernetes (default) or TYPE=server
@test -f .env.edge.$(TYPE) || (echo "Run 'make dev-edge-create TYPE=$(TYPE)' first (expected .env.edge.$(TYPE))"; exit 1)
ifeq ($(TYPE),server)
$(BINDIR)/kedge agent run \
--hub-url=https://localhost:9443 \
--hub-insecure-skip-tls-verify \
--token=$(KEDGE_EDGE_JOIN_TOKEN) \
--tunnel-url=https://localhost:9443 \
--edge-name=$(KEDGE_EDGE_NAME) \
--cluster=$(KEDGE_EDGE_CLUSTER) \
--type=server \
--ssh-proxy-port=2222 \
--ssh-user=kedge \
--ssh-password=password
else
hack/scripts/ensure-kind-cluster.sh
$(BINDIR)/kedge agent run \
--hub-url=https://localhost:9443 \
--hub-insecure-skip-tls-verify \
--token=$(KEDGE_EDGE_JOIN_TOKEN) \
--tunnel-url=https://localhost:9443 \
--edge-name=$(KEDGE_EDGE_NAME) \
--kubeconfig=.kubeconfig-kedge-agent \
--cluster=$(KEDGE_EDGE_CLUSTER) \
--type=kubernetes
endif
dev-create-workload: ## Create a demo VirtualWorkload targeting dev sites
kubectl apply -f hack/dev/examples/virtualworkload-nginx.yaml
-include .env
-include .env.edge.$(TYPE)
export
dev-infra: $(KCP) $(DEX) certs ## Run infra only (kcp + Dex)
hack/scripts/dev-infra.sh
# Service hooks for dependency tracking
HOOKS_DIR := .hooks
SERVICE_HOOKS := hack/scripts/service-hooks.sh
# Helper to check if a service is running
define check_service
@source $(SERVICE_HOOKS) && service_is_running $(1) || (echo "ERROR: $(1) is not running. Start with: $(2)" && exit 1)
endef
# Helper to require service not running
define check_no_service
@source $(SERVICE_HOOKS) && ! service_is_running $(1) || (echo "ERROR: $(1) is running. Stop it first or use a different mode." && exit 1)
endef
dev-run-kcp: $(KCP) ## Run external kcp server
@source $(SERVICE_HOOKS) && cleanup_stale_hooks
@echo "Starting kcp..."
@source $(SERVICE_HOOKS) && \
($(KCP) start --root-directory=$(KCP_DATA_DIR) --feature-gates=WorkspaceMounts=true,CacheAPIs=true & \
KCP_PID=$$!; \
service_start kcp $$KCP_PID; \
wait $$KCP_PID)
run-dex: $(DEX) certs ## Run Dex OIDC server
@source $(SERVICE_HOOKS) && cleanup_stale_hooks
@echo "Starting Dex..."
@source $(SERVICE_HOOKS) && \
($(DEX) serve hack/dev/dex/dex-config-dev.yaml & \
DEX_PID=$$!; \
service_start dex $$DEX_PID; \
wait $$DEX_PID)
dev-run-ssh-server:
docker run \
--name=openssh-server \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=Etc/UTC \
-e PASSWORD_ACCESS=true \
-e USER_PASSWORD=password \
-e USER_NAME=kedge \
-p 2222:2222 \
--restart unless-stopped \
lscr.io/linuxserver/openssh-server:latest
GRAPHQL_GRPC_ADDR ?= localhost:50051
GRAPHQL_APIEXPORT_SLICE ?= core.faros.sh
GRAPHQL_APIEXPORT_LOGICAL_CLUSTER ?= root:kedge:providers
dev-run-graphql: build-graphql ## Run GraphQL (listener + gateway, kcp mode, gRPC transport, playground at :8080)
$(BINDIR)/kedge-graphql run \
--kubeconfig=$(KCP_DATA_DIR)/admin.kubeconfig \
--grpc-addr=$(GRAPHQL_GRPC_ADDR) \
--apiexport-endpoint-slice-name=$(GRAPHQL_APIEXPORT_SLICE) \
--apiexport-endpoint-slice-logicalcluster=$(GRAPHQL_APIEXPORT_LOGICAL_CLUSTER) \
--workspace-schema-kubeconfig-override=$(KCP_DATA_DIR)/admin.kubeconfig \
--enable-playground \
--gateway-port=9090
# --- Hub configuration options ---
# These can be combined to create different run configurations.
STATIC_AUTH_TOKEN ?= dev-token
# Base hub flags (always needed)
HUB_FLAGS_BASE := \
--serving-cert-file=certs/apiserver.crt \
--serving-key-file=certs/apiserver.key \
--hub-external-url=https://localhost:9443 \
--dev-mode -v 4
# Auth: OIDC via Dex
HUB_FLAGS_OIDC := \
--idp-issuer-url=https://localhost:5554/dex \
--idp-client-id=kedge \
--idp-client-secret=ZXhhbXBsZS1hcHAtc2VjcmV0
# Auth: Static token
HUB_FLAGS_STATIC := \
--static-auth-token=$(STATIC_AUTH_TOKEN) \
--admin-users=$(ADMIN_USERS)
# Platform-admin identities allowed at /api/admin/* + the portal /bonkers area.
# The dev static token "$(STATIC_AUTH_TOKEN)" resolves (proxy.ensureStaticTokenUserOnce)
# to email static-<first8chars>@kedge.local — for dev-token that's
# static-dev-toke@kedge.local. Override for OIDC dev with your real email.
ADMIN_USERS ?= static-dev-toke@kedge.local
# KCP: External (requires running kcp separately)
HUB_FLAGS_KCP_EXTERNAL := \
--external-kcp-kubeconfig=.kcp/admin.kubeconfig
# KCP: Embedded (runs kcp in-process)
# --kcp-shard-external-url / --kcp-shard-virtual-workspace-url ARE NOT set
# by default — kcp defaults them to localhost which works for in-process
# consumers (hub's GraphQL listener, controllers, kcp proxy). Overriding
# them globally to host.docker.internal breaks anything running on the
# host (DNS doesn't resolve unless you're on Docker Desktop with the
# magic enabled). If you need EndpointSlice URLs that are reachable from
# inside a kind pod (e.g. kro pod talking to kcp), set KCP_SHARD_EXTERNAL_URL
# explicitly AND make sure host.docker.internal resolves on your host
# (or use your LAN IP).
KCP_SHARD_EXTERNAL_URL ?=
HUB_FLAGS_KCP_EMBEDDED := \
--embedded-kcp \
--kcp-root-dir=.kcp \
--kcp-secure-port=6443 \
$(if $(KCP_SHARD_EXTERNAL_URL),--kcp-shard-external-url=$(KCP_SHARD_EXTERNAL_URL) --kcp-shard-virtual-workspace-url=$(KCP_SHARD_EXTERNAL_URL),)
# GraphQL: Embedded (runs listener+gateway in-process alongside hub)
GRAPHQL_APIEXPORT_SLICE ?= core.faros.sh
GRAPHQL_APIEXPORT_LOGICAL_CLUSTER ?= root:kedge:providers
GRAPHQL_GRPC_ADDR ?= localhost:50051
HUB_FLAGS_GRAPHQL_EMBEDDED := \
--embedded-graphql \
--graphql-apiexport-slice-name=$(GRAPHQL_APIEXPORT_SLICE) \
--graphql-apiexport-logical-cluster=$(GRAPHQL_APIEXPORT_LOGICAL_CLUSTER) \
--graphql-grpc-addr=$(GRAPHQL_GRPC_ADDR) \
--graphql-playground
# Portal dev proxy: reverse-proxy /console/* to the Vite dev server at :3000
# so UI changes hot-reload without rebuilding the hub. Start the Vite server
# with: cd portal && npm run dev
PORTAL_DEV_URL ?= http://localhost:3000
HUB_FLAGS_PORTAL_DEV := \
--portal-dev-url=$(PORTAL_DEV_URL)
# --- Run targets ---
# Naming convention: run-hub-[auth]-[kcp]
# auth: oidc | static
# kcp: external | embedded
## External KCP + OIDC auth (requires: make run-dex, make dev-run-kcp)
run-hub: build-hub certs
@source $(SERVICE_HOOKS) && require_service dex "make run-dex"
@source $(SERVICE_HOOKS) && require_service kcp "make dev-run-kcp"
$(BINDIR)/kedge-hub $(HUB_FLAGS_BASE) $(HUB_FLAGS_OIDC) $(HUB_FLAGS_KCP_EXTERNAL)
## External KCP + static token auth (requires: make dev-run-kcp)
run-hub-static: build-hub certs
@source $(SERVICE_HOOKS) && require_service kcp "make dev-run-kcp"
$(BINDIR)/kedge-hub $(HUB_FLAGS_BASE) $(HUB_FLAGS_STATIC) $(HUB_FLAGS_KCP_EXTERNAL)
## Embedded KCP + OIDC auth (requires: make run-dex)
run-hub-embedded: build-hub certs
@source $(SERVICE_HOOKS) && require_service dex "make run-dex"
@source $(SERVICE_HOOKS) && require_service_not_running kcp "embedded kcp mode"
$(BINDIR)/kedge-hub $(HUB_FLAGS_BASE) $(HUB_FLAGS_OIDC) $(HUB_FLAGS_KCP_EMBEDDED)
## Embedded KCP + static token auth + embedded GraphQL + portal dev proxy (standalone - no external deps)
run-hub-embedded-static: build-hub certs
@source $(SERVICE_HOOKS) && require_service_not_running kcp "embedded kcp mode"
$(BINDIR)/kedge-hub $(HUB_FLAGS_BASE) $(HUB_FLAGS_STATIC) $(HUB_FLAGS_KCP_EMBEDDED) $(HUB_FLAGS_GRAPHQL_EMBEDDED) $(HUB_FLAGS_PORTAL_DEV)
## Embedded KCP + static token + embedded GraphQL (fully standalone)
run-hub-standalone: build-hub certs
@source $(SERVICE_HOOKS) && require_service_not_running kcp "embedded kcp mode"
$(BINDIR)/kedge-hub $(HUB_FLAGS_BASE) $(HUB_FLAGS_STATIC) $(HUB_FLAGS_KCP_EMBEDDED) $(HUB_FLAGS_GRAPHQL_EMBEDDED)
## Embedded KCP + OIDC + embedded GraphQL
run-hub-embedded-graphql: build-hub certs
@source $(SERVICE_HOOKS) && require_service dex "make run-dex"
@source $(SERVICE_HOOKS) && require_service_not_running kcp "embedded kcp mode"
$(BINDIR)/kedge-hub $(HUB_FLAGS_BASE) $(HUB_FLAGS_OIDC) $(HUB_FLAGS_KCP_EMBEDDED) $(HUB_FLAGS_GRAPHQL_EMBEDDED)
# Local kcp checkout to iterate against. Defaults to the standard per-user Go
# workspace path. Override on the CLI or via env:
# make tilt-cluster TILT_KCP_DIR=/path/to/kcp
# make tilt-cluster KCP_DIR=/path/to/kcp
TILT_KCP_DIR ?= $(or $(KCP_DIR),$(HOME)/go/src/github.com/kcp-dev/kcp)
## Full multi-shard kcp in a kind cluster + kedge-hub in-cluster, against a local kcp checkout
tilt-cluster: ## Run Tiltfile.cluster against a local kcp tree (override with TILT_KCP_DIR=... or KCP_DIR=...)
@# Create the kind cluster + context BEFORE `tilt up`. If the cluster is
@# created from inside the Tiltfile, Tilt initializes its deploy client
@# before the kind-kcp-tilt context exists and caches an empty config,
@# leaving every native k8s_yaml resource stuck on "could not set up
@# kubernetes client: no configuration has been provided". Guaranteeing the
@# cluster+context up front avoids that race.
@kind get clusters 2>/dev/null | grep -qx kcp-tilt || kind create cluster --name kcp-tilt
@kind export kubeconfig --name kcp-tilt
tilt up -f Tiltfile.cluster -- --kcp-dir="$(TILT_KCP_DIR)"
# --- Provider quickstart (local dev) ---
# The quickstart provider is a small standalone HTTP server that registers
# itself with the hub via a CatalogEntry. To exercise the full provider
# flow locally:
#
# Terminal 1: make run-hub-embedded-static
# Terminal 2: make install-provider-quickstart # admin: register the entry
# Terminal 3: make run-provider-quickstart # tenant: run the binary
#
# The hub proxies /ui/providers/quickstart and /services/providers/quickstart
# to the binary in Terminal 3; the quickstart heartbeats every 30s so the
# hub's TTL-driven readiness stays True.
QUICKSTART_PORT ?= 8081
QUICKSTART_HUB_URL ?= https://localhost:9443
QUICKSTART_TOKEN ?= $(STATIC_AUTH_TOKEN)
# kcp admin kubeconfig produced by embedded-kcp mode (see HUB_FLAGS_KCP_EMBEDDED).
QUICKSTART_KCP_KUBECONFIG ?= $(KCP_DATA_DIR)/admin.kubeconfig
# kcp apiserver URL for `kubectl apply` of the CatalogEntry. Embedded-kcp
# binds to :6443; Tiltfile.cluster (operator-deployed kcp) uses the envoy
# gateway at kcp.localhost:8443 and overrides this from the Tilt resource.
QUICKSTART_KCP_SERVER ?= https://localhost:6443
QUICKSTART_MANIFEST ?= providers/quickstart/manifest.yaml
# Declarative provisioning record: the hub's Provider controller creates the
# sub-workspace + ServiceAccount + kubeconfig Secret from this.
QUICKSTART_PROVIDER_MANIFEST ?= providers/quickstart/provider.yaml
QUICKSTART_WORKSPACE_PATH ?= root:kedge:providers:quickstart
QUICKSTART_RUNTIME_KUBECONFIG ?= $(KCP_DATA_DIR)/quickstart-runtime.kubeconfig
## Run the quickstart provider binary locally. Heartbeats to the hub on
## $(QUICKSTART_HUB_URL); TLS verification skipped (dev cert is self-signed).
run-provider-quickstart: build-quickstart-provider ## Run the quickstart provider (requires: make run-hub-embedded-static + make install-provider-quickstart)
@echo "Starting quickstart provider on :$(QUICKSTART_PORT)"
@echo " hub: $(QUICKSTART_HUB_URL)"
@echo " token: $(QUICKSTART_TOKEN)"
PORT=$(QUICKSTART_PORT) \
KEDGE_HUB_URL=$(QUICKSTART_HUB_URL) \
KEDGE_HUB_TOKEN=$(QUICKSTART_TOKEN) \
KEDGE_HUB_INSECURE=true \
KEDGE_PROVIDER_NAME=quickstart \
$(BINDIR)/quickstart-provider
## Apply the quickstart CatalogEntry into root:kedge:providers. Idempotent.
## Requires the hub to be running so the admin kubeconfig exists.
install-provider-quickstart: ## Apply quickstart Provider + CatalogEntry into root:kedge:providers
@test -f $(QUICKSTART_KCP_KUBECONFIG) || { \
echo "kubeconfig not found at $(QUICKSTART_KCP_KUBECONFIG)"; \
echo "start the hub first with: make run-hub-embedded-static"; \
exit 1; \
}
kubectl --kubeconfig=$(QUICKSTART_KCP_KUBECONFIG) \
--server=$(QUICKSTART_KCP_SERVER)/clusters/root:kedge:system:providers \
--insecure-skip-tls-verify \
apply -f $(QUICKSTART_PROVIDER_MANIFEST) -f $(QUICKSTART_MANIFEST)
## Run provider e2e suite (embedded kcp + quickstart-provider subprocess).
## Lightweight — no kind/Helm, just two host binaries the suite drives over
## HTTP + kcp dynamic clients. KEDGE_E2E_KEEP_DATA=true preserves logs/data.
E2E_PROVIDER_TIMEOUT ?= 10m
e2e-provider: build-hub build-quickstart-provider ## Run provider e2e suite
@test -z "$$(lsof -ti :19443 :16443 :18081 :2380 2>/dev/null)" || { \
echo "ports 19443/16443/18081/2380 are in use; stop any running kedge-hub/quickstart-provider first"; \
exit 1; \
}
go test ./test/e2e/suites/provider/... -v -timeout $(E2E_PROVIDER_TIMEOUT) $(if $(E2E_FLAGS),-args $(E2E_FLAGS))
## Run --providers flag mechanics suite (dep validation, unknown name,
## filtered enable). Each test spawns its own hub on the standard
## 19443/16443/2380 ports, so this MUST NOT run concurrently with
## `e2e-provider` — the Makefile checks the port up-front.
E2E_PROVIDER_FLAGS_TIMEOUT ?= 10m
e2e-provider-flags: build-hub ## Run --providers flag mechanics suite
@test -z "$$(lsof -ti :19443 :16443 :2380 2>/dev/null)" || { \
echo "ports 19443/16443/2380 are in use; stop any running kedge-hub first (e.g. pkill kedge-hub)"; \
exit 1; \
}
go test ./test/e2e/suites/providerflags/... -v -timeout $(E2E_PROVIDER_FLAGS_TIMEOUT) $(if $(E2E_FLAGS),-args $(E2E_FLAGS))
## Run both provider suites back-to-back (sequential — they share port 2380).
e2e-provider-all: e2e-provider e2e-provider-flags ## Run provider + provider-flags suites sequentially
## Infrastructure provider e2e (embedded kcp + infrastructure-provider
## init/serve subprocesses). Covers the kcp-side surface the kind/kro
## template e2e can't: provisioning, init bootstrap + template seeding, the
## Template controller chain via the stub backend, retired-template
## enforcement, and the tenant catalog read through an APIBinding. Shares
## the embedded-kcp etcd port 2380 with the other subprocess suites — do
## not run them concurrently.
E2E_INFRA_PROVIDER_TIMEOUT ?= 15m
e2e-infra-provider: build-hub build-infrastructure-provider ## Run infrastructure provider e2e suite
@test -z "$$(lsof -ti :19453 :16453 :18086 :2380 2>/dev/null)" || { \
echo "ports 19453/16453/18086/2380 are in use; stop any running kedge-hub/infrastructure-provider first"; \
exit 1; \
}
go test ./test/e2e/suites/infraprovider/... -v -timeout $(E2E_INFRA_PROVIDER_TIMEOUT) $(if $(E2E_FLAGS),-args $(E2E_FLAGS))
## Tilt-cluster suite: runs against an ALREADY-RUNNING operator-deployed,
## multi-shard Tilt stack (start it in another terminal with `make tilt-cluster`).
## Unlike the other e2e suites it does NOT spawn its own processes — it connects
## to the live stack (kcp front-proxy via tilt-frontproxy.kubeconfig, the
## in-cluster hub, the host-run providers) and verifies the providers end-to-end:
## provider registration, the templates catalog/projection, MCP tool federation,
## and the per-tenant identity gate. Endpoints override via KEDGE_E2E_* env.
E2E_TILT_TIMEOUT ?= 10m
E2E_TILT_HUB_URL ?= https://localhost:9443
E2E_TILT_INFRA_URL ?= http://localhost:8082
.PHONY: e2e-tilt-cluster
e2e-tilt-cluster: ## Run Tilt-cluster provider e2e (requires `make tilt-cluster` running)
@curl -sk --max-time 5 -o /dev/null "$(E2E_TILT_HUB_URL)/healthz" || { \
echo "hub not reachable at $(E2E_TILT_HUB_URL); bring the stack up first in another terminal: make tilt-cluster"; \
exit 1; \
}
@curl -s --max-time 5 -o /dev/null "$(E2E_TILT_INFRA_URL)/healthz" || { \
echo "infrastructure provider not reachable at $(E2E_TILT_INFRA_URL); is 'make tilt-cluster' fully up?"; \
exit 1; \
}
go test ./test/e2e/suites/tiltcluster/... -v -timeout $(E2E_TILT_TIMEOUT) $(if $(E2E_FLAGS),-args $(E2E_FLAGS))
## Create quickstart's APIExport (+ endpoint slice + bind grant) inside its
## provider workspace, so tenants can Enable it. The Provider controller already
## minted the provider-token Secret on register; we read it, write a dev runtime
## kubeconfig targeting the sub-workspace, and run the provider's `init`
## (sdkinstall.Bootstrap). Idempotent. Order: install-provider-quickstart →
## this → Enable works. Mirrors init-provider-kuery/code/infrastructure.
init-provider-quickstart: build-quickstart-provider ## Bootstrap quickstart APIExport + write dev runtime kubeconfig
@test -f $(QUICKSTART_KCP_KUBECONFIG) || { \
echo "kubeconfig not found at $(QUICKSTART_KCP_KUBECONFIG)"; \
echo "start the hub first with: make run-hub-embedded-static"; \
exit 1; \
}
@echo "Reading provider-token from $(QUICKSTART_WORKSPACE_PATH) and writing $(QUICKSTART_RUNTIME_KUBECONFIG)"
@TOKEN=$$(kubectl --kubeconfig=$(QUICKSTART_KCP_KUBECONFIG) \
--server=$(QUICKSTART_KCP_SERVER)/clusters/$(QUICKSTART_WORKSPACE_PATH) \
--insecure-skip-tls-verify \
get secret -n default provider-token -o jsonpath='{.data.token}' | base64 -d); \
test -n "$$TOKEN" || { echo "provider-token Secret empty — wait for the Provider controller to provision the workspace"; exit 1; }; \
mkdir -p $(KCP_DATA_DIR); \
printf 'apiVersion: v1\nkind: Config\nclusters:\n- name: kedge\n cluster:\n server: %s\n insecure-skip-tls-verify: true\ncontexts:\n- name: kedge\n context:\n cluster: kedge\n user: kedge\ncurrent-context: kedge\nusers:\n- name: kedge\n user:\n token: %s\n' \
"$(QUICKSTART_KCP_SERVER)/clusters/$(QUICKSTART_WORKSPACE_PATH)" "$$TOKEN" \
> $(QUICKSTART_RUNTIME_KUBECONFIG)
@echo "Running quickstart-provider init (creates APIExport + endpoint slice + bind grant)"
KEDGE_PROVIDER_KUBECONFIG=$(QUICKSTART_RUNTIME_KUBECONFIG) \
QUICKSTART_WORKSPACE_PATH=$(QUICKSTART_WORKSPACE_PATH) \
KEDGE_SCHEMAS_DIR=/nonexistent \
$(BINDIR)/quickstart-provider init
## Delete the quickstart CatalogEntry + Provider. Deleting the Provider triggers
## full teardown of root:kedge:providers:quickstart (workspace, SA, APIExport)
## via the controller's finalizer.
uninstall-provider-quickstart: ## Delete quickstart CatalogEntry + Provider (full teardown)
-kubectl --kubeconfig=$(QUICKSTART_KCP_KUBECONFIG) \
--server=$(QUICKSTART_KCP_SERVER)/clusters/root:kedge:system:providers \
--insecure-skip-tls-verify \
delete -f $(QUICKSTART_MANIFEST) -f $(QUICKSTART_PROVIDER_MANIFEST)
# --- Provider kuery (local dev) ---
# Mirror of the quickstart pattern above. Distinct port (8084) so the demo
# providers can run side-by-side. Phase 1 skeleton — see
# docs/kuery-provider-architecture.md for the phasing.
KUERY_PORT ?= 8084
KUERY_HUB_URL ?= https://localhost:9443
KUERY_TOKEN ?= $(STATIC_AUTH_TOKEN)
KUERY_KCP_KUBECONFIG ?= $(KCP_DATA_DIR)/admin.kubeconfig
KUERY_KCP_SERVER ?= https://localhost:6443
KUERY_MANIFEST ?= providers/kuery/manifest.yaml
KUERY_PROVIDER_MANIFEST ?= providers/kuery/provider.yaml
KUERY_WORKSPACE_PATH ?= root:kedge:providers:kuery
KUERY_SCHEMAS_DIR ?= providers/kuery/deploy/chart/files/schemas
# Optional: identityHash of the edges export for kuery's first-party edges
# permission claim (copy from /bonkers Root identities). Empty → APIExport is
# still created (Enable binds), but edge engagement won't activate until set.
KUERY_EDGES_IDENTITY_HASH ?=
# Dev runtime kubeconfig for the engagement controller, written by
# init-provider-kuery from the provider SA token the hub mints.
KUERY_RUNTIME_KUBECONFIG ?= $(KCP_DATA_DIR)/kuery-runtime.kubeconfig
# Local store backend. Dev always runs Postgres — the same backend as
# production — because Postgres-only SQL (jsonb_array_elements, uuid columns,
# …) diverges from SQLite and passing on SQLite has shipped real query bugs.
# kuery-db-up starts a throwaway container matching KUERY_DEV_DATABASE_URL.
KUERY_POSTGRES_CONTAINER ?= kedge-kuery-postgres
# Pulled from Google's Docker Hub mirror (same official image, more reliable
# pulls — Docker Hub has been dropping them with "unexpected EOF").
KUERY_POSTGRES_IMAGE ?= mirror.gcr.io/library/postgres:16-alpine
KUERY_POSTGRES_PORT ?= 55433
KUERY_POSTGRES_DATA_DIR ?= $(KCP_DATA_DIR)/kuery-postgres
KUERY_POSTGRES_USER ?= kuery
KUERY_POSTGRES_PASSWORD ?= kuery
KUERY_POSTGRES_DB ?= kuery
KUERY_DEV_DATABASE_URL ?= postgres://$(KUERY_POSTGRES_USER):$(KUERY_POSTGRES_PASSWORD)@localhost:$(KUERY_POSTGRES_PORT)/$(KUERY_POSTGRES_DB)?sslmode=disable
# Connection string the provider uses. Defaults to the local dev container
# above; point it at any external Postgres to override.
KUERY_STORE_DSN ?=
kuery-db-up: ## Start/reuse local Postgres for the kuery store (no-op when KUERY_STORE_DSN points at an external DB)
@if [ -n "$(KUERY_STORE_DSN)" ]; then \
echo "Using externally configured KUERY_STORE_DSN; not starting local kuery Postgres"; \
exit 0; \
fi; \
mkdir -p "$(KUERY_POSTGRES_DATA_DIR)"; \
if docker ps --format '{{.Names}}' | grep -qx "$(KUERY_POSTGRES_CONTAINER)"; then \
echo "kuery Postgres already running ($(KUERY_POSTGRES_CONTAINER))"; \
elif docker ps -a --format '{{.Names}}' | grep -qx "$(KUERY_POSTGRES_CONTAINER)"; then \
echo "Starting existing kuery Postgres container ($(KUERY_POSTGRES_CONTAINER))"; \
docker start "$(KUERY_POSTGRES_CONTAINER)" >/dev/null; \
else \
echo "Creating kuery Postgres container ($(KUERY_POSTGRES_CONTAINER))"; \
docker run -d \
--name "$(KUERY_POSTGRES_CONTAINER)" \
-e POSTGRES_USER="$(KUERY_POSTGRES_USER)" \
-e POSTGRES_PASSWORD="$(KUERY_POSTGRES_PASSWORD)" \
-e POSTGRES_DB="$(KUERY_POSTGRES_DB)" \
-p 127.0.0.1:$(KUERY_POSTGRES_PORT):5432 \
-v "$(abspath $(KUERY_POSTGRES_DATA_DIR)):/var/lib/postgresql/data" \
"$(KUERY_POSTGRES_IMAGE)" >/dev/null; \
fi; \
echo "Waiting for kuery Postgres..."; \
for _ in $$(seq 1 30); do \
if docker exec "$(KUERY_POSTGRES_CONTAINER)" pg_isready -U "$(KUERY_POSTGRES_USER)" -d "$(KUERY_POSTGRES_DB)" >/dev/null 2>&1; then \
echo " database: $(KUERY_DEV_DATABASE_URL)"; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "ERROR: kuery Postgres did not become ready"; \
docker logs "$(KUERY_POSTGRES_CONTAINER)" --tail=50; \
exit 1
kuery-db-down: ## Stop and remove the local kuery Postgres container (data remains in KUERY_POSTGRES_DATA_DIR)
@if docker ps -a --format '{{.Names}}' | grep -qx "$(KUERY_POSTGRES_CONTAINER)"; then \
echo "Removing kuery Postgres container ($(KUERY_POSTGRES_CONTAINER))"; \
docker rm -f "$(KUERY_POSTGRES_CONTAINER)" >/dev/null; \
else \
echo "No kuery Postgres container to remove ($(KUERY_POSTGRES_CONTAINER))"; \
fi
run-provider-kuery: build-kuery-provider kuery-db-up ## Run the kuery provider (requires: make run-hub-embedded-static + make install-provider-kuery; engagement needs init-provider-kuery)
@echo "Starting kuery provider on :$(KUERY_PORT)"
@echo " hub: $(KUERY_HUB_URL)"
@echo " token: $(KUERY_TOKEN)"
@if [ -f $(KUERY_RUNTIME_KUBECONFIG) ]; then \
echo " engagement: $(KUERY_RUNTIME_KUBECONFIG)"; \
else \
echo " engagement: DISABLED (run 'make init-provider-kuery' after install-provider-kuery)"; \
fi
@# Dev always runs Postgres. Fall back to the local dev container DSN when
@# KUERY_STORE_DSN is unset (external Postgres overrides it).
STORE_DSN="$${KUERY_STORE_DSN:-$(KUERY_STORE_DSN)}"; \
if [ -z "$$STORE_DSN" ]; then \
STORE_DSN="$(KUERY_DEV_DATABASE_URL)"; \
fi; \
echo " store: postgres ($$STORE_DSN)"; \
PORT=$(KUERY_PORT) \
KEDGE_HUB_URL=$(KUERY_HUB_URL) \
KEDGE_HUB_TOKEN=$(KUERY_TOKEN) \
KEDGE_HUB_INSECURE=true \
KEDGE_PROVIDER_NAME=kuery \
KEDGE_PROVIDER_KUBECONFIG=$(KUERY_RUNTIME_KUBECONFIG) \
KEDGE_DEV_ALLOW_TENANT_QUERY=true \
KUERY_STORE_DRIVER=postgres \
KUERY_STORE_DSN="$$STORE_DSN" \
$(BINDIR)/kuery-provider
install-provider-kuery: ## Apply kuery Provider + CatalogEntry into root:kedge:providers
@test -f $(KUERY_KCP_KUBECONFIG) || { \
echo "kubeconfig not found at $(KUERY_KCP_KUBECONFIG)"; \
echo "start the hub first with: make run-hub-embedded-static"; \
exit 1; \
}
kubectl --kubeconfig=$(KUERY_KCP_KUBECONFIG) \
--server=$(KUERY_KCP_SERVER)/clusters/root:kedge:system:providers \
--insecure-skip-tls-verify \
apply -f $(KUERY_PROVIDER_MANIFEST) -f $(KUERY_MANIFEST)
## Dev bootstrap for the engagement controller. The Provider controller writes
## the minted kubeconfig into a Secret in root:kedge:providers, but host-binary
## dev needs a host-reachable server URL — so we read the provider SA token from
## the sub-workspace (the same token the Provider controller minted) and write a
## dev kubeconfig with the local server URL, plus the APIExportEndpointSlice the
## engagement watcher discovers VW URLs from.
## Order: install-provider-kuery (Provider CR applied → controller provisions
## the sub-workspace + provider-token Secret) → this → the kuery Tilt resource
## restarts on the kubeconfig file appearing.
init-provider-kuery: build-kuery-provider ## Bootstrap kuery APIExport (schemas+slice+bind grant) + write dev runtime kubeconfig
@test -f $(KUERY_KCP_KUBECONFIG) || { \
echo "kubeconfig not found at $(KUERY_KCP_KUBECONFIG)"; \
echo "start the hub first with: make run-hub-embedded-static"; \
exit 1; \
}
@echo "Reading provider-token from $(KUERY_WORKSPACE_PATH) and writing $(KUERY_RUNTIME_KUBECONFIG)"
@TOKEN=$$(kubectl --kubeconfig=$(KUERY_KCP_KUBECONFIG) \
--server=$(KUERY_KCP_SERVER)/clusters/$(KUERY_WORKSPACE_PATH) \
--insecure-skip-tls-verify \
get secret -n default provider-token -o jsonpath='{.data.token}' | base64 -d); \
test -n "$$TOKEN" || { echo "provider-token Secret empty — wait for the Provider controller to provision the workspace"; exit 1; }; \
mkdir -p $(KCP_DATA_DIR); \
printf 'apiVersion: v1\nkind: Config\nclusters:\n- name: kedge\n cluster:\n server: %s\n insecure-skip-tls-verify: true\ncontexts:\n- name: kedge\n context:\n cluster: kedge\n user: kedge\ncurrent-context: kedge\nusers:\n- name: kedge\n user:\n token: %s\n' \
"$(KUERY_KCP_SERVER)/clusters/$(KUERY_WORKSPACE_PATH)" "$$TOKEN" \
> $(KUERY_RUNTIME_KUBECONFIG)
@# kcp requires kuery's first-party edges permissionClaim to carry the
@# identityHash of the export that serves edges. Tenants consume edges
@# through the core.faros.sh binding, so resolve core.faros.sh's
@# identityHash from system:controllers (override via KUERY_EDGES_IDENTITY_HASH).
@# The slice + bind grant are created inside install.Bootstrap using the
@# provider SA (cluster-admin → has `bind`), not the admin kubeconfig.
@echo "Running kuery-provider init (schemas + APIExport + endpoint slice + bind grant)"
@HASH="$(KUERY_EDGES_IDENTITY_HASH)"; \
if [ -z "$$HASH" ]; then \
HASH=$$(kubectl --kubeconfig=$(KUERY_KCP_KUBECONFIG) \
--server=$(KUERY_KCP_SERVER)/clusters/root:kedge:system:controllers \
--insecure-skip-tls-verify \
get apiexport core.faros.sh -o jsonpath='{.status.identityHash}'); \
echo "resolved edges identityHash from core.faros.sh: $$HASH"; \
fi; \
test -n "$$HASH" || { echo "could not resolve core.faros.sh identityHash — is the hub bootstrapped?"; exit 1; }; \
KEDGE_PROVIDER_KUBECONFIG=$(KUERY_RUNTIME_KUBECONFIG) \
KUERY_WORKSPACE_PATH=$(KUERY_WORKSPACE_PATH) \
KEDGE_SCHEMAS_DIR=$(KUERY_SCHEMAS_DIR) \
KUERY_EDGES_IDENTITY_HASH=$$HASH \
$(BINDIR)/kuery-provider init
uninstall-provider-kuery: ## Delete kuery CatalogEntry + Provider (full teardown)
-kubectl --kubeconfig=$(KUERY_KCP_KUBECONFIG) \
--server=$(KUERY_KCP_SERVER)/clusters/root:kedge:system:providers \
--insecure-skip-tls-verify \
delete -f $(KUERY_MANIFEST) -f $(KUERY_PROVIDER_MANIFEST)
# --- Provider infrastructure (local dev) ---
# Mirror of the quickstart pattern above. Distinct port (8082) so both
# providers can run side-by-side under Tilt. Iteration loop:
#
# Terminal 1: make run-hub-embedded-static
# Terminal 2: make install-provider-infrastructure # admin: register entry
# Terminal 3: make run-provider-infrastructure # tenant: run binary
#
KROMC_PORT ?= 8082
KROMC_HUB_URL ?= https://localhost:9443
KROMC_TOKEN ?= $(STATIC_AUTH_TOKEN)
KROMC_KCP_KUBECONFIG ?= $(KCP_DATA_DIR)/admin.kubeconfig
# Same override story as QUICKSTART_KCP_SERVER above — Tiltfile.cluster
# repoints this at the envoy gateway.
KROMC_KCP_SERVER ?= https://localhost:6443
KROMC_MANIFEST ?= providers/infrastructure/manifest.yaml
KROMC_PROVIDER_MANIFEST ?= providers/infrastructure/provider.yaml
# --- App Studio provider (local dev) ---
# Same pattern as quickstart/infrastructure/code: local dev applies the
# checked-in manifest.yaml; the Helm chart's CatalogEntry is for in-cluster
# self-registration via ConfigMap.
APP_STUDIO_PORT ?= 8085
APP_STUDIO_HUB_URL ?= https://localhost:9443
APP_STUDIO_TOKEN ?= $(STATIC_AUTH_TOKEN)
APP_STUDIO_KCP_KUBECONFIG ?= $(KCP_DATA_DIR)/admin.kubeconfig
APP_STUDIO_KCP_SERVER ?= https://localhost:6443
APP_STUDIO_WORKSPACE_PATH ?= root:kedge:providers:app-studio
APP_STUDIO_PROVIDER_KUBECONFIG ?= $(KCP_DATA_DIR)/app-studio-provider.kubeconfig
APP_STUDIO_SCHEMAS_DIR ?= providers/app-studio/deploy/chart/files/schemas
APP_STUDIO_MANIFEST ?= providers/app-studio/manifest.yaml
APP_STUDIO_PROVIDER_MANIFEST ?= providers/app-studio/provider.yaml
APP_STUDIO_DATABASE_URL ?=
APP_STUDIO_IN_MEMORY_MESSAGE_STORE ?=
APP_STUDIO_AUTO_APPROVE_ACTIONS ?= true
APP_STUDIO_DEV_DATABASE_URL ?= postgres://appstudio:appstudio@localhost:55432/appstudio?sslmode=disable
APP_STUDIO_POSTGRES_CONTAINER ?= kedge-app-studio-postgres
APP_STUDIO_POSTGRES_IMAGE ?= mirror.gcr.io/library/postgres:16-alpine
APP_STUDIO_POSTGRES_PORT ?= 55432
APP_STUDIO_POSTGRES_DATA_DIR ?= $(KCP_DATA_DIR)/app-studio-postgres
APP_STUDIO_POSTGRES_USER ?= appstudio
APP_STUDIO_POSTGRES_PASSWORD ?= appstudio
APP_STUDIO_POSTGRES_DB ?= appstudio
# --- agents provider (long-running personal AI agents) ---
AGENTS_PORT ?= 8087
AGENTS_HUB_URL ?= https://localhost:9443
AGENTS_TOKEN ?= $(STATIC_AUTH_TOKEN)
AGENTS_KCP_KUBECONFIG ?= $(KCP_DATA_DIR)/admin.kubeconfig
AGENTS_KCP_SERVER ?= https://localhost:6443
AGENTS_WORKSPACE_PATH ?= root:kedge:providers:agents
AGENTS_PROVIDER_KUBECONFIG ?= $(KCP_DATA_DIR)/agents-provider.kubeconfig
AGENTS_SCHEMAS_DIR ?= providers/agents/deploy/chart/files/schemas
AGENTS_MANIFEST ?= providers/agents/manifest.yaml
AGENTS_PROVIDER_MANIFEST ?= providers/agents/provider.yaml
# Durable store: dev runs use a local Postgres container by default (mirrors
# app-studio). Set AGENTS_IN_MEMORY_STORE=true for a non-durable quick run.
AGENTS_IN_MEMORY_STORE ?=
AGENTS_DEV_DATABASE_URL ?= postgres://agents:agents@localhost:55434/agents?sslmode=disable
AGENTS_POSTGRES_CONTAINER ?= kedge-agents-postgres
AGENTS_POSTGRES_IMAGE ?= mirror.gcr.io/library/postgres:16-alpine
AGENTS_POSTGRES_PORT ?= 55434
AGENTS_POSTGRES_DATA_DIR ?= $(KCP_DATA_DIR)/agents-postgres
## Run the infrastructure provider binary locally. Heartbeats to the hub on
## $(KROMC_HUB_URL); TLS verification skipped (dev cert is self-signed).
## KRO_KUBECONFIG is left unset by default → provider serves the baked-in
## stub catalog so the UI is demoable without standing up a real central
## kro cluster. Point KRO_KUBECONFIG at a real kubeconfig to use the
## real client + your own ResourceGraphDefinitions.
run-provider-infrastructure: build-infrastructure-provider ## Run the infrastructure provider (requires: make run-hub-embedded-static + make install-provider-infrastructure)
@echo "Starting infrastructure provider on :$(KROMC_PORT)"
@echo " hub: $(KROMC_HUB_URL)"
@echo " token: $(KROMC_TOKEN)"
@# Prefer an explicit KRO_KUBECONFIG from the caller's env, then
@# fall back to the dev-kro management cluster's kubeconfig when
@# present, and finally to stub mode if neither exists.
@if [ -n "$$KRO_KUBECONFIG" ]; then \
echo " kro: $$KRO_KUBECONFIG (from env)"; \
elif [ -f "$(KRO_KIND_KUBECONFIG)" ]; then \
echo " kro: $(KRO_KIND_KUBECONFIG) (dev-kro management cluster)"; \
else \
echo " kro: <unset → stub catalog; run 'make dev-kro-up' for real RGDs>"; \
fi
PORT=$(KROMC_PORT) \
KEDGE_HUB_URL=$(KROMC_HUB_URL) \
KEDGE_HUB_TOKEN=$(KROMC_TOKEN) \
KEDGE_HUB_INSECURE=true \
KEDGE_PROVIDER_NAME=infrastructure \
KEDGE_DEV_ALLOW_TENANT_QUERY=true \
INFRASTRUCTURE_WORKSPACE_PATH=$${INFRASTRUCTURE_WORKSPACE_PATH:-$(INFRASTRUCTURE_WORKSPACE_PATH)} \
KRO_KUBECONFIG=$${KRO_KUBECONFIG:-$$( [ -f "$(KRO_KIND_KUBECONFIG)" ] && echo "$(KRO_KIND_KUBECONFIG)" )} \
INFRASTRUCTURE_KUBECONFIG=$${INFRASTRUCTURE_KUBECONFIG:-$$( [ -f "$(INFRASTRUCTURE_RUNTIME_KUBECONFIG)" ] && echo "$(INFRASTRUCTURE_RUNTIME_KUBECONFIG)" )} \
KEDGE_APP_BASE_DOMAIN=$${KEDGE_APP_BASE_DOMAIN:-apps.127.0.0.1.sslip.io} \
KEDGE_GATEWAY_NAME=$${KEDGE_GATEWAY_NAME:-cloudflare-tunnel} \
KEDGE_GATEWAY_NAMESPACE=$${KEDGE_GATEWAY_NAMESPACE:-cfgate-system} \
$(BINDIR)/infrastructure-provider
run-provider-infrastructure-operator: build-infrastructure-provider ## Run the infrastructure provider in OPERATOR mode (bootstrap reconcile + serve from a provider + runtime kubeconfig)
@echo "Starting infrastructure provider (operator) on :$(KROMC_PORT)"
@echo " hub: $(KROMC_HUB_URL)"
@echo " provider: $${INFRASTRUCTURE_PROVIDER_KUBECONFIG:-$(KROMC_KCP_KUBECONFIG)} (kcp)"
@echo " runtime: $${INFRASTRUCTURE_RUNTIME_KUBECONFIG:-$(KRO_KIND_KUBECONFIG)} (kro cluster)"
@echo " ws: $(INFRASTRUCTURE_WORKSPACE_PATH)"
@# The operator needs the provider workspace to already exist — run
@# `make install-provider-infrastructure` (admin-portal onboarding in prod)
@# first. It then reconciles the in-workspace bootstrap and seeds kro itself.
PORT=$(KROMC_PORT) \
KEDGE_HUB_URL=$(KROMC_HUB_URL) \
KEDGE_HUB_TOKEN=$(KROMC_TOKEN) \
KEDGE_HUB_INSECURE=true \
KEDGE_PROVIDER_NAME=infrastructure \
KEDGE_DEV_ALLOW_TENANT_QUERY=true \
INFRASTRUCTURE_WORKSPACE_PATH=$(INFRASTRUCTURE_WORKSPACE_PATH) \
INFRASTRUCTURE_PROVIDER_KUBECONFIG=$${INFRASTRUCTURE_PROVIDER_KUBECONFIG:-$(KROMC_KCP_KUBECONFIG)} \
INFRASTRUCTURE_RUNTIME_KUBECONFIG=$${INFRASTRUCTURE_RUNTIME_KUBECONFIG:-$$( [ -f "$(KRO_KIND_KUBECONFIG)" ] && echo "$(KRO_KIND_KUBECONFIG)" )} \
$(BINDIR)/infrastructure-provider operator
# ── CRD-driven operator (controller) dev flow ───────────────────────────────
# Replaces kro-mgmt-up + infrastructure-init: one host-binary controller that
# bootstraps the workspace, helm-installs kro (with the kind hostAliases +