@@ -119,20 +119,42 @@ tasks:
119119 cmds :
120120 - echo "Generating deepcopy and object files..."
121121 - " \" {{.TOOL_DIR}}/controller-gen\" object paths=\" ./pkg/apis/...\" "
122- - echo "Generating CRD manifests for each package..."
123- - |
124- set -e
125- for package_dir in pkg/apis/*/; do
126- package_name=$(basename "$package_dir")
127- echo "Generating CRDs for package: $package_name"
128- mkdir -p "config/crd/bases/$package_name"
129- "{{.TOOL_DIR}}/controller-gen" crd paths="./$package_dir..." output:dir="./config/crd/bases/$package_name"
130- done
131- - echo "Generating webhook files..."
132- - " \" {{.TOOL_DIR}}/controller-gen\" webhook paths=\" ./internal/webhooks/...\" output:dir=\" ./config/webhook\" "
133122 # Generate RBAC rules for the controllers.
134123 - echo "Generating RBAC rules for the controllers..."
135124 - " \" {{.TOOL_DIR}}/controller-gen\" rbac:roleName=milo-controller-manager paths=\" ./internal/controllers/...\" output:dir=\" ./config/controller-manager/overlays/core-control-plane/rbac\" "
125+ - task : generate:openapi
126+ silent : true
127+
128+ generate:openapi :
129+ desc : Generate OpenAPI definitions for search API types
130+ deps :
131+ - task : install-go-tool
132+ vars :
133+ NAME : openapi-gen
134+ PACKAGE : k8s.io/code-generator/cmd/openapi-gen
135+ VERSION : v0.23.0
136+ cmds :
137+ - echo "Generating OpenAPI definitions..."
138+ - |
139+ set -e
140+ # Packages to generate OpenAPI for
141+ PACKAGES=(
142+ "pkg/apis/policy/v1alpha1"
143+ "pkg/apis/search/v1alpha1"
144+ )
145+
146+ for REL_DIR in "${PACKAGES[@]}"; do
147+ PKG="go.miloapis.net/search/$REL_DIR"
148+ echo "Generating OpenAPI for $PKG..."
149+
150+ "{{.TOOL_DIR}}/openapi-gen" \
151+ --input-dirs "$PKG,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version" \
152+ --output-package "$REL_DIR" \
153+ --output-base "." \
154+ --output-file-base "zz_generated.openapi" \
155+ --go-header-file "hack/boilerplate.go.txt" \
156+ --report-filename "$REL_DIR/api_violations.report"
157+ done
136158 silent : true
137159
138160 # Test tasks
@@ -191,6 +213,26 @@ tasks:
191213 echo "📦 Installing infrastructure dependencies..."
192214 echo ""
193215
216+ # ============================================================
217+ # Install Etcd
218+ # ============================================================
219+ echo "📦 Installing Etcd..."
220+
221+ echo "Applying Etcd resources..."
222+ task test-infra:kubectl -- apply -k config/dependencies/etcd
223+
224+ echo "Waiting for Etcd namespace to be created..."
225+ task test-infra:kubectl -- wait --for=jsonpath='{.status.phase}'=Active namespace/etcd-system --timeout=30s 2>/dev/null || echo "⚠️ Namespace not ready yet"
226+
227+ echo "Waiting for Etcd HelmRelease to be ready..."
228+ task test-infra:kubectl -- wait --for=condition=ready helmrelease/etcd -n etcd-system --timeout=300s 2>/dev/null || echo "⚠️ Etcd HelmRelease not ready yet"
229+
230+ echo "Waiting for Etcd pods to be ready..."
231+ task test-infra:kubectl -- wait --for=condition=ready pod -l app.kubernetes.io/name=etcd -n etcd-system --timeout=120s 2>/dev/null || echo "⚠️ Etcd pods not ready yet"
232+
233+ echo "✅ Etcd installed"
234+ echo ""
235+
194236 # ============================================================
195237 # Install NATS
196238 # ============================================================
@@ -269,24 +311,36 @@ tasks:
269311 task test-infra:kubectl -- apply -k config/components/nats-streams
270312
271313 echo "⏳ Waiting for NATS stream to be ready..."
272- task test-infra:kubectl -- wait --for=condition=ready stream/audit-events -n nats-system --timeout=60s 2>/dev/null || echo "⚠️ Stream not ready yet"
314+ task test-infra:kubectl -- wait --for=condition=ready stream/audit-events -n nats-system --timeout=120s 2>/dev/null || echo "⚠️ Stream not ready yet"
273315
274316 echo ""
275317 echo "📋 Deploying Search server and components..."
276318 task test-infra:kubectl -- apply -k config/overlays/dev
277319
278- echo ""
320+ echo "⏳ Waiting for Search API Server to be ready..."
321+ task test-infra:kubectl -- wait --for=condition=available deployment/search-apiserver -n search-system --timeout=120s 2>/dev/null || echo "⚠️ Search API Server not ready yet"
322+
323+ echo "⏳ Waiting for Search Controller Manager to be ready..."
324+ task test-infra:kubectl -- wait --for=condition=available deployment/search-controller-manager -n search-system --timeout=120s 2>/dev/null || echo "⚠️ Search Controller Manager not ready yet"
325+
279326 echo "✅ Search server and all dependencies deployed successfully!"
280327 echo ""
281328 echo "📊 Check status:"
282329 echo " All resources: task test-infra:kubectl -- get all -n search-system"
283330 echo " Vector pods: task test-infra:kubectl -- get pods -l app.kubernetes.io/instance=vector-sidecar -n search-system"
284331 echo " NATS pods: task test-infra:kubectl -- get pods -n nats-system"
285332 echo " NATS streams: task test-infra:kubectl -- get streams -n nats-system"
333+ echo " Meilisearch pods: task test-infra:kubectl -- get pods -n meilisearch-system"
334+ echo " Etcd pods: task test-infra:kubectl -- get pods -n etcd-system"
335+ echo " Search Server pods: task test-infra:kubectl -- get pods -n search-system"
286336 echo ""
287337 echo "📋 View logs:"
288338 echo " Vector: task test-infra:kubectl -- logs -l app.kubernetes.io/instance=vector-sidecar -n search-system -f"
289339 echo " NATS: task test-infra:kubectl -- logs -l app.kubernetes.io/name=nats -n nats-system -f"
340+ echo " Meilisearch: task test-infra:kubectl -- logs -l app.kubernetes.io/name=meilisearch -n meilisearch-system -f"
341+ echo " Etcd: task test-infra:kubectl -- logs -l app.kubernetes.io/name=etcd -n etcd-system -f"
342+ echo " Search API Server: task test-infra:kubectl -- logs -l app.kubernetes.io/name=search-apiserver -n search-system -f"
343+ echo " Search Controller: task test-infra:kubectl -- logs -l app.kubernetes.io/name=search-controller-manager -n search-system -f"
290344
291345 dev:generate-webhook-certs :
292346 desc : Generate all certificates for webhook server
@@ -297,34 +351,64 @@ tasks:
297351 export CA_BUNDLE
298352 # Dynamically patch the generated manifest to use local host url and injected CA bundle
299353 perl -0777 -pe 's/(\s*)clientConfig:\n\s+service:\n\s+name: webhook-service\n\s+namespace: system\n\s+path: (.*)/$1clientConfig:\n$1 url: https:\/\/host.docker.internal:9443$2\n$1 caBundle: $ENV{CA_BUNDLE}/' config/webhook/manifests.yaml | task test-infra:kubectl -- apply -f -
300-
354+
301355 dev:run-controller :
302- desc : Run the controller manager locally (requires kubeconfig)
303- deps :
304- - dev:apply-crd
305- - dev:generate-webhook-certs
356+ desc : Run the controller manager against the LOCAL Search API server (127.0.0.1:9443)
306357 cmds :
358+ - |
359+ # Generate a temporary kubeconfig pointing to localhost:9443
360+ mkdir -p .tmp
361+ kubectl config view --minify --raw | \
362+ sed "s|server:.*|server: https://127.0.0.1:9443|g" | \
363+ sed "s|certificate-authority-data:.*|insecure-skip-tls-verify: true|g" \
364+ > .tmp/local-search-kubeconfig.yaml
365+ - |
366+ echo "🚀 Running controller against local Search API server..."
367+ KUBECONFIG=.tmp/local-search-kubeconfig.yaml go run ./cmd/search controller-manager \
368+ --metrics-bind-address=:8085 \
369+ --health-probe-bind-address=:8086 \
370+ --leader-elect=false
371+ silent : true
372+
373+ dev:pf-etcd :
374+ desc : Port forward Etcd for local development
375+ cmds :
376+ - echo "Port forwarding Etcd to localhost:2379..."
377+ - task test-infra:kubectl -- port-forward -n etcd-system svc/etcd 2379:2379
378+
379+ dev:run-apiserver :
380+ desc : Run the API server locally (requires dev:pf-etcd running)
381+ cmds :
382+ - |
383+ # Ensure kubeconfig is up to date with the current Kind cluster port
384+ echo "Syncing kubeconfig for cluster '{{.TEST_INFRA_CLUSTER_NAME}}'..."
385+ kind export kubeconfig --name "{{.TEST_INFRA_CLUSTER_NAME}}"
307386 - |
308387 current_context=$(kubectl config current-context)
309- if [ "$current_context" != "kind-test-infra " ]; then
310- echo "❌ Error: Wrong context! You are in '$current_context', but must be in 'kind-test-infra '."
388+ if [ "$current_context" != "kind-{{.TEST_INFRA_CLUSTER_NAME}} " ]; then
389+ echo "❌ Error: Wrong context! You are in '$current_context', but must be in 'kind-{{.TEST_INFRA_CLUSTER_NAME}} '."
311390 echo "Please run context switch command first."
312391 exit 1
313392 fi
393+ - mkdir -p "{{.CERTS_DIR}}"
314394 - |
315- go run ./cmd/search controller-manager \
316- --metrics-bind-address=:8082 \
317- --health-probe-bind-address=:8083 \
318- --webhook-cert-path={{.CERTS_DIR}} \
319- --webhook-cert-name=server.crt \
320- --webhook-cert-key=server.key
321- silent : true
322-
323- dev:apply-crd :
324- desc : Apply all CRDs from config/crd/bases to the cluster
325- cmds :
326- - task test-infra:kubectl -- apply -R -f config/crd/bases
327- silent : true
395+ # Extract Kind CA to allowed local kubectl to authenticate via client certs
396+ kubectl config view --minify --raw -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' | base64 -d > "{{.CERTS_DIR}}/kind-ca.crt"
397+ - echo "Running Search API Server locally..."
398+ - echo "Ensure you are running 'task dev:pf-etcd' in another terminal!"
399+ - |
400+ # Use KUBECONFIG if set, otherwise fallback to default
401+ KCFG=${KUBECONFIG:-$HOME/.kube/config}
402+ go run ./cmd/search serve \
403+ --etcd-servers http://127.0.0.1:2379 \
404+ --secure-port 9443 \
405+ --bind-address 127.0.0.1 \
406+ --authentication-skip-lookup=true \
407+ --authentication-kubeconfig="$KCFG" \
408+ --authorization-kubeconfig="$KCFG" \
409+ --kubeconfig="$KCFG" \
410+ --client-ca-file="{{.CERTS_DIR}}/kind-ca.crt" \
411+ --authorization-always-allow-paths=/healthz,/readyz,/livez,/openapi,/openapi/v2,/openapi/v3,/apis,/api
328412
329413 dev:undeploy :
330414 desc : Undeploy Search server from test-infra cluster
@@ -489,6 +573,7 @@ tasks:
489573 echo "Redeploying Search controller manager..."
490574
491575 # Restart the deployment to pick up new image
576+ task test-infra:kubectl -- rollout restart deployment/search-apiserver -n search-system
492577 task test-infra:kubectl -- rollout restart deployment/search-controller-manager -n search-system
493578
494579 # Wait for rollout to complete
0 commit comments