.PHONY: help bootstrap sync status logs clean test

help: ## Show this help message
	@echo 'Usage: make [target]'
	@echo ''
	@echo 'Available targets:'
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "  %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

bootstrap: ## Bootstrap FluxCD on the cluster
	@./bootstrap.sh

sync: ## Force sync all FluxCD resources
	@flux reconcile kustomization flux-system --with-source
	@flux reconcile helmrelease --all

status: ## Show status of all FluxCD resources
	@flux get all --all-namespaces

logs: ## Show FluxCD logs
	@flux logs --all-namespaces

clean: ## Remove FluxCD from cluster
	@flux uninstall --namespace=flux-system --silent

test: ## Test the cluster connectivity
	@echo "Testing cluster connectivity..."
	@kubectl cluster-info
	@echo ""
	@echo "Testing GPU availability..."
	@kubectl get nodes -o jsonpath='{.items[*].status.allocatable.nvidia\.com/gpu}'
	@echo ""
	@echo "Testing FluxCD..."
	@flux check

apply: ## Apply all manifests directly (for testing)
	@kubectl apply -k clusters/k3s-dgx

diff: ## Show diff between cluster and git
	@flux diff kustomization flux-system --with-source

restart: ## Restart all FluxCD controllers
	@kubectl rollout restart deployment/source-controller -n flux-system
	@kubectl rollout restart deployment/kustomize-controller -n flux-system
	@kubectl rollout restart deployment/helm-controller -n flux-system
	@kubectl rollout restart deployment/notification-controller -n flux-system

gpu-status: ## Show GPU status
	@kubectl describe nodes | grep -A 5 "nvidia.com/gpu"

kserve-status: ## Show KServe status
	@kubectl get inferenceservices -n kserve
	@kubectl get pods -n kserve

model-logs: ## Show model inference logs
	@kubectl logs -n kserve -l serving.kserve.io/inferenceservice=huihui-granite --tail=100 -f

secrets: ## Generate example secrets (DO NOT COMMIT)
	@echo "Creating example secrets directory..."
	@mkdir -p secrets
	@echo "# Add your secrets here" > secrets/README.md
	@echo "# DO NOT commit actual secrets to git" >> secrets/README.md